spring_boot_docker/Dockerfile

38 lines
1.3 KiB
Docker
Raw Normal View History

2022-10-17 22:25:46 +03:00
FROM eclipse-temurin:17 as app-build
ENV RELEASE=17
2022-10-18 11:02:38 +03:00
RUN groupadd --gid 1000 spring-app \
&& useradd --uid 1000 --gid spring-app --shell /bin/bash --create-home spring-app
USER spring-app:spring-app
2022-10-17 22:25:46 +03:00
WORKDIR /opt/build
2022-10-18 11:02:38 +03:00
COPY ./target/*.jar ./application.jar
2022-10-17 22:25:46 +03:00
RUN java -Djarmode=layertools -jar application.jar extract
RUN $JAVA_HOME/bin/jlink \
2022-10-18 11:02:38 +03:00
--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` \
2022-10-17 22:25:46 +03:00
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
2022-10-18 11:02:38 +03:00
--output jdk
2022-10-17 22:25:46 +03:00
2022-10-18 11:02:38 +03:00
FROM debian:buster-slim
2022-10-17 22:25:46 +03:00
ARG BUILD_PATH=/opt/build
ENV JAVA_HOME=/opt/jdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"
2022-10-18 11:02:38 +03:00
RUN groupadd --gid 1000 spring-app \
&& useradd --uid 1000 --gid spring-app --shell /bin/bash --create-home spring-app
USER spring-app:spring-app
WORKDIR /opt/workspace
2022-10-17 22:25:46 +03:00
2022-10-18 11:02:38 +03:00
COPY --from=app-build $BUILD_PATH/jdk $JAVA_HOME
2022-10-17 22:25:46 +03:00
COPY --from=app-build $BUILD_PATH/dependencies/ ./
2022-10-18 11:02:38 +03:00
COPY --from=app-build $BUILD_PATH/spring-boot-loader/ ./
2022-10-17 22:25:46 +03:00
COPY --from=app-build $BUILD_PATH/snapshot-dependencies/ ./
COPY --from=app-build $BUILD_PATH/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]