-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathDockerfile_4_custom_jre
More file actions
90 lines (72 loc) · 2.38 KB
/
Dockerfile_4_custom_jre
File metadata and controls
90 lines (72 loc) · 2.38 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
# Définir une variable globale pour le fichier JAR
ARG JAR_FILE=spring-boot-efficient-search-api-*.jar
##
## Build stage
##
#FROM maven:3.9.11-eclipse-temurin-24-alpine AS maven_build
#COPY . /.
#RUN mvn clean package -DskipTests
##########################
#
# Step 1: Build a custom JRE
#
FROM eclipse-temurin:25-alpine AS build-jre
# Copy the application JAR file
# Rendre la variable ARG disponible dans ce stage
ARG JAR_FILE
#COPY --from=maven_build ./target/${JAR_FILE} /app/app.jar
COPY ./target/${JAR_FILE} /app/app.jar
WORKDIR /app
# Install required tools for jlink
RUN apk add --no-cache binutils
# Unpack the JAR, analyze dependencies, and build a minimal JRE
RUN mkdir -p unpacked && \
unzip app.jar -d unpacked && \
$JAVA_HOME/bin/jdeps \
--ignore-missing-deps \
--print-module-deps \
-q \
--recursive \
--multi-release 24 \
--class-path="unpacked/BOOT-INF/lib/*" \
--module-path="unpacked/BOOT-INF/lib/*" \
app.jar > /dependencies.info && \
rm -rf unpacked && \
$JAVA_HOME/bin/jlink \
--verbose \
--add-modules $(cat /dependencies.info) \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=zip-6 \
--output /customjre
RUN file0="$(cat /dependencies.info)" && echo $file0
##########################
#
# Step 2: Build the main application image
#
FROM alpine:latest
# Set environment variables for the JRE
ENV JAVA_HOME=/jre
ENV PATH="${JAVA_HOME}/bin:${PATH}"
# Copy the custom JRE from the previous stage
COPY --from=build-jre /customjre $JAVA_HOME
# Add a non-root user for the application
ARG APPLICATION_USER=appuser
RUN adduser --no-create-home -u 1000 -D $APPLICATION_USER
# Configure the working directory
RUN mkdir /app && chown -R $APPLICATION_USER /app
# Set the working directory
WORKDIR /app
# Copy the application JAR file
ARG JAR_FILE
#COPY --chown=1000:1000 --from=maven_build ./target/${JAR_FILE} /app/app.jar
COPY --chown=1000:1000 ./target/${JAR_FILE} /app/app.jar
# Expose the application port
EXPOSE 8080
# Define the entrypoint to run the application
ENTRYPOINT [ "java", "-jar", "/app/app.jar" ]
# docker build -t spring-boot-efficient-search-api_4 . -f ./Dockerfile_4_custom_jre
# docker run -d -p 8444:8080 spring-boot-efficient-search-api_4
# docker images --filter=reference='spring-boot-efficient-search-api*' | sort
#[+] Building 154.0s (19/19) FINISHED