# Build stage
# Non-alpine tags are multi-arch (amd64 + arm64). Alpine Maven often has no Mac/ARM image.
FROM maven:3.9-eclipse-temurin-17 AS build
WORKDIR /app

COPY pom.xml .
COPY src ./src

# Use image mvn (not ./mvnw). Official maven image sets MAVEN_CONFIG=/root/.m2,
# which breaks the wrapper with: Unknown lifecycle phase "/root/.m2"
RUN mvn -q -DskipTests package

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

RUN groupadd -r qms && useradd -r -g qms 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"]
