Skip to content

Commit 0832831

Browse files
slideoleg-nenashev
authored andcommitted
#709,#861 - Make the REF_DIR configurable in plugin installation scripts (#866)
* Fix jenkinsci/docker/issues/861 This allows overriding the default REF dir * Fix other references to hardcoded offset * Fix test * Add REF ENV item This will make it so that REF will have a default value
1 parent fc0053c commit 0832831

File tree

10 files changed

+77
-27
lines changed

10 files changed

+77
-27
lines changed

Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ ARG gid=1000
99
ARG http_port=8080
1010
ARG agent_port=50000
1111
ARG JENKINS_HOME=/var/jenkins_home
12+
ARG REF=/usr/share/jenkins/ref
1213

1314
ENV JENKINS_HOME $JENKINS_HOME
1415
ENV JENKINS_SLAVE_AGENT_PORT ${agent_port}
16+
ENV REF $REF
1517

1618
# Jenkins is run with user `jenkins`, uid = 1000
1719
# If you bind mount a volume from the host or a data container,
@@ -25,10 +27,10 @@ RUN mkdir -p $JENKINS_HOME \
2527
# can be persisted and survive image upgrades
2628
VOLUME $JENKINS_HOME
2729

28-
# `/usr/share/jenkins/ref/` contains all reference configuration we want
30+
# $REF (defaults to `/usr/share/jenkins/ref/`) contains all reference configuration we want
2931
# to set on a fresh new installation. Use it to bundle additional plugins
3032
# or config file with your custom jenkins Docker image.
31-
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
33+
RUN mkdir -p ${REF}/init.groovy.d
3234

3335
# Use tini as subreaper in Docker container to adopt zombie processes
3436
ARG TINI_VERSION=v0.16.1
@@ -58,7 +60,7 @@ RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \
5860
ENV JENKINS_UC https://updates.jenkins.io
5961
ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
6062
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
61-
RUN chown -R ${user} "$JENKINS_HOME" /usr/share/jenkins/ref
63+
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
6264

6365
# for main web interface:
6466
EXPOSE ${http_port}
@@ -75,6 +77,6 @@ COPY jenkins.sh /usr/local/bin/jenkins.sh
7577
COPY tini-shim.sh /bin/tini
7678
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
7779

78-
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup /usr/share/jenkins/ref/plugins from a support bundle
80+
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup ${REF}/plugins from a support bundle
7981
COPY plugins.sh /usr/local/bin/plugins.sh
8082
COPY install-plugins.sh /usr/local/bin/install-plugins.sh

Dockerfile-alpine

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ ARG gid=1000
99
ARG http_port=8080
1010
ARG agent_port=50000
1111
ARG JENKINS_HOME=/var/jenkins_home
12+
ARG REF=/usr/share/jenkins/ref
1213

1314
ENV JENKINS_HOME $JENKINS_HOME
1415
ENV JENKINS_SLAVE_AGENT_PORT ${agent_port}
16+
ENV REF $REF
1517

1618
# Jenkins is run with user `jenkins`, uid = 1000
1719
# If you bind mount a volume from the host or a data container,
@@ -25,10 +27,10 @@ RUN mkdir -p $JENKINS_HOME \
2527
# can be persisted and survive image upgrades
2628
VOLUME $JENKINS_HOME
2729

28-
# `/usr/share/jenkins/ref/` contains all reference configuration we want
30+
# $REF (defaults to `/usr/share/jenkins/ref/`) contains all reference configuration we want
2931
# to set on a fresh new installation. Use it to bundle additional plugins
3032
# or config file with your custom jenkins Docker image.
31-
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
33+
RUN mkdir -p ${REF}/init.groovy.d
3234

3335
# jenkins version being bundled in this docker image
3436
ARG JENKINS_VERSION
@@ -48,7 +50,7 @@ RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \
4850
ENV JENKINS_UC https://updates.jenkins.io
4951
ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
5052
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
51-
RUN chown -R ${user} "$JENKINS_HOME" /usr/share/jenkins/ref
53+
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
5254

