# ── Stage 1: Maven build ─────────────────────────────────────────────────────
# Use the official Maven + Temurin 21 image so we don't need an installed JDK
FROM maven:3.9-eclipse-temurin-21 AS build
WORKDIR /app

# Copy POM first — lets Docker cache the dependency layer separately from source.
# Rebuilds after source-only changes skip the slow "mvn dependency:go-offline" step.
COPY pom.xml .
RUN mvn dependency:go-offline -q 2>/dev/null || true

# Copy source and build the fat-JAR (tests skipped — we only need the runtime)
COPY src/ src/
RUN mvn package -DskipTests -q

# ── Stage 2: minimal JRE runtime ─────────────────────────────────────────────
FROM eclipse-temurin:21-jre-jammy
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar

# The Spring Boot app listens on 8080 inside the container
EXPOSE 8080

ENTRYPOINT ["java", "-jar", "app.jar"]
