fix #18
copy files from /sur/share/jenkins/ref to jenkins_home
so jenkins_home can be initialized with some reference
configuration/plugins but still can be customized and
be persisted on a volume
utility script to install plugins at startup based on
support-core plugin format
diff --git a/Dockerfile b/Dockerfile
index b59322c..bf18942 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,15 +3,21 @@
RUN apt-get update && apt-get install -y wget git curl zip && rm -rf /var/lib/apt/lists/*
ENV JENKINS_VERSION 1.565.3
-RUN mkdir /usr/share/jenkins/
+
+# `/usr/share/jenkins/ref/` contains all reference configuraiton we want to set on a fresh new installation
+# use it to bundle additional plugins or config file with your custom jenkins Docker image.
+RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
+
RUN useradd -d /home/jenkins -m -s /bin/bash jenkins
-COPY init.groovy /tmp/WEB-INF/init.groovy.d/tcp-slave-angent-port.groovy
-RUN curl -L http://mirrors.jenkins-ci.org/war-stable/$JENKINS_VERSION/jenkins.war -o /usr/share/jenkins/jenkins.war \
- && cd /tmp && zip -g /usr/share/jenkins/jenkins.war WEB-INF/init.groovy.d/tcp-slave-angent-port.groovy && rm -rf /tmp/WEB-INF
+COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-angent-port.groovy
+
+# could use ADD but this one does not check Last-Modified header - see https://github.com/docker/docker/issues/8331
+RUN curl -L http://mirrors.jenkins-ci.org/war-stable/$JENKINS_VERSION/jenkins.war -o /usr/share/jenkins/jenkins.war
ENV JENKINS_HOME /var/jenkins_home
-RUN usermod -m -d "$JENKINS_HOME" jenkins && chown -R jenkins "$JENKINS_HOME"
+ENV JENKINS_UC https://updates.jenkins-ci.org
+RUN usermod -m -d "$JENKINS_HOME" jenkins && chown -R jenkins "$JENKINS_HOME" /usr/share/jenkins/ref
VOLUME /var/jenkins_home
# for main web interface:
@@ -24,3 +30,6 @@
COPY jenkins.sh /usr/local/bin/jenkins.sh
ENTRYPOINT ["/usr/local/bin/jenkins.sh"]
+
+# from a derived Dockerfile, can use `RUN plugin.sh active.txt` to setup /usr/share/jenkins/ref/plugins from a support bundle
+COPY plugins.sh /usr/local/bin/plugins.sh
diff --git a/README.md b/README.md
index 7e16f94..bd9dbdf 100644
--- a/README.md
+++ b/README.md
@@ -92,17 +92,31 @@
```
In such a derived image, you can customize your jenkins instance with hook scripts or additional plugins.
-Those need to be packaged inside the executed jenkins.war, so use :
+For this purpose, use `/usr/share/jenkins/ref` as a place to define the default JENKINS_HOME content you
+wish the target installation to look like :
```
-RUN mkdir -p /tmp/WEB-INF/plugins
-RUN curl -L https://updates.jenkins-ci.org/latest/git.hpi -o /tmp/WEB-INF/plugins/git.hpi
-RUN curl -L https://updates.jenkins-ci.org/latest/git-client.hpi -o /tmp/WEB-INF/plugins/git-client.hpi
-RUN cd /tmp; zip --grow /usr/share/jenkins/jenkins.war WEB-INF/*
+FROM jenkins
+COPY plugins /usr/share/jenkins/ref/plugins
+COPY custom.groovy /usr/share/jenkins/ref/init.groovy.d/custom.groovy
```
+When jenkins container starts, it will check JENKINS_HOME has this reference content, and copy them there if required. It will not override such files, so if you upgraded some plugins from UI they won't be reverted on next start.
+
Also see [JENKINS-24986](https://issues.jenkins-ci.org/browse/JENKINS-24986)
+For your convenience, you also can use a plain text file to define plugins to be installed (using core-support plugin format)
+```
+pluginID:version
+anotherPluginID:version
+```
+And in derived Dockerfile just invoke the utility plugin.sh script
+```
+FROM jenkins
+COPY plugins.txt /usr/share/jenkins/plugins.txt
+RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
+```
+
# Upgrading
diff --git a/jenkins.sh b/jenkins.sh
index 31dc7e4..1bd0f85 100755
--- a/jenkins.sh
+++ b/jenkins.sh
@@ -1,5 +1,25 @@
#! /bin/bash
+# Copy files from /usr/share/jenkins/ref into /var/jenkins_home
+# So the initial JENKINS-HOME is set with expected content.
+# Don't override, as this is just a reference setup, and use from UI
+# can then change this, upgrade plugins, etc.
+copy_reference_file() {
+ f=${1%/}
+ echo "$f"
+ rel=${f:23}
+ dir=$(dirname ${f})
+ echo " $f -> $rel"
+ if [[ ! -e /var/jenkins_home/${rel} ]]
+ then
+ echo "copy $rel to JENKINS_HOME"
+ mkdir -p /var/jenkins_home/${dir:23}
+ cp -r /usr/share/jenkins/ref/${rel} /var/jenkins_home/${rel};
+ fi;
+}
+export -f copy_reference_file
+find /usr/share/jenkins/ref/ -type f -exec bash -c 'copy_reference_file {}' \;
+
# if `docker run` first argument start with `--` the user is passing jenkins launcher arguments
if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
exec java $JAVA_OPTS -jar /usr/share/jenkins/jenkins.war $JENKINS_OPTS "$@"
diff --git a/plugins.sh b/plugins.sh
new file mode 100755
index 0000000..e0df32b
--- /dev/null
+++ b/plugins.sh
@@ -0,0 +1,17 @@
+#! /bin/bash
+
+# Parse a support-core plugin -style txt file as specification for jenkins plugins to be installed
+# in the reference directory, so user can define a derived Docker image with just :
+#
+# FROM jenkins
+# COPY plugins.txt /plugins.txt
+# RUN /usr/share/jenkins/plugins.sh /plugins.txt
+#
+
+REF=/usr/share/jenkins/ref/plugins
+mkdir -p $REF
+
+while read spec; do
+ plugin=(${spec//:/ });
+ curl -L ${JENKINS_UC}/download/plugins/${plugin[0]}/${plugin[1]}/${plugin[0]}.hpi -o $REF/${plugin[0]}.hpi;
+done < $1