# Build stage
FROM maven:3.9-eclipse-temurin-17-alpine AS build
WORKDIR /app

COPY pom.xml .
COPY mvnw .
COPY .mvn .mvn
COPY src ./src

RUN ./mvnw -q -DskipTests package

# Runtime stage
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app

RUN addgroup -S qms && adduser -S qms -G qms \
    && mkdir -p /app/uploads/ads \
    && chown -R qms:qms /app

COPY --from=build /app/target/bbqms-0.0.1-SNAPSHOT.jar app.jar

USER qms

EXPOSE 8080

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