# ========================================================================= # Stage 1: Build # ========================================================================= # Pin to a specific tag — do NOT use "latest" FROM maven:3.9.9-eclipse-temurin-21 AS build WORKDIR /workspace # Copy dependency manifests first (better layer caching) COPY pom.xml . COPY .mvn/ .mvn/ COPY mvnw mvnw.cmd ./ # Pre-download dependencies (cached layer) RUN ./mvnw -B dependency:go-offline # Copy sources and build COPY src/ src/ RUN ./mvnw -B clean package -DskipTests # ========================================================================= # Stage 2: Runtime # ========================================================================= # Pin to a specific tag — do NOT use "latest" FROM eclipse-temurin:21-jre-alpine # Create a non-root user and group RUN addgroup -S app && adduser -S app -G app WORKDIR /app # Copy the fat jar from the build stage COPY --from=build --chown=app:app /workspace/target/*.jar app.jar # Drop privileges USER app # Expose the HTTP port EXPOSE 8080 # Healthcheck against the public health endpoint. # Uses wget because Alpine has it by default (curl may not be installed). HEALTHCHECK --interval=10s --timeout=3s --start-period=30s --retries=3 \ CMD wget -qO- http://localhost:8080/health/live >/dev/null 2>&1 || exit 1 # PID 1 = java process. exec form so signals (SIGTERM) reach the JVM directly. ENTRYPOINT ["java", "-jar", "/app/app.jar"]