Skip to content

Commit bfca0b7

Browse files
committed
Base Docker on hardened images
Split the Dockerfile into a two-stage build: - Use hardened maven image to build the jar - Use hardened temurin image to run the jar
1 parent adf5a08 commit bfca0b7

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

Dockerfile

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
# fetch basic image
2-
FROM maven:3.9.9-eclipse-temurin-17
1+
###################################################################################################
2+
# Stage 1: Build the application
3+
###################################################################################################
34

4-
# application placed into /opt/app
5-
RUN mkdir -p /app
5+
FROM dhi.io/maven:3-jdk17-debian13-dev AS build
66
WORKDIR /app
77

8-
# selectively add the POM file and
9-
# install dependencies
10-
COPY pom.xml /app/
11-
RUN mvn install
8+
# selectively add the POM file and install dependencies
9+
COPY pom.xml .
10+
RUN mvn dependency:go-offline -B
1211

13-
# rest of the project
14-
COPY src /app/src
12+
# add the src and package it
13+
COPY src src
1514
RUN mvn package
1615

17-
# local application port
18-
EXPOSE 8080
16+
###################################################################################################
17+
# Stage 2: Create the final runtime image
18+
###################################################################################################
19+
20+
FROM dhi.io/eclipse-temurin:17-debian13
21+
WORKDIR /app
1922

20-
# execute it
21-
# CMD ["mvn", "exec:java"]
22-
CMD ["java", "-jar", "target/cqlTranslationServer-2.9.0.jar", "-d"]
23+
# copy the translation service jar and dependency libs from the previous build
24+
COPY --from=build /app/target/cqlTranslationServer-*.jar cqlTranslationServer.jar
25+
COPY --from=build /app/target/libs libs/
26+
27+
# Expose the port and run it!
28+
EXPOSE 8080
29+
ENTRYPOINT ["java","-jar","/app/cqlTranslationServer.jar", "-d"]

0 commit comments

Comments
 (0)