| # Skynet Simplified Dockerfile |
| # Single build path with tests and CodeNarc |
|
|
| ########################################### |
| # Builder - Complete build with all checks |
| ########################################### |
| FROM gradle:8.5-jdk21 AS builder |
|
|
| # Set working directory |
| WORKDIR /workspace |
|
|
| # Copy Gradle wrapper and build files first (for better caching) |
| COPY gradlew ./ |
| COPY gradle/ gradle/ |
| COPY build.gradle settings.gradle ./ |
| COPY config/ config/ |
|
|
| # Download dependencies (this layer will be cached unless build files change) |
| RUN ./gradlew --no-daemon dependencies |
|
|
| # Copy source code |
| COPY src/ src/ |
|
|
| # Build the application skipping CodeNarc checks |
| RUN ./gradlew --no-daemon clean build |
|
|
| # Copy the JAR |
| RUN cp build/libs/skynet.jar /workspace/skynet.jar |
|
|
| ########################################### |
| # Runtime - Production runtime environment |
| ########################################### |
| FROM eclipse-temurin:21-jre |
|
|
| # Create non-root user |
| RUN groupadd -r skynet && useradd -r -g skynet skynet |
|
|
| # Install curl for health checks |
| RUN apt-get update && \ |
| apt-get install -y --no-install-recommends curl && \ |
| rm -rf /var/lib/apt/lists |
|
|
| # Set working directory |
| WORKDIR /app |
|
|
| # Copy the JAR from builder stage |
| COPY --from=builder /workspace/skynet.jar /app/skynet.jar |
|
|
| # Create logs directory and set ownership |
| RUN mkdir -p /app/logs && chown -R skynet:skynet /app |
|
|
| # Switch to non-root user |
| USER skynet |
|
|
| # Expose the application port |
| EXPOSE 8080 |
|
|
| # Health check endpoint |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ |
| CMD curl -f http://localhost:8080/actuator/health || exit 1 |
|
|
| # JVM optimization for containers (reasonable defaults) |
| ENV JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -XX:+UseG1GC -XX:+UseStringDeduplication" |
|
|
| # Only set the server port since it's needed for EXPOSE |
| ENV SERVER_PORT=8080 |
|
|
| # Run the application |
| ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/skynet.jar"] |
|
|
| # Default command (can be overridden) |
| CMD [] |
| |