Skip to content

Commit

Permalink
Create the Multi stage build deploy commands for Swatch
Browse files Browse the repository at this point in the history
Revert "Add gradle build to RHTAP pipelines"
Commented out unusable commands for docker staging.
Refactor docker file for build stage deployment
Adjust shell script
Add dashes for chown
Add new dockerignore condition
  • Loading branch information
ksynvrit committed Sep 22, 2023
1 parent de08c59 commit 3381910
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 103 deletions.
14 changes: 12 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# by default ignore everything
**

**/build
# ignore dockerfiles so subproject can build using cache
**/Dockerfile
**/Dockerfile.jvm
# allow the build libs for spring-boot based contexts
!build/libs
!build/javaagent
# allow the quarkus-app build folder for quarkus based builds
!build/quarkus-app
# ignore bonfire CI working files
.bonfire
.bonfire_venv
.cicd_bootstrap.sh
.cicd_tools_bootstrap.sh
.kube
.docker
artifacts
27 changes: 1 addition & 26 deletions .tekton/rhsm-subscriptions-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,31 +201,6 @@ spec:
workspaces:
- name: source
workspace: workspace
- name: gradle-build
runAfter:
- prefetch-dependencies
taskSpec:
steps:
- name: gradle-build
image: registry.access.redhat.com/ubi9/openjdk-17
workingDir: "/workspace/source/"
command:
- ./gradlew
args:
- assemble
resources:
requests:
memory: 2Gi
cpu: 2
limits:
memory: 6Gi
cpu: 6
workspaces:
- name: source
workspace: workspace
workspaces:
- name: source
workspace: workspace
- name: build-container
params:
- name: IMAGE
Expand All @@ -243,7 +218,7 @@ spec:
- name: COMMIT_SHA
value: $(tasks.clone-repository.results.commit)
runAfter:
- gradle-build
- prefetch-dependencies
taskRef:
params:
- name: name
Expand Down
27 changes: 1 addition & 26 deletions .tekton/rhsm-subscriptions-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,31 +196,6 @@ spec:
values:
- "true"
workspaces:
- name: source
workspace: workspace
- name: gradle-build
runAfter:
- prefetch-dependencies
taskSpec:
steps:
- name: gradle-build
image: registry.access.redhat.com/ubi9/openjdk-17
workingDir: "/workspace/source/"
command:
- ./gradlew
args:
- assemble
resources:
requests:
memory: 2Gi
cpu: 2
limits:
memory: 6Gi
cpu: 6
workspaces:
- name: source
workspace: workspace
workspaces:
- name: source
workspace: workspace
- name: build-container
Expand All @@ -240,7 +215,7 @@ spec:
- name: COMMIT_SHA
value: $(tasks.clone-repository.results.commit)
runAfter:
- gradle-build
- prefetch-dependencies
taskRef:
params:
- name: name
Expand Down
29 changes: 27 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
FROM registry.access.redhat.com/ubi9/openjdk-17:1.16

USER root
WORKDIR /stage

COPY gradlew .
COPY gradle gradle
COPY build.gradle settings.gradle dependencies.gradle ./
COPY buildSrc buildSrc
# The commented out commands are used for quarkus offline as we need the subprojects to run at top level
# Have to add too many files to have quarkus offline run
# We can revist once we refactor the codebases a bit

#COPY swatch-contracts/build.gradle swatch-contracts/build.gradle
#COPY swatch-producer-aws/build.gradle swatch-producer-aws/build.gradle
#COPY clients clients
#COPY clients-core/build.gradle clients-core/build.gradle
#COPY swatch-common-config-workaround/build.gradle swatch-common-config-workaround/build.gradle
#COPY swatch-common-resteasy/build.gradle swatch-common-resteasy/build.gradle
#COPY swatch-product-configuration/build.gradle swatch-product-configuration/build.gradle
#RUN ./gradlew quarkusGoOffline

COPY . .
RUN ./gradlew assemble -x test

FROM registry.access.redhat.com/ubi9/openjdk-17-runtime:1.16-1.1693315923

