diff --git a/api/Dockerfile b/api/Dockerfile index 6513df81..0e30a21e 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,24 +1,13 @@ -FROM amazoncorretto:17 -LABEL authors="dario" - -# Install Maven -RUN yum install -y tar which gzip - -ENV MAVEN_HOME /usr/share/maven - -COPY --from=maven:3.9.6-eclipse-temurin-11 ${MAVEN_HOME} ${MAVEN_HOME} -COPY --from=maven:3.9.6-eclipse-temurin-11 /usr/local/bin/mvn-entrypoint.sh /usr/local/bin/mvn-entrypoint.sh -COPY --from=maven:3.9.6-eclipse-temurin-11 /usr/share/maven/ref/settings-docker.xml /usr/share/maven/ref/settings-docker.xml - -RUN ln -s ${MAVEN_HOME}/bin/mvn /usr/bin/mvn - -ARG MAVEN_VERSION=3.9.6 -ARG USER_HOME_DIR="/root" -ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" - -ENTRYPOINT ["/usr/local/bin/mvn-entrypoint.sh"] -CMD ["mvn"] +FROM maven:3.8.1-openjdk-17 AS build +# Compile api +WORKDIR /api +COPY . /api +WORKDIR /api +RUN mvn install +RUN mvn clean package +FROM amazoncorretto:17 AS runtime +# Copy the compiled jar file from the build stage ARG DATABASE_USER ARG DATABASE_PASSWORD ARG JWT_SECRET @@ -28,12 +17,7 @@ ENV DATABASE_URL jdbc:postgresql://WIQ_DB:5432/wiq ENV DATABASE_USER $DATABASE_USER ENV DATABASE_PASSWORD $DATABASE_PASSWORD ENV JWT_SECRET $JWT_SECRET -# Compile api -COPY . /api -WORKDIR /api -RUN mvn install -COPY target/*.jar app.jar +COPY --from=build /api/target/quiz-api-0.0.1-SNAPSHOT.jar app.jar ENTRYPOINT ["java","-jar","app.jar"] - EXPOSE 8080 \ No newline at end of file