1
1
ARG BOOKWORM_TAG=20241016
2
2
3
3
# #####################################################
4
- # BUILD STAGE #
4
+ # BUILD STAGE #
5
5
# #####################################################
6
6
FROM debian:bookworm-"${BOOKWORM_TAG}" AS jre-build
7
7
@@ -18,20 +18,22 @@ RUN apt-get update \
18
18
jq \
19
19
&& \
20
20
21
+ echo "Downloading jdk" \
22
+ && chmod +x /usr/bin/jdk-download.sh \
23
+ && /usr/bin/jdk-download.sh && \
24
+
21
25
echo "Cleaning up" \
22
26
&& apt-get autoremove \
23
27
&& apt-get clean \
24
- && rm -rf /var/lib/apt/lists/* && \
25
-
26
- echo "Downloading jdk" \
27
- && chmod +x /usr/bin/jdk-download.sh \
28
- && /usr/bin/jdk-download.sh
28
+ && rm -rf /var/lib/apt/lists/*
29
29
30
30
ENV PATH="/opt/jdk-${JAVA_VERSION}/bin:${PATH}"
31
31
32
- # Generate smaller java runtime without unneeded files
33
- # for now we include the full module path to maintain compatibility
34
- # while still saving space (approx 200mb from the full distribution)
32
+ # --------------------------------------------------------------------#
33
+ # Generate smaller java runtime without unneeded files #
34
+ # for now we include the full module path to maintain compatibility #
35
+ # while still saving space (approx 200mb from the full distribution) #
36
+ # --------------------------------------------------------------------#
35
37
RUN case "$(jlink --version 2>&1)" in \
36
38
"17." *) set -- "--compress=2" ;; \
37
39
# the compression argument is different for JDK21
@@ -52,7 +54,18 @@ RUN case "$(jlink --version 2>&1)" in \
52
54
# #####################################################
53
55
FROM debian:bookworm-"${BOOKWORM_TAG}" AS controller
54
56
55
- # metadata labels
57
+ # ----------------------------------------------------#
58
+ # jenkins version being bundled in this docker image #
59
+ # ----------------------------------------------------#
60
+ ARG JENKINS_VERSION
61
+ ENV JENKINS_VERSION=${JENKINS_VERSION:-2.479}
62
+
63
+ ARG TARGETARCH \
64
+ COMMIT_SHA
65
+
66
+ # -----------------#
67
+ # metadata labels #
68
+ # -----------------#
56
69
LABEL \
57
70
org.opencontainers.image.vendor="Jenkins project" \
58
71
org.opencontainers.image.title="Official Jenkins Docker image" \
@@ -63,6 +76,9 @@ LABEL \
63
76
org.opencontainers.image.revision="${COMMIT_SHA}" \
64
77
org.opencontainers.image.licenses="MIT"
65
78
79
+ # ------------------------------#
80
+ # Installing required packages #
81
+ # ------------------------------#
66
82
RUN apt-get update \
67
83
&& apt-get install -y --no-install-recommends \
68
84
ca-certificates \
@@ -84,8 +100,10 @@ RUN apt-get update \
84
100
&& apt-get clean \
85
101
&& rm -rf /var/lib/apt/lists/*
86
102
87
- # Installing git-lfs
88
- RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh -o /tmp/script.deb.sh \
103
+ # --------------------#
104
+ # Installing git-lfs #
105
+ # --------------------#
106
+ RUN curl -fsSL https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh -o /tmp/script.deb.sh \
89
107
&& bash /tmp/script.deb.sh \
90
108
&& rm -f /tmp/script.deb.sh \
91
109
&& apt-get install -y --no-install-recommends git-lfs \
@@ -96,89 +114,88 @@ RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.d
96
114
&& apt-get clean \
97
115
&& rm -rf /var/lib/apt/lists/*
98
116
117
+ ENV LANG=C.UTF-8
99
118
100
- # ----------------------------------------------------------------------#
101
- # JENKINS_VERSION: jenkins version being bundled in this docker image #
102
- # ----------------------------------------------------------------------#
103
- ARG JENKINS_VERSION
104
- ENV JENKINS_VERSION="${JENKINS_VERSION:-2.479}"
105
-
106
- # -----------------------------------------------------------------------------#
107
- # JENKINS_SHA: jenkins.war checksum, download will be validated using it #
108
- # -----------------------------------------------------------------------------#
109
- # JENKINS_URL: Can be used to customize where jenkins.war get downloaded from #
110
- # -----------------------------------------------------------------------------#
111
- ARG JENKINS_SHA="910ea36cef37c45087e39d65e335988e036fccea47c79cc5a52e721a10cb1b49" \
112
- JENKINS_URL="https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war" \
113
- TARGETARCH \
114
- COMMIT_SHA \
115
- user=jenkins \
119
+ ARG user=jenkins \
116
120
group=jenkins \
117
121
uid=1000 \
118
122
gid=1000 \
119
123
http_port=8080 \
120
124
agent_port=50000 \
121
- JENKINS_HOME="/var/jenkins_home" \
122
- REF="/usr/share/jenkins/ref" \
123
- PLUGIN_CLI_VERSION="2.13.2" \
124
- PLUGIN_CLI_URL="https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/${PLUGIN_CLI_VERSION}/jenkins-plugin-manager-${PLUGIN_CLI_VERSION}.jar"
125
-
126
- ENV LANG=C.UTF-8 \
127
- JENKINS_HOME="$JENKINS_HOME" \
128
- JENKINS_SLAVE_AGENT_PORT="${agent_port}" \
129
- JENKINS_UC="https://updates.jenkins.io" \
130
- JENKINS_UC_EXPERIMENTAL="https://updates.jenkins.io/experimental" \
131
- JENKINS_INCREMENTALS_REPO_MIRROR="https://repo.jenkins-ci.org/incrementals" \
132
- COPY_REFERENCE_FILE_LOG="$JENKINS_HOME/copy_reference_file.log" \
133
- JAVA_HOME="/opt/java/openjdk" \
134
- REF=$REF
125
+ JENKINS_HOME=/var/jenkins_home \
126
+ REF=/usr/share/jenkins/ref
135
127
128
+ ENV JENKINS_HOME=$JENKINS_HOME \
129
+ JENKINS_SLAVE_AGENT_PORT=${agent_port} \
130
+ REF=$REF
136
131
137
132
# ---------------------------------------------------------------#
138
133
# Jenkins is run with user `jenkins`, uid = 1000 #
139
134
# If you bind mount a volume from the host or a data container, #
140
- # ensure you use the same uid #
141
- # -------------------------------------------------------------------------------------------#
142
- # $REF (defaults to `/usr/share/jenkins/ref/`) contains all reference configuration we want #
143
- # to set on a fresh new installation. Use it to bundle additional plugins #
144
- # or config file with your custom jenkins Docker image. #
145
- # ----------------------------------------------------------------------------------------------------------#
146
- # could use ADD but this one does not check Last-Modified header neither does it allow to control checksum #
147
- # see https://github.com/docker/docker/issues/8331 #
148
- # ----------------------------------------------------------------------------------------------------------#
135
+ # ensure you use the same uid(e.g. 1000) #
136
+ # ---------------------------------------------------------------#
149
137
RUN mkdir -p $JENKINS_HOME \
150
138
&& chown ${uid}:${gid} $JENKINS_HOME \
151
139
&& groupadd -g ${gid} ${group} \
152
- && useradd -d "$JENKINS_HOME" -u ${uid} -g ${gid} -l -m -s /bin/bash ${user} && \
140
+ && useradd -d "$JENKINS_HOME" -u ${uid} -g ${gid} -l -m -s /bin/bash ${user}
153
141
154
- echo "---------------------------------------" \
155
- && mkdir -p ${REF}/init.groovy.d \
156
- && chown -R ${user} "$JENKINS_HOME" "$REF" && \
142
+ # -----------------------------------------------------------------------------------#
143
+ # $REF (defaults to `/usr/share/jenkins/ref/`) contains all reference configuration #
144
+ # we want to set on a fresh new installation. Use it to bundle additional plugins #
145
+ # or config file with your custom jenkins Docker image. #
146
+ # -----------------------------------------------------------------------------------#
147
+ RUN mkdir -p ${REF}/init.groovy.d
148
+
149
+ # ------------------------------------------------------------------------#
150
+ # JENKINS_SHA: jenkins.war checksum, download will be validated using it #
151
+ # -----------------------------------------------------------------------------#
152
+ # JENKINS_URL: Can be used to customize where jenkins.war get downloaded from #
153
+ # -----------------------------------------------------------------------------#
154
+ ARG JENKINS_SHA=910ea36cef37c45087e39d65e335988e036fccea47c79cc5a52e721a10cb1b49 \
155
+ JENKINS_URL="https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war"
157
156
158
- echo "---------------------------------------" \
159
- && curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \
157
+ # ----------------------------------------------------------------------------------------------------------#
158
+ # could use ADD but this one does not check Last-Modified header neither does it allow to control checksum #
159
+ # see https://github.com/docker/docker/issues/8331 #
160
+ # ----------------------------------------------------------------------------------------------------------#
161
+ RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \
160
162
&& echo "${JENKINS_SHA} /usr/share/jenkins/jenkins.war" >/tmp/jenkins_sha \
161
163
&& sha256sum -c --strict /tmp/jenkins_sha \
162
- && rm -f /tmp/jenkins_sha && \
164
+ && rm -f /tmp/jenkins_sha
163
165
164
- echo "---------------------------------------" \
165
- && curl -fsSL ${PLUGIN_CLI_URL} -o /opt/jenkins-plugin-manager.jar \
166
- && echo "$(curl -fsSL " ${PLUGIN_CLI_URL}.sha256") /opt/jenkins-plugin-manager.jar" > /tmp/jenkins_sha \
166
+ ENV JENKINS_UC=https://updates.jenkins.io \
167
+ JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental \
168
+ JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
169
+ RUN chown -R ${user} "$JENKINS_HOME" "$REF"
170
+
171
+ ARG PLUGIN_CLI_VERSION=2.13.2 \
172
+ PLUGIN_CLI_URL=https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/${PLUGIN_CLI_VERSION}/jenkins-plugin-manager-${PLUGIN_CLI_VERSION}.jar
173
+ RUN curl -fsSL ${PLUGIN_CLI_URL} -o /opt/jenkins-plugin-manager.jar \
174
+ && echo "$(curl -fsSL " ${PLUGIN_CLI_URL}.sha256") /opt/jenkins-plugin-manager.jar" >/tmp/jenkins_sha \
167
175
&& sha256sum -c --strict /tmp/jenkins_sha \
168
176
&& rm -f /tmp/jenkins_sha
169
177
178
+ ENV COPY_REFERENCE_FILE_LOG=$JENKINS_HOME/copy_reference_file.log \
179
+ JAVA_HOME=/opt/java/openjdk
170
180
171
181
ENV PATH="${JAVA_HOME}/bin:${PATH}"
182
+
172
183
COPY --from=jre-build /javaruntime $JAVA_HOME
173
184
174
185
COPY ["./jenkins-support" , "./jenkins.sh" , "/usr/local/bin/" ]
175
186
COPY ["./jenkins-plugin-cli.sh" , "/bin/jenkins-plugin-cli" ]
176
187
177
- # Jenkins home directory is a volume, so configuration and build history
178
- # can be persisted and survive image upgrades
188
+ # ---------------------------------------------------------------#
189
+ # Jenkins home directory is a volume, so configuration #
190
+ # and build history can be persisted and survive image upgrades #
191
+ # ---------------------------------------------------------------#
179
192
VOLUME $JENKINS_HOME
180
193
181
- # for main web interface + for attached agents
194
+ # ------------------------------------------#
195
+ # ${http_port}: for main web interface #
196
+ # ------------------------------------------#
197
+ # ${agent_port}: for attached agents #
198
+ # ------------------------------------------#
182
199
EXPOSE ${http_port} ${agent_port}
183
200
184
201
USER ${user}
0 commit comments