-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.40.manual
More file actions
93 lines (74 loc) · 3.75 KB
/
Copy pathDockerfile.40.manual
File metadata and controls
93 lines (74 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# ============================================================
# Stage 1: Build Environment (Manual SDKMAN Toolchain)
# Purpose: Demonstrate manual environment provisioning and
# fixed-UID/GID file ownership for high-security CI.
# ============================================================
FROM ubuntu:noble AS stage-build
# Toolchain versioning for reproducible builds
ARG JAVA_VERSION="25.0.3-tem"
ARG MAVEN_VERSION="3.9.16"
ARG BUILDER_UID=2000
ARG BUILDER_GID=2000
LABEL maintainer="Emmanuel Bruno <emmanuel.bruno@univ-tln.fr>"
LABEL description="Java Hello World Application - SDKMAN build"
# ------------------------------------------------------------
# OS Layer: Provision essential tools for SDKMAN
# ------------------------------------------------------------
RUN apt-get update && \
apt-get install --yes --quiet --no-install-recommends \
ca-certificates curl unzip zip bash && \
rm -rf /var/lib/apt/lists/*
# ------------------------------------------------------------
# Security: Create dedicated builder user with deterministic UID/GID
# ------------------------------------------------------------
RUN groupadd -g ${BUILDER_GID} builder \
&& useradd -m -u ${BUILDER_UID} -g builder -s /bin/bash builder
USER builder
ENV HOME=/home/builder
ENV SDKMAN_DIR="$HOME/.sdkman"
ENV PATH="$SDKMAN_DIR/bin:$SDKMAN_DIR/candidates/java/current/bin:$SDKMAN_DIR/candidates/maven/current/bin:$PATH"
SHELL ["/bin/bash", "-c"]
# ------------------------------------------------------------
# Provisioning: Install Java/Maven via SDKMAN
# ------------------------------------------------------------
RUN curl -s "https://get.sdkman.io" | bash && \
source "$SDKMAN_DIR/bin/sdkman-init.sh" && \
sdk install java "$JAVA_VERSION" && \
sdk install maven "$MAVEN_VERSION" && \
rm -rf "$SDKMAN_DIR/archives/*" "$SDKMAN_DIR/tmp/*"
WORKDIR /app
# ------------------------------------------------------------
# Layer: Dependency Resolution (BuildKit Cached)
# ------------------------------------------------------------
COPY --chown=builder:builder mvnw ./
COPY --chown=builder:builder .mvn .mvn
COPY --chown=builder:builder pom.xml ./
RUN --mount=type=cache,target=/home/builder/.m2,uid=${BUILDER_UID},gid=${BUILDER_GID} \
source "$SDKMAN_DIR/bin/sdkman-init.sh" && \
./mvnw --batch-mode dependency:resolve
# ------------------------------------------------------------
# Layer: Build
# ------------------------------------------------------------
COPY --chown=builder:builder src ./src
RUN --mount=type=cache,target=/home/builder/.m2,uid=${BUILDER_UID},gid=${BUILDER_GID} \
source "$SDKMAN_DIR/bin/sdkman-init.sh" && \
./mvnw --batch-mode -Pjvm -DskipTests clean verify
# ============================================================
# Stage 2: Runtime Environment
# ============================================================
# Distribute using a slim JRE-only image. Note: We do not require
# the UID to match the builder; we only need a non-root user.
FROM eclipse-temurin:25-jre-noble AS stage-runtime
LABEL maintainer="Emmanuel Bruno <emmanuel.bruno@univ-tln.fr>"
LABEL description="Java Hello World Application - multi-stage runtime"
RUN groupadd -r appgroup && useradd -r -g appgroup appuser && \
mkdir -p /app && chown -R appuser:appgroup /app
# Deploy minimal runtime artifacts from the build stage
COPY --from=stage-build --chown=appuser:appgroup /app/target/hello-world-*-SNAPSHOT.jar /app/app.jar
COPY --from=stage-build --chown=appuser:appgroup /app/target/libs /app/libs
USER appuser
ENV HOME=/home/appuser
# JVM Container Ergonomics: JAVA_TOOL_OPTIONS is natively parsed by the
# JVM, enabling container-aware resource management.
ENV JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"
ENTRYPOINT ["java", "-jar", "/app/app.jar"]