Skip to content

Commit 2c2ef2c

Browse files
committed
Resolved some issues
1.Moved Variables back to their possitions for caching advantage. 2.Moved needed variables for lables on the top. 3.Split some RUN statements back for caching advantage. 4. Enhanced comments
1 parent 063405a commit 2c2ef2c

File tree

1 file changed

+81
-64
lines changed

1 file changed

+81
-64
lines changed

debian/bookworm/hotspot/Dockerfile

+81-64
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ARG BOOKWORM_TAG=20241016
22

33
######################################################
4-
# BUILD STAGE #
4+
# BUILD STAGE #
55
######################################################
66
FROM debian:bookworm-"${BOOKWORM_TAG}" AS jre-build
77

@@ -18,20 +18,22 @@ RUN apt-get update \
1818
jq \
1919
&& \
2020

21+
echo "Downloading jdk" \
22+
&& chmod +x /usr/bin/jdk-download.sh \
23+
&& /usr/bin/jdk-download.sh && \
24+
2125
echo "Cleaning up" \
2226
&& apt-get autoremove \
2327
&& 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/*
2929

3030
ENV PATH="/opt/jdk-${JAVA_VERSION}/bin:${PATH}"
3131

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+
#--------------------------------------------------------------------#
3537
RUN case "$(jlink --version 2>&1)" in \
3638
"17."*) set -- "--compress=2" ;; \
3739
# the compression argument is different for JDK21
@@ -52,7 +54,18 @@ RUN case "$(jlink --version 2>&1)" in \
5254
######################################################
5355
FROM debian:bookworm-"${BOOKWORM_TAG}" AS controller
5456

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+
#-----------------#
5669
LABEL \
5770
org.opencontainers.image.vendor="Jenkins project" \
5871
org.opencontainers.image.title="Official Jenkins Docker image" \
@@ -63,6 +76,9 @@ LABEL \
6376
org.opencontainers.image.revision="${COMMIT_SHA}" \
6477
org.opencontainers.image.licenses="MIT"
6578

79+
#------------------------------#
80+
# Installing required packages #
81+
#------------------------------#
6682
RUN apt-get update \
6783
&& apt-get install -y --no-install-recommends \
6884
ca-certificates \
@@ -84,8 +100,10 @@ RUN apt-get update \
84100
&& apt-get clean \
85101
&& rm -rf /var/lib/apt/lists/*
86102

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 \
89107
&& bash /tmp/script.deb.sh \
90108
&& rm -f /tmp/script.deb.sh \
91109
&& 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
96114
&& apt-get clean \
97115
&& rm -rf /var/lib/apt/lists/*
98116

117+
ENV LANG=C.UTF-8
99118

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 \
116120
group=jenkins \
117121
uid=1000 \
118122
gid=1000 \
119123
http_port=8080 \
120124
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
135127

128+
ENV JENKINS_HOME=$JENKINS_HOME \
129+
JENKINS_SLAVE_AGENT_PORT=${agent_port} \
130+
REF=$REF
136131

137132
#---------------------------------------------------------------#
138133
# Jenkins is run with user `jenkins`, uid = 1000 #
139134
# 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+
#---------------------------------------------------------------#
149137
RUN mkdir -p $JENKINS_HOME \
150138
&& chown ${uid}:${gid} $JENKINS_HOME \
151139
&& 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}
153141

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"
157156

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 \
160162
&& echo "${JENKINS_SHA} /usr/share/jenkins/jenkins.war" >/tmp/jenkins_sha \
161163
&& sha256sum -c --strict /tmp/jenkins_sha \
162-
&& rm -f /tmp/jenkins_sha && \
164+
&& rm -f /tmp/jenkins_sha
163165

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 \
167175
&& sha256sum -c --strict /tmp/jenkins_sha \
168176
&& rm -f /tmp/jenkins_sha
169177

178+
ENV COPY_REFERENCE_FILE_LOG=$JENKINS_HOME/copy_reference_file.log \
179+
JAVA_HOME=/opt/java/openjdk
170180

171181
ENV PATH="${JAVA_HOME}/bin:${PATH}"
182+
172183
COPY --from=jre-build /javaruntime $JAVA_HOME
173184

174185
COPY ["./jenkins-support", "./jenkins.sh", "/usr/local/bin/"]
175186
COPY ["./jenkins-plugin-cli.sh", "/bin/jenkins-plugin-cli"]
176187

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+
#---------------------------------------------------------------#
179192
VOLUME $JENKINS_HOME
180193

181-
# for main web interface + for attached agents
194+
#------------------------------------------#
195+
# ${http_port}: for main web interface #
196+
#------------------------------------------#
197+
# ${agent_port}: for attached agents #
198+
#------------------------------------------#
182199
EXPOSE ${http_port} ${agent_port}
183200

184201
USER ${user}

0 commit comments

Comments
 (0)