From 2a7c3151eb783293da099bbeca9c7cdb71fbad08 Mon Sep 17 00:00:00 2001 From: davidtio Date: Sat, 28 Feb 2026 13:35:31 +0800 Subject: [PATCH] Upgrade Dockerfile to JDK 25 and Scala 3.8.2 Co-Authored-By: Claude Opus 4.6 --- Dockerfile | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 214ea0c..89ec471 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,42 @@ # === Build stage === -FROM eclipse-temurin:17 AS build +# Updated to JDK 25 for better performance and longer support +FROM eclipse-temurin:25-jdk AS build -# Install sbt +# Modern GPG handling & sbt install RUN apt-get update && apt-get install -y curl gnupg && \ + curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | gpg --dearmor > /etc/apt/trusted.gpg.d/sbt.gpg && \ echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" > /etc/apt/sources.list.d/sbt.list && \ - curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | apt-key add && \ apt-get update && apt-get install -y sbt && \ rm -rf /var/lib/apt/lists/* WORKDIR /app -# Cache dependency resolution +# Optimization: Copy ALL build definitions first +# This ensures caching works if your source code changes but dependencies don't. COPY build.sbt . -COPY project/build.properties project/ -COPY project/plugins.sbt project/ +COPY project/*.sbt project/*.properties project/*.scala project/ RUN sbt update -# Copy source and build fat JAR +# Build the assembly (Fat JAR) COPY src/ src/ -RUN sbt assembly +RUN sbt "set test in assembly := false" assembly # === Runtime stage === -FROM eclipse-temurin:17-jre-alpine +# Updated to the latest JRE 25 on Alpine +FROM eclipse-temurin:25-jre-alpine +# Security: Create a non-root user RUN addgroup -S app && adduser -S app -G app WORKDIR /app -COPY --from=build /app/target/scala-3.7.1/demoapp.jar ./demoapp.jar +# Adjust path for Scala 3.8.2 +COPY --from=build --chown=app:app /app/target/scala-3.8.2/demoapp.jar ./demoapp.jar -RUN chown -R app:app /app USER app - EXPOSE 8080 +# Optimization: Use cgroup-aware RAM limits ENV PORT=8080 -ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 -XX:+UseSerialGC" +ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 -XX:+UseContainerSupport -XX:+ExitOnOutOfMemoryError" ENTRYPOINT ["sh", "-c", "exec java $JAVA_OPTS -jar demoapp.jar"]