Skip to content

Commit

Permalink
improve docker image building
Browse files Browse the repository at this point in the history
verinice-veo#1116
  • Loading branch information
jochenkemnade committed Nov 22, 2024
1 parent 6fa913f commit 6dc9dbe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ docker_image:
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
$DESTINATION_ARG
--build-arg VEO_REPORTING_VERSION="${PROJECT_VERSION}"
--build-arg JAR_FILE="build/libs/veo-reporting-${PROJECT_VERSION}.jar"
--label org.opencontainers.image.version="${PROJECT_VERSION}"
--label org.opencontainers.image.revision=${CI_COMMIT_SHA}

Expand Down
23 changes: 18 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
FROM gcr.io/distroless/java21-debian12:nonroot
FROM eclipse-temurin:21-jdk AS builder

WORKDIR /builder

ARG JAR_FILE=build/libs/*.jar

# Copy the jar file to the working directory and rename it to application.jar
COPY ${JAR_FILE} application.jar
# Extract the jar file using an efficient layout
RUN java -Djarmode=tools -jar application.jar extract --layers --destination extracted

ARG VEO_REPORTING_VERSION
FROM gcr.io/distroless/java21-debian12:nonroot

LABEL org.opencontainers.image.title="vernice.veo reporting"
LABEL org.opencontainers.image.description="Backend of the verinice.veo-reporting web application."
Expand All @@ -14,8 +23,12 @@ ENV JDK_JAVA_OPTIONS "-Djdk.serialFilter=maxbytes=0"

USER nonroot

COPY --chown=nonroot:nonroot build/libs/veo-reporting-${VEO_REPORTING_VERSION}.jar /app/veo-reporting.jar

WORKDIR /app
EXPOSE 8080
CMD ["veo-reporting.jar"]

COPY --chown=nonroot:nonroot --from=builder /builder/extracted/dependencies/ ./
COPY --chown=nonroot:nonroot --from=builder /builder/extracted/spring-boot-loader/ ./
COPY --chown=nonroot:nonroot --from=builder /builder/extracted/snapshot-dependencies/ ./
COPY --chown=nonroot:nonroot --from=builder /builder/extracted/application/ ./

CMD ["application.jar"]

0 comments on commit 6dc9dbe

Please sign in to comment.