COPY build/libs/* /deployments/
COPY build/javaagent/* /opt/
COPY --from=0 /stage/build/libs/* /deployments/
COPY --from=0 /stage/build/javaagent/* /opt/
ENV JAVA_OPTS_APPEND=-javaagent:/opt/splunk-otel-javaagent.jar
18 changes: 4 additions & 14 deletions bin/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,21 @@ fi

# Exit script if a podman command fails
trap build_failed ERR
# Remove any jars from build/libs. Having multiple JARS here will confuse s2i/run
./gradlew clean

for p in "${projects[@]}"; do
case "$p" in
"rhsm")
./gradlew :assemble
podman build . -t quay.io/$quay_user/rhsm-subscriptions:$tag --label "git-commit=${commit}"
podman build . -t quay.io/$quay_user/rhsm-subscriptions:$tag --label "git-commit=${commit}" --ulimit nofile=2048:2048
;;
"conduit")
./gradlew swatch-system-conduit:assemble
podman build . -f swatch-system-conduit/Dockerfile \
-t quay.io/$quay_user/swatch-system-conduit:$tag --label "git-commit=${commit}"
-t quay.io/$quay_user/swatch-system-conduit:$tag --label "git-commit=${commit}" --ulimit nofile=2048:2048
;;
"swatch-producer-aws")
./gradlew :swatch-producer-aws:assemble
pushd swatch-producer-aws
podman build . -f src/main/docker/Dockerfile.jvm -t quay.io/$quay_user/swatch-producer-aws:$tag --label "git-commit=${commit}"
popd
podman build . -f swatch-producer-aws/src/main/docker/Dockerfile.jvm -t quay.io/$quay_user/swatch-producer-aws:$tag --label "git-commit=${commit}" --ulimit nofile=2048:2048
;;
"swatch-contracts")
./gradlew :swatch-contracts:assemble
pushd swatch-contracts
podman build . -f src/main/docker/Dockerfile.jvm -t quay.io/$quay_user/swatch-contracts:$tag --label "git-commit=${commit}"
popd
podman build . -f swatch-contracts/src/main/docker/Dockerfile.jvm -t quay.io/$quay_user/swatch-contracts:$tag --label "git-commit=${commit}" --ulimit nofile=2048:2048
;;
*) echo "Please use values from the set \"rhsm\", \"conduit\", \"swatch-producer-aws\", \"swatch-contracts\"";;
esac
Expand Down
5 changes: 1 addition & 4 deletions build_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ DOCKER_CONF="$PWD/.docker"
mkdir -p "$DOCKER_CONF"
docker --config="$DOCKER_CONF" login -u="$QUAY_USER" -p="$QUAY_TOKEN" quay.io

USE_DOCKER=true ./podman_run.sh ./gradlew assemble

for service in $SERVICES; do
IMAGE="quay.io/cloudservices/$service"
DOCKERFILE=$(get_dockerfile $service)
APP_ROOT=$(get_approot $service)
docker --config="$DOCKER_CONF" build --no-cache -t "${IMAGE}:${IMAGE_TAG}" $APP_ROOT -f $APP_ROOT/$(get_dockerfile $service)
docker --config="$DOCKER_CONF" build --ulimit nofile=2048:2048 "${IMAGE}:${IMAGE_TAG}" $PWD -f $PWD/$(get_dockerfile $service)
docker --config="$DOCKER_CONF" push "${IMAGE}:${IMAGE_TAG}"
docker --config="$DOCKER_CONF" tag "${IMAGE}:${IMAGE_TAG}" "${IMAGE}:${SMOKE_TEST_TAG}"
docker --config="$DOCKER_CONF" push "${IMAGE}:${SMOKE_TEST_TAG}"
Expand Down
14 changes: 7 additions & 7 deletions cicd_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ fi
get_dockerfile() {
component=$1
if [[ -f $component/src/main/docker/Dockerfile.jvm ]]; then
echo "src/main/docker/Dockerfile.jvm"
echo "$component/src/main/docker/Dockerfile.jvm"
else
echo "./Dockerfile"
if [ "$component" == "rhsm-subscriptions" ]; then
echo "./Dockerfile"
else
echo "$component/Dockerfile"
fi
fi
}

get_approot() {
component=$1
if [ "$component" == "rhsm-subscriptions" ]; then
echo "$PWD"
else
echo "$PWD/$component"
fi
echo "$PWD"
}

# First sed removes leading ".", second sed removes leading "/"
Expand Down
2 changes: 1 addition & 1 deletion pr_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# NOTE: if you need to debug this file, use DRY_RUN=true to echo docker/podman/oc commands without running them

# before we run common consoledot builds, prepare the binary artifacts for quarkus style builds
./podman_run.sh ./gradlew assemble
./podman_run.sh

source cicd_common.sh

Expand Down
11 changes: 9 additions & 2 deletions swatch-contracts/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
*
!build/*-runner
!build/*-runner.jar
!build/lib/*
!build/quarkus-app/*
!build/quarkus-app/*
# ignore bonfire CI working files
.bonfire
.bonfire_venv
.cicd_bootstrap.sh
.cicd_tools_bootstrap.sh
.kube
.docker
artifacts
34 changes: 29 additions & 5 deletions swatch-contracts/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,43 @@
# accessed directly. (example: "foo.example.com,bar.example.com")
#
###
FROM registry.access.redhat.com/ubi9/openjdk-17:1.16

USER root
WORKDIR /stage

COPY gradlew .
COPY gradle gradle
COPY build.gradle settings.gradle dependencies.gradle ./
COPY buildSrc buildSrc
# The commented out commands are used for quarkus offline as we need the subprojects to run at top level
# Have to add too many files to have quarkus offline run
# We can revist once we refactor the codebases a bit

#COPY swatch-contracts/build.gradle swatch-contracts/build.gradle
#COPY swatch-producer-aws/build.gradle swatch-producer-aws/build.gradle
#COPY clients clients
#COPY clients-core/build.gradle clients-core/build.gradle
#COPY swatch-common-config-workaround/build.gradle swatch-common-config-workaround/build.gradle
#COPY swatch-common-resteasy/build.gradle swatch-common-resteasy/build.gradle
#COPY swatch-product-configuration/build.gradle swatch-product-configuration/build.gradle
#RUN ./gradlew quarkusGoOffline

COPY . .
RUN ./gradlew assemble -x test

FROM registry.access.redhat.com/ubi9/openjdk-17-runtime:1.16-1.1693315923

ENV LANGUAGE='en_US:en'


# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --chown=185 build/quarkus-app/lib/ /deployments/lib/
COPY --chown=185 build/quarkus-app/*.jar /deployments/
COPY --chown=185 build/quarkus-app/app/ /deployments/app/
COPY --chown=185 build/quarkus-app/quarkus/ /deployments/quarkus/
COPY --from=0 --chown=185 /stage/swatch-contracts/build/quarkus-app/lib/ /deployments/lib/
COPY --from=0 --chown=185 /stage/swatch-contracts/build/quarkus-app/*.jar /deployments/
COPY --from=0 --chown=185 /stage/swatch-contracts/build/quarkus-app/app/ /deployments/app/
COPY --from=0 --chown=185 /stage/swatch-contracts/build/quarkus-app/quarkus/ /deployments/quarkus/

EXPOSE 8080
USER 185
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"

11 changes: 8 additions & 3 deletions swatch-producer-aws/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# by default ignore everything
**

# allow the build libs for spring-boot based contexts
!build/libs
# allow the quarkus-app build folder for quarkus based builds
!build/quarkus-app
# ignore bonfire CI working files
.bonfire
.bonfire_venv
.cicd_bootstrap.sh
.cicd_tools_bootstrap.sh
.kube
.docker
artifacts
35 changes: 30 additions & 5 deletions swatch-producer-aws/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,44 @@
# accessed directly. (example: "foo.example.com,bar.example.com")
#
###
FROM registry.access.redhat.com/ubi9/openjdk-17:1.16

USER root
WORKDIR /stage

COPY gradlew .
COPY gradle gradle
COPY build.gradle settings.gradle dependencies.gradle ./
COPY buildSrc buildSrc
# The commented out commands are used for quarkus offline as we need the subprojects to run at top level
# Have to add too many files to have quarkus offline run
# We can revist once we refactor the codebases a bit

#COPY swatch-contracts/build.gradle swatch-contracts/build.gradle
#COPY swatch-producer-aws/build.gradle swatch-producer-aws/build.gradle
#COPY clients clients
#COPY clients-core/build.gradle clients-core/build.gradle
#COPY swatch-common-config-workaround/build.gradle swatch-common-config-workaround/build.gradle
#COPY swatch-common-resteasy/build.gradle swatch-common-resteasy/build.gradle
#COPY swatch-product-configuration/build.gradle swatch-product-configuration/build.gradle
#RUN ./gradlew quarkusGoOffline

COPY . .
RUN ./gradlew assemble -x test

FROM registry.access.redhat.com/ubi9/openjdk-17-runtime:1.16-1.1693315923

ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'


# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --chown=185 build/quarkus-app/lib/ /deployments/lib/
COPY --chown=185 build/quarkus-app/*.jar /deployments/
COPY --chown=185 build/quarkus-app/app/ /deployments/app/
COPY --chown=185 build/quarkus-app/quarkus/ /deployments/quarkus/
COPY --from=0 --chown=185 /stage/swatch-producer-aws/build/quarkus-app/lib/ /deployments/lib/
COPY --from=0 --chown=185 /stage/swatch-producer-aws/build/quarkus-app/*.jar /deployments/
COPY --from=0 --chown=185 /stage/swatch-producer-aws/build/quarkus-app/app/ /deployments/app/
COPY --from=0 --chown=185 /stage/swatch-producer-aws/build/quarkus-app/quarkus/ /deployments/quarkus/

EXPOSE 8080
USER 185

ENV AB_JOLOKIA_OFF=""
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
Expand Down
11 changes: 8 additions & 3 deletions swatch-system-conduit/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# by default ignore everything
**

# allow the build libs for spring-boot based contexts
!build/libs
# allow the quarkus-app build folder for quarkus based builds
!build/quarkus-app
# allow the build libs for splunk otel java agent
!build/javaagent
# ignore bonfire CI working files
.bonfire
.bonfire_venv
.cicd_bootstrap.sh
.cicd_tools_bootstrap.sh
.kube
.docker
artifacts
Loading

0 comments on commit 3381910

Please sign in to comment.