5355
# for main web interface:
5456
EXPOSE ${http_port}
@@ -65,6 +67,6 @@ COPY jenkins.sh /usr/local/bin/jenkins.sh
6567
COPY tini-shim.sh /bin/tini
6668
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
6769

68-
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup /usr/share/jenkins/ref/plugins from a support bundle
70+
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup $REF/plugins from a support bundle
6971
COPY plugins.sh /usr/local/bin/plugins.sh
7072
COPY install-plugins.sh /usr/local/bin/install-plugins.sh

Dockerfile-centos

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ ARG gid=1000
1010
ARG http_port=8080
1111
ARG agent_port=50000
1212
ARG JENKINS_HOME=/var/jenkins_home
13+
ARG REF=/usr/share/jenkins/ref
1314

1415
ENV JENKINS_HOME $JENKINS_HOME
1516
ENV JENKINS_SLAVE_AGENT_PORT ${agent_port}
17+
ENV REF $REF
1618

1719
# Jenkins is run with user `jenkins`, uid = 1000
1820
# If you bind mount a volume from the host or a data container,
@@ -26,10 +28,10 @@ RUN mkdir -p $JENKINS_HOME \
2628
# can be persisted and survive image upgrades
2729
VOLUME $JENKINS_HOME
2830

29-
# `/usr/share/jenkins/ref/` contains all reference configuration we want
31+
# $REF (defaults to `/usr/share/jenkins/ref/`) contains all reference configuration we want
3032
# to set on a fresh new installation. Use it to bundle additional plugins
3133
# or config file with your custom jenkins Docker image.
32-
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
34+
RUN mkdir -p ${REF}/init.groovy.d
3335

3436
# Use tini as subreaper in Docker container to adopt zombie processes
3537
ARG TINI_VERSION=v0.16.1
@@ -59,7 +61,7 @@ RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \
5961
ENV JENKINS_UC https://updates.jenkins.io
6062
ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
6163
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
62-
RUN chown -R ${user} "$JENKINS_HOME" /usr/share/jenkins/ref
64+
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
6365

6466
# for main web interface:
6567
EXPOSE ${http_port}
@@ -76,6 +78,6 @@ COPY jenkins.sh /usr/local/bin/jenkins.sh
7678
COPY tini-shim.sh /bin/tini
7779
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
7880

79-
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup /usr/share/jenkins/ref/plugins from a support bundle
81+
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup $REF/plugins from a support bundle
8082
COPY plugins.sh /usr/local/bin/plugins.sh
8183
COPY install-plugins.sh /usr/local/bin/install-plugins.sh

Dockerfile-jdk11

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ ARG gid=1000
99
ARG http_port=8080
1010
ARG agent_port=50000
1111
ARG JENKINS_HOME=/var/jenkins_home
12+
ARG REF=/usr/share/jenkins/ref
1213

1314
ENV JENKINS_HOME $JENKINS_HOME
1415
ENV JENKINS_SLAVE_AGENT_PORT ${agent_port}
16+
ENV REF $REF
1517

1618
# Jenkins is run with user `jenkins`, uid = 1000
1719
# If you bind mount a volume from the host or a data container,
@@ -25,10 +27,10 @@ RUN mkdir -p $JENKINS_HOME \
2527
# can be persisted and survive image upgrades
2628
VOLUME $JENKINS_HOME
2729

28-
# `/usr/share/jenkins/ref/` contains all reference configuration we want
30+
# $REF (defaults to `/usr/share/jenkins/ref/`) contains all reference configuration we want
2931
# to set on a fresh new installation. Use it to bundle additional plugins
3032
# or config file with your custom jenkins Docker image.
31-
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
33+
RUN mkdir -p ${REF}/init.groovy.d
3234

3335
# Use tini as subreaper in Docker container to adopt zombie processes
3436
ARG TINI_VERSION=v0.16.1
@@ -58,7 +60,7 @@ RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \
5860
ENV JENKINS_UC https://updates.jenkins.io
5961
ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
6062
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
61-
RUN chown -R ${user} "$JENKINS_HOME" /usr/share/jenkins/ref
63+
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
6264

6365
# for main web interface:
6466
EXPOSE ${http_port}
@@ -76,6 +78,6 @@ COPY jenkins.sh /usr/local/bin/jenkins.sh
7678
COPY tini-shim.sh /bin/tini
7779
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
7880

