Skip to content

Commit

Permalink
Implement a multi stage build and automate the creation of the public…
Browse files Browse the repository at this point in the history
… and private keys in the docker file
  • Loading branch information
mertkaanguzel committed Jan 24, 2024
1 parent eab10bc commit e05c2c7
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
FROM openjdk:21

EXPOSE 8080
FROM openjdk:21-jdk-slim as build-env

WORKDIR /usr/src/myapp

# COPY . .

COPY pom.xml mvnw ./
RUN chmod +x ./mvnw
COPY .mvn .mvn
RUN ./mvnw dependency:resolve

COPY src src

RUN apt-get update && apt-get -y install openssl && \
mkdir ./src/main/resources/certs && cd ./src/main/resources/certs && \
openssl genrsa -out keypair.pem 2048 && \
openssl rsa -in keypair.pem -pubout -out public.pem && \
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt \
-in keypair.pem -out private.pem && rm keypair.pem

RUN ./mvnw package

FROM eclipse-temurin:21.0.1_12-jre

WORKDIR /

COPY --from=build-env /usr/src/myapp/target/medium-clone.jar .

EXPOSE 8080

ENTRYPOINT [ "java" ]

CMD [ "-jar", "./target/medium-clone.jar" ]
CMD [ "-jar", "./medium-clone.jar" ]

0 comments on commit e05c2c7

Please sign in to comment.