Merge pull request #80 from KengoTODA/issue-48
close #48: check SHA1 hash
diff --git a/Dockerfile b/Dockerfile
index 00ea65e..6fb06b5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -19,7 +19,7 @@
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
-COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-angent-port.groovy
+COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-agent-port.groovy
ENV JENKINS_VERSION 1.596.2
ENV JENKINS_SHA 96ee85602a41d68c164fb54d4796be5d1d9cc5d0
@@ -38,6 +38,9 @@
# will be used by attached slave agents:
EXPOSE 50000
+ENV COPY_REFERENCE_FILE_LOG /var/log/copy_reference_file.log
+RUN touch $COPY_REFERENCE_FILE_LOG && chown jenkins.jenkins $COPY_REFERENCE_FILE_LOG
+
USER jenkins
COPY jenkins.sh /usr/local/bin/jenkins.sh
diff --git a/README.md b/README.md
index 9d9a956..9846eab 100644
--- a/README.md
+++ b/README.md
@@ -98,8 +98,9 @@
```
FROM jenkins
-COPY plugins /usr/share/jenkins/ref/plugins
+COPY plugins.txt /usr/share/jenkins/ref/
COPY custom.groovy /usr/share/jenkins/ref/init.groovy.d/custom.groovy
+RUN /usr/local/bin/plugins.sh /usr/share/jenkins/ref/plugins.txt
```
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.
diff --git a/jenkins.sh b/jenkins.sh
index 1bd0f85..da0dd65 100755
--- a/jenkins.sh
+++ b/jenkins.sh
@@ -6,18 +6,19 @@
# can then change this, upgrade plugins, etc.
copy_reference_file() {
f=${1%/}
- echo "$f"
+ echo "$f" >> $COPY_REFERENCE_FILE_LOG
rel=${f:23}
dir=$(dirname ${f})
- echo " $f -> $rel"
+ echo " $f -> $rel" >> $COPY_REFERENCE_FILE_LOG
if [[ ! -e /var/jenkins_home/${rel} ]]
then
- echo "copy $rel to JENKINS_HOME"
+ echo "copy $rel to JENKINS_HOME" >> $COPY_REFERENCE_FILE_LOG
mkdir -p /var/jenkins_home/${dir:23}
cp -r /usr/share/jenkins/ref/${rel} /var/jenkins_home/${rel};
fi;
}
export -f copy_reference_file
+echo "--- Copying files at $(date)" >> $COPY_REFERENCE_FILE_LOG
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
diff --git a/plugins.sh b/plugins.sh
index df060b3..8fe2e97 100755
--- a/plugins.sh
+++ b/plugins.sh
@@ -2,18 +2,20 @@
# 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/local/bin/plugins.sh /plugins.txt
-#
+#
REF=/usr/share/jenkins/ref/plugins
mkdir -p $REF
while read spec; do
- plugin=(${spec//:/ });
+ plugin=(${spec//:/ });
[[ ${plugin[0]} =~ ^# ]] && continue
[[ ${plugin[0]} =~ ^\s*$ ]] && continue
- curl -L ${JENKINS_UC}/download/plugins/${plugin[0]}/${plugin[1]}/${plugin[0]}.hpi -o $REF/${plugin[0]}.hpi;
+ [[ -z ${plugin[1]} ]] && plugin[1]="latest"
+ echo "Downloading ${plugin[0]}:${plugin[1]}"
+ curl -s -L -f ${JENKINS_UC}/download/plugins/${plugin[0]}/${plugin[1]}/${plugin[0]}.hpi -o $REF/${plugin[0]}.hpi || echo "Failed to download ${plugin[0]}:${plugin[1]}"
done < $1