-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (46 loc) · 1.9 KB
/
Copy pathDockerfile
File metadata and controls
61 lines (46 loc) · 1.9 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
# ---- Stage 1: Build ----
FROM eclipse-temurin:21-jdk-alpine AS build
RUN apk add --no-cache maven
WORKDIR /workspace
# Copy POMs first for dependency caching
COPY pom.xml .
COPY app/pom.xml app/
COPY examples/restful-api/pom.xml examples/restful-api/
COPY examples/database/pom.xml examples/database/
COPY examples/hpc/pom.xml examples/hpc/
COPY examples/etl/pom.xml examples/etl/
COPY examples/systems/pom.xml examples/systems/
COPY examples/patterns/pom.xml examples/patterns/
COPY examples/simulation/pom.xml examples/simulation/
COPY examples/testing/pom.xml examples/testing/
RUN mvn dependency:go-offline -pl app -am -B -q
# Copy source and build
COPY . .
RUN mvn package -pl app -am -B -q -DskipTests \
&& mv app/target/template-app-*.jar /app.jar
# ---- Stage 2: Extract layered jar ----
FROM eclipse-temurin:21-jre-alpine AS extract
COPY --from=build /app.jar /app.jar
RUN java -Djarmode=tools -jar /app.jar extract --layers --launcher --destination /extracted
# ---- Stage 3: Runtime ----
FROM eclipse-temurin:21-jre-alpine
LABEL maintainer="team@example.com" \
org.opencontainers.image.title="java-enterprise-template" \
org.opencontainers.image.description="Spring Boot application" \
org.opencontainers.image.source="https://github.com/example/java-enterprise-template"
RUN addgroup -S app && adduser -S app -G app
WORKDIR /app
COPY --from=extract /extracted/dependencies/ ./
COPY --from=extract /extracted/spring-boot-loader/ ./
COPY --from=extract /extracted/snapshot-dependencies/ ./
COPY --from=extract /extracted/application/ ./
RUN chown -R app:app /app
USER app
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=3 \
CMD wget -qO- http://localhost:8080/actuator/health || exit 1
ENTRYPOINT ["java", \
"-XX:+UseContainerSupport", \
"-XX:MaxRAMPercentage=75.0", \
"-XX:+ExitOnOutOfMemoryError", \
"org.springframework.boot.loader.launch.JarLauncher"]