# Report Service Dockerfile
FROM openjdk:17-slim

# Install useful tools
RUN apt-get update && apt-get install -y \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user
RUN groupadd -r erp && useradd -r -g erp erp

# Working directory
WORKDIR /app

# Copy application
COPY target/report-service-1.0.0-SNAPSHOT.jar app.jar

# Copy health check script
COPY src/main/resources/deployment/health-check.sh /app/health-check.sh
RUN chmod +x /app/health-check.sh

# Ownership
RUN chown -R erp:erp /app

# Switch to non-root user
USER erp

# Expose port
EXPOSE 8086

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD /app/health-check.sh

# JVM options
ENV JAVA_OPTS="-Xms256m -Xmx512m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Djava.security.egd=file:/dev/./urandom"

# Entry point
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"]
