FROM maven:3.9.6-eclipse-temurin-17 AS build

WORKDIR /app

# Copy only pom.xml first (better layer caching)
COPY doodlestudent/api/pom.xml .

# Download dependencies
RUN mvn dependency:go-offline

# Copy the rest of the source code
COPY doodlestudent/api/src ./src

# Build the application
RUN mvn package -DskipTests

# ---------------------------
# Stage 2 - Runtime
# ---------------------------
FROM eclipse-temurin:17-jre-alpine

WORKDIR /app

# Copy the built application from the build stage
COPY --from=build /app/target/quarkus-app/ ./quarkus-app/

# Quarkus default port
EXPOSE 8080

# Run the application
ENTRYPOINT ["java", "-jar", "quarkus-app/quarkus-run.jar"]