Spaces:
Build error
Build error
| # Ultra-minimal Alpine + Custom JRE | |
| # Expected size: ~120-160MB | |
| # Stage 1: Create custom JRE with only needed modules | |
| FROM eclipse-temurin:21-jdk-alpine as jre-builder | |
| WORKDIR /app | |
| # Analyze JAR to find required modules | |
| COPY build/libs/*.jar app.jar | |
| RUN jdeps --ignore-missing-deps --print-module-deps app.jar > modules.txt | |
| # Create minimal JRE with only required modules | |
| RUN jlink \ | |
| --add-modules $(cat modules.txt),java.logging,java.xml,java.sql,java.naming,java.desktop,java.management,java.security.jgss,java.instrument \ | |
| --strip-debug \ | |
| --no-man-pages \ | |
| --no-header-files \ | |
| --compress=2 \ | |
| --output /custom-jre | |
| # Stage 2: Production image | |
| FROM alpine:3.19 | |
| RUN apk add --no-cache tzdata && \ | |
| addgroup -g 1001 -S appgroup && \ | |
| adduser -u 1001 -S appuser -G appgroup | |
| # Copy custom JRE | |
| COPY --from=jre-builder /custom-jre /opt/java | |
| ENV JAVA_HOME=/opt/java | |
| ENV PATH="$JAVA_HOME/bin:$PATH" | |
| WORKDIR /app | |
| COPY build/libs/*.jar app.jar | |
| RUN chown appuser:appgroup app.jar | |
| USER appuser | |
| EXPOSE 8080 | |
| ENTRYPOINT ["java", \ | |
| "-XX:+UseContainerSupport", \ | |
| "-XX:MaxRAMPercentage=70.0", \ | |
| "-XX:+UseG1GC", \ | |
| "-jar", "app.jar"] | |