From f4f078cd4095464dd608b1ff23e241a90886eba2 Mon Sep 17 00:00:00 2001 From: Guillaume Lours Date: Thu, 12 Mar 2020 14:29:50 +0100 Subject: [PATCH] Improve Dockerfile Signed-off-by: Guillaume Lours --- samples/spring-postgres/backend/Dockerfile | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/samples/spring-postgres/backend/Dockerfile b/samples/spring-postgres/backend/Dockerfile index abeeae4..949dd0a 100755 --- a/samples/spring-postgres/backend/Dockerfile +++ b/samples/spring-postgres/backend/Dockerfile @@ -1,12 +1,20 @@ -FROM maven:3.6.3-jdk-11 AS build -COPY pom.xml . -RUN mvn --batch-mode dependency:resolve -COPY . . -RUN mvn --batch-mode package -RUN cp target/*jar target/app.jar +FROM maven:3.6.3-jdk-11 AS builder +WORKDIR /workdir/server +COPY pom.xml /workdir/server/pom.xml +RUN mvn dependency:go-offline + +COPY src /workdir/server/src +RUN mvn install +RUN mkdir -p target/depency +WORKDIR /workdir/server/target/dependency +RUN jar -xf ../*.jar + +FROM openjdk:11-jre-slim -FROM openjdk:11-jre EXPOSE 8080 VOLUME /tmp -COPY --from=build target/app.jar app.jar -ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] +ARG DEPENDENCY=/workdir/server/target/dependency +COPY --from=builder ${DEPENDENCY}/BOOT-INF/lib /app/lib +COPY --from=builder ${DEPENDENCY}/META-INF /app/META-INF +COPY --from=builder ${DEPENDENCY}/BOOT-INF/classes /app +ENTRYPOINT ["java","-cp","app:app/lib/*","com.company.project.Application"] \ No newline at end of file