diff --git a/.dockerignore b/.dockerignore index 841a916..5d1213d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,4 +6,4 @@ target/ *.iml *.log .DS_Store -README.md \ No newline at end of file +README.md diff --git a/Dockerfile b/Dockerfile index d5cf4be..c1f266f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,40 @@ +# ---------- Build stage ---------- FROM eclipse-temurin:21-jdk AS build WORKDIR /app -COPY . . +# Copy Maven wrapper and build configuration first for better layer caching +COPY mvnw pom.xml ./ +COPY .mvn .mvn RUN chmod +x mvnw -RUN ./mvnw -DskipTests package +# Download dependencies before copying application source +RUN ./mvnw -B dependency:go-offline -FROM eclipse-temurin:21-jre +COPY src ./src + +RUN ./mvnw -B -DskipTests package + + +# ---------- Runtime stage ---------- +FROM eclipse-temurin:21-jre AS runtime WORKDIR /app +# curl is required by the existing Docker Compose healthcheck RUN apt-get update \ && apt-get install -y --no-install-recommends curl \ - && rm -rf /var/lib/apt/lists/* - -RUN useradd --system --create-home appuser + && rm -rf /var/lib/apt/lists/* \ + && groupadd --system --gid 10001 appuser \ + && useradd --system --uid 10001 --gid appuser \ + --no-create-home appuser -COPY --from=build /app/target/*.jar app.jar +# Copy only the packaged application +COPY --from=build --chown=10001:10001 /app/target/*.jar /app/app.jar -USER appuser +USER 10001:10001 EXPOSE 8081 -ENTRYPOINT ["java", "-jar", "app.jar"] +ENTRYPOINT ["java", "-jar", "/app/app.jar"]