# Build stage
FROM maven:3.9-eclipse-temurin-11 AS build
WORKDIR /build
COPY pom.xml .
COPY src ./src
RUN mvn clean package -DskipTests

# Runtime stage - using headless JRE to reduce size
FROM eclipse-temurin:11-jre-jammy
WORKDIR /app

# Install minimal OpenCV runtime libraries (not the full dev package)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    libopencv-core4.5d \
    libopencv-imgcodecs4.5d \
    libopencv-dnn4.5d && \
    rm -rf /var/lib/apt/lists/*

# Copy the JAR file
COPY --from=build /build/target/troostwijk-scraper-1.0-SNAPSHOT-jar-with-dependencies.jar app.jar

# Set OpenCV library path and notification config
ENV LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
ENV NOTIFICATION_CONFIG=desktop

ENTRYPOINT ["java", "-Djava.library.path=/usr/lib/x86_64-linux-gnu", "-jar", "/app/app.jar"]