79-
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup /usr/share/jenkins/ref/plugins from a support bundle
81+
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup $REF/plugins from a support bundle
8082
COPY plugins.sh /usr/local/bin/plugins.sh
8183
COPY install-plugins.sh /usr/local/bin/install-plugins.sh

Dockerfile-slim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ ARG gid=1000
99
ARG http_port=8080
1010
ARG agent_port=50000
1111
ARG JENKINS_HOME=/var/jenkins_home
12+
ARG REF=/usr/share/jenkins/ref
1213

1314
ENV JENKINS_HOME $JENKINS_HOME
1415
ENV JENKINS_SLAVE_AGENT_PORT ${agent_port}
16+
ENV REF $REF
1517

1618
# Jenkins is run with user `jenkins`, uid = 1000
1719
# If you bind mount a volume from the host or a data container,
@@ -25,10 +27,10 @@ RUN mkdir -p $JENKINS_HOME \
2527
# can be persisted and survive image upgrades
2628
VOLUME $JENKINS_HOME
2729

28-
# `/usr/share/jenkins/ref/` contains all reference configuration we want
30+
# $REF (defaults to `/usr/share/jenkins/ref/`) contains all reference configuration we want
2931
# to set on a fresh new installation. Use it to bundle additional plugins
3032
# or config file with your custom jenkins Docker image.
31-
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
33+
RUN mkdir -p ${REF}/init.groovy.d
3234

3335
# Use tini as subreaper in Docker container to adopt zombie processes
3436
ARG TINI_VERSION=v0.16.1
@@ -58,7 +60,7 @@ RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \
5860
ENV JENKINS_UC https://updates.jenkins.io
5961
ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
6062
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
61-
RUN chown -R ${user} "$JENKINS_HOME" /usr/share/jenkins/ref
63+
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
6264

6365
# for main web interface:
6466
EXPOSE ${http_port}
@@ -75,6 +77,6 @@ COPY jenkins.sh /usr/local/bin/jenkins.sh
7577
COPY tini-shim.sh /bin/tini
7678
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
7779

78-
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup /usr/share/jenkins/ref/plugins from a support bundle
80+
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup $REF/plugins from a support bundle
7981
COPY plugins.sh /usr/local/bin/plugins.sh
8082
COPY install-plugins.sh /usr/local/bin/install-plugins.sh

install-plugins.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020

2121
set -o pipefail
2222

23-
REF_DIR=${REF:-/usr/share/jenkins/ref/plugins}
24-
FAILED="$REF_DIR/failed-plugins.txt"
2523

2624
JENKINS_WAR=${JENKINS_WAR:-/usr/share/jenkins/jenkins.war}
2725

2826
. /usr/local/bin/jenkins-support
2927

28+
REF_DIR="${REF}/plugins"
29+
FAILED="$REF_DIR/failed-plugins.txt"
30+
3031
getLockFile() {
3132
printf '%s' "$REF_DIR/${1}.lock"
3233
}

jenkins-support

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash -eu
22

