# ---------- Build stage ----------
FROM maven:3.9-eclipse-temurin-17 AS build
WORKDIR /build
# Cache dependencies first
COPY pom.xml .
RUN mvn -B -q dependency:go-offline
# Build the app
COPY src ./src
RUN mvn -B -q -DskipTests clean package

# ---------- Runtime stage ----------
FROM eclipse-temurin:17-jre
WORKDIR /app
# Uploaded documents/photos live here (mounted as a volume)
ENV STORAGE_DIR=/data/uploads
RUN mkdir -p /data/uploads
COPY --from=build /build/target/car-rental-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-XX:MaxRAMPercentage=75", "-jar", "app.jar"]
