# ==================== BUILD STAGE ====================
FROM maven:3.9-eclipse-temurin-25-alpine AS builder
WORKDIR /app
# Copy POM first (allows for cached dependency layer)
COPY pom.xml .
# This will now work if the opencv dependency has no classifier
# -----LOCAL----
RUN mvn dependency:resolve -B
# -----LOCAL----
# RUN mvn dependency:go-offline -B

COPY src ./src
# Updated with both properties to avoid the warning
RUN mvn package -DskipTests -Dquarkus.package.jar.type=uber-jar -Dquarkus.package.jar.enabled=true

# ==================== RUNTIME STAGE ====================
FROM eclipse-temurin:25-jre
WORKDIR /app
# Create user BEFORE copying files (this fixes the error)
RUN addgroup -S quarkus && adduser -S quarkus -G quarkus
# Copy the built jar with correct pattern (use wildcard for any quarkus jar)
COPY --from=builder --chown=quarkus:quarkus /app/target/auctiora-*.jar app.jar
USER quarkus
EXPOSE 8081
ENTRYPOINT ["java", \
    "-Dio.netty.tryReflectionSetAccessible=true", \
    "--enable-native-access=ALL-UNNAMED", \
    "--sun-misc-unsafe-memory-access=allow", \
    "-jar", "app.jar"]