1
+ # ### Start of builder image
2
+ # ------------------------
3
+ # Builder stage to prepare application for final image
4
+ FROM openjdk:14-slim-buster as builder
5
+ WORKDIR temp
6
+
7
+ # Fatjar location, but could be set to different location from command line
8
+ ARG JAR_FILE=target/*.jar
9
+
10
+ # Copy fat jar file to current image builder
11
+ COPY ${JAR_FILE} application.jar
12
+
13
+ # Extract the jar file layers
14
+ RUN java -Djarmode=layertools -jar --enable-preview application.jar extract
15
+ # ### End of builder stage
16
+
17
+ # ### Start of actual image
18
+ # ------------------------
19
+ # Build image based on JDK 14 base image, based on latest debian buster OS
20
+ FROM openjdk:14-slim-buster
21
+ MAINTAINER Mohamed Taman <
[email protected] >
22
+
23
+ # Set image information, but could be set to different location from command line
24
+ ARG IMAGE_VERSION="0.0.1-SNAPSHOT"
25
+ ARG IMAGE_NAME="Product Service"
26
+ ARG MAINTAINER=
"Mohamed Taman <[email protected] >"
27
+
28
+ LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER}
29
+
30
+ # Limiting security access to not user root user
31
+ RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman
32
+
33
+ # Setting user to current created user
34
+ USER taman
35
+
36
+ # Set working directory to application folder
37
+ WORKDIR /home/taman/application
38
+
39
+ # Copy all layers from builder stage to current image
40
+ COPY --from=builder temp/dependencies/ ./
41
+ COPY --from=builder temp/snapshot-dependencies/ ./
42
+ COPY --from=builder temp/resources/ ./
43
+ COPY --from=builder temp/application/ ./
44
+
45
+ # Expose current application to port 8080
46
+ EXPOSE 8080
47
+
48
+ ARG JAVA_OPTS=""
49
+
50
+ # Run the application with JVM configs if any
51
+ ENTRYPOINT ["bash" , "-c" , \
52
+ "java -server --enable-preview -XX:+UseContainerSupport \
53
+ -XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \
54
+ org.springframework.boot.loader.JarLauncher ${0} ${@}" ]
0 commit comments