-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.10.maven
More file actions
58 lines (46 loc) · 2.24 KB
/
Copy pathDockerfile.10.maven
File metadata and controls
58 lines (46 loc) · 2.24 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
# ============================================================
# Stage: Build & Run (Single-stage Maven)
# Purpose: Baseline development environment for Java 25
# ============================================================
FROM maven:3.9.16-eclipse-temurin-25-noble
# ------------------------------------------------------------
# Build Environment Configuration
# ------------------------------------------------------------
WORKDIR /app
ENV HOME=/home/appuser
ENV MAVEN_CONFIG=/home/appuser/.m2
ENV MAVEN_OPTS="-Dmaven.repo.local=/home/appuser/.m2"
LABEL maintainer="Emmanuel Bruno <emmanuel.bruno@univ-tln.fr>"
LABEL description="Java Hello World Application - Full Maven baseline"
# ------------------------------------------------------------
# Security: Unprivileged user creation
# ------------------------------------------------------------
RUN groupadd -r appgroup \
&& useradd -r -g appgroup -m -d /home/appuser appuser \
&& mkdir -p /home/appuser/.m2 \
&& chown -R appuser:appgroup /home/appuser \
&& chown -R appuser:appgroup /app
# ------------------------------------------------------------
# Layer 1: Dependency Caching
# ------------------------------------------------------------
# Copying only the wrapper and POM allows Docker to cache
# dependencies independently of source code changes.
COPY --chown=appuser:appgroup .mvn/ .mvn
COPY --chown=appuser:appgroup mvnw pom.xml ./
USER appuser
# Pre-resolve project dependencies to optimize build time
RUN ./mvnw dependency:resolve
# ------------------------------------------------------------
# Layer 2: Source Compilation
# ------------------------------------------------------------
COPY --chown=appuser:appgroup src ./src
# Build artifact using the 'jvm' profile (configured for thin JAR)
RUN ./mvnw clean package -DskipTests -Pjvm
# ------------------------------------------------------------
# Execution
# ------------------------------------------------------------
# Configure JVM container ergonomics for resource management
ENV JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"
# Explicitly invoke the JAR. The 'jvm' profile's Manifest
# automatically links to external dependencies in the /libs folder.
ENTRYPOINT ["java", "-jar", "/app/target/hello-world-0.1.0-SNAPSHOT.jar"]