-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a multi stage build and automate the creation of the public…
… and private keys in the docker file
- Loading branch information
1 parent
eab10bc
commit e05c2c7
Showing
1 changed file
with
18 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |