Upgrade Dockerfile to JDK 25 and Scala 3.8.2
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
29
Dockerfile
29
Dockerfile
@@ -1,39 +1,42 @@
|
|||||||
# === Build stage ===
|
# === 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 && \
|
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 && \
|
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 && \
|
apt-get update && apt-get install -y sbt && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
WORKDIR /app
|
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 build.sbt .
|
||||||
COPY project/build.properties project/
|
COPY project/*.sbt project/*.properties project/*.scala project/
|
||||||
COPY project/plugins.sbt project/
|
|
||||||
RUN sbt update
|
RUN sbt update
|
||||||
|
|
||||||
# Copy source and build fat JAR
|
# Build the assembly (Fat JAR)
|
||||||
COPY src/ src/
|
COPY src/ src/
|
||||||
RUN sbt assembly
|
RUN sbt "set test in assembly := false" assembly
|
||||||
|
|
||||||
# === Runtime stage ===
|
# === 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
|
RUN addgroup -S app && adduser -S app -G app
|
||||||
WORKDIR /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
|
USER app
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Optimization: Use cgroup-aware RAM limits
|
||||||
ENV PORT=8080
|
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"]
|
ENTRYPOINT ["sh", "-c", "exec java $JAVA_OPTS -jar demoapp.jar"]
|
||||||
|
|||||||
Reference in New Issue
Block a user