3+
: "${REF:="/usr/share/jenkins/ref"}"
4+
35
# compare if version1 < version2
46
versionLT() {
57
local v1; v1=$(echo "$1" | cut -d '-' -f 1 )
@@ -40,9 +42,9 @@ get_plugin_version() {
4042
copy_reference_file() {
4143
f="${1%/}"
4244
b="${f%.override}"
43-
rel="${b:23}"
45+
rel="${b#"$REF/"}"
4446
version_marker="${rel}.version_from_image"
45-
dir=$(dirname "${b}")
47+
dir=$(dirname "${rel}")
4648
local action;
4749
local reason;
4850
local container_version;
@@ -103,7 +105,7 @@ copy_reference_file() {
103105
if [[ ! -e $JENKINS_HOME/${rel} || "$action" == "UPGRADED" || $f = *.override ]]; then
104106
action=${action:-"INSTALLED"}
105107
log=true
106-
mkdir -p "$JENKINS_HOME/${dir:23}"
108+
mkdir -p "$JENKINS_HOME/${dir}"
107109
cp -pr "${f}" "$JENKINS_HOME/${rel}";
108110
# pin plugins on initial copy
109111
touch "$JENKINS_HOME/${rel}.pinned"
@@ -117,7 +119,7 @@ copy_reference_file() {
117119
then
118120
action="INSTALLED"
119121
log=true
120-
mkdir -p "$JENKINS_HOME/${dir:23}"
122+
mkdir -p "$JENKINS_HOME/${dir}"
121123
cp -pr "$(realpath "${f}")" "$JENKINS_HOME/${rel}";
122124
else
123125
action="SKIPPED"

jenkins.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
: "${JENKINS_WAR:="/usr/share/jenkins/jenkins.war"}"
44
: "${JENKINS_HOME:="/var/jenkins_home"}"
55
: "${COPY_REFERENCE_FILE_LOG:="${JENKINS_HOME}/copy_reference_file.log"}"
6+
: "${REF:="/usr/share/jenkins/ref"}"
67
touch "${COPY_REFERENCE_FILE_LOG}" || { echo "Can not write to ${COPY_REFERENCE_FILE_LOG}. Wrong volume permissions?"; exit 1; }
78
echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
8-
find /usr/share/jenkins/ref/ \( -type f -o -type l \) -exec bash -c '. /usr/local/bin/jenkins-support; for arg; do copy_reference_file "$arg"; done' _ {} +
9+
find "${REF}" \( -type f -o -type l \) -exec bash -c '. /usr/local/bin/jenkins-support; for arg; do copy_reference_file "$arg"; done' _ {} +
910

1011
# if `docker run` first argument start with `--` the user is passing jenkins launcher arguments
1112
if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then

tests/install-plugins.bats

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,39 @@ SUT_IMAGE=$(sut_image)
5454
assert_line 'docker-plugin.jpi.pinned'
5555
}
5656

57+
@test "plugins are installed with install-plugins.sh with non-default REF" {
58+
run docker_build_child $SUT_IMAGE-install-plugins-ref $BATS_TEST_DIRNAME/install-plugins/ref
59+
assert_success
60+
refute_line --partial 'Skipping already installed dependency'
61+
docker run --rm $SUT_IMAGE-install-plugins-ref -e REF=/var/lib/jenkins/ref ls --color=never -1 /var/lib/jenkins/ref | tr -d '\r'
62+
63+
# replace DOS line endings \r\n
64+
run bash -c "docker run --rm $SUT_IMAGE-install-plugins ls --color=never -1 /var/jenkins_home/plugins | tr -d '\r'"
65+
assert_success
66+
assert_line 'maven-plugin.jpi'
67+
assert_line 'maven-plugin.jpi.pinned'
68+
assert_line 'ant.jpi'
69+
assert_line 'ant.jpi.pinned'
70+
assert_line 'credentials.jpi'
71+
assert_line 'credentials.jpi.pinned'
72+
assert_line 'mesos.jpi'
73+
assert_line 'mesos.jpi.pinned'
74+
# optional dependencies
75+
refute_line 'metrics.jpi'
76+
refute_line 'metrics.jpi.pinned'
77+
# plugins bundled but under detached-plugins, so need to be installed
78+
assert_line 'javadoc.jpi'
79+
assert_line 'javadoc.jpi.pinned'
80+
assert_line 'mailer.jpi'
81+
assert_line 'mailer.jpi.pinned'
82+
assert_line 'git.jpi'
83+
assert_line 'git.jpi.pinned'
84+
assert_line 'filesystem_scm.jpi'
85+
assert_line 'filesystem_scm.jpi.pinned'
86+
assert_line 'docker-plugin.jpi'
87+
assert_line 'docker-plugin.jpi.pinned'
88+
}
89+
5790
@test "plugins are installed with install-plugins.sh from a plugins file" {
5891
run docker_build_child $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins
5992
assert_success

tests/install-plugins/ref/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM bats-jenkins-install-plugins
2+
3+
RUN rm -rf /usr/share/jenkins/ref ; /usr/local/bin/install-plugins.sh maven-plugin:2.13 ant:1.3

0 commit comments

Comments
 (0)