From 7a4334fb3f6992cffe69f91475fab1874fd8128f Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Mon, 17 Oct 2022 22:25:46 +0300 Subject: [PATCH] dockerfile-pro --- Dockerfile | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 75458c6..042a600 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,32 @@ -FROM openjdk:17.0.2-jdk-slim-buster -ARG JAR_FILE=target/*.jar -COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file +FROM eclipse-temurin:17 as app-build + +ENV RELEASE=17 + +WORKDIR /opt/build + +COPY ./target/spring-boot-*.jar ./application.jar + +RUN java -Djarmode=layertools -jar application.jar extract +RUN $JAVA_HOME/bin/jlink \ + --add-modules `jdeps --ignore-missing-deps -q -recursive --multi-release ${RELEASE} --print-module-deps -cp 'dependencies/BOOT-INF/lib/*' 'snapshot-dependencies/BOOT-INF/lib/' application.jar` \ + --strip-debug \ + --no-man-pages \ + --no-header-files \ + --compress=2 \ + --output ./custom-jdk + +FROM alpine:latest + +ARG BUILD_PATH=/opt/build +ENV JAVA_HOME=/opt/jdk +ENV PATH "${JAVA_HOME}/bin:${PATH}" + +WORKDIR application + +COPY --from=app-build $BUILD_PATH/custom-jdk $JAVA_HOME +COPY --from=app-build $BUILD_PATH/spring-boot-loader/ ./ +COPY --from=app-build $BUILD_PATH/dependencies/ ./ +COPY --from=app-build $BUILD_PATH/snapshot-dependencies/ ./ +COPY --from=app-build $BUILD_PATH/application/ ./ + +ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] \ No newline at end of file