From 086d9fb4ae24e4a68fecac47e0225f782d41298c Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 16 Feb 2015 22:30:06 -0600 Subject: [PATCH] [jenkins] Initial commit of self-upgrading Jenkins --- jenkins/Dockerfile | 13 +++++++++++++ jenkins/README.md | 25 +++++++++++++++++++++++++ jenkins/download-and-start.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 jenkins/Dockerfile create mode 100644 jenkins/README.md create mode 100755 jenkins/download-and-start.sh diff --git a/jenkins/Dockerfile b/jenkins/Dockerfile new file mode 100644 index 00000000..71879620 --- /dev/null +++ b/jenkins/Dockerfile @@ -0,0 +1,13 @@ +FROM itzg/ubuntu-openjdk-7 + +MAINTAINER itzg + +RUN DEBIAN_FRONTEND=noninteractive apt-get -y install curl && apt-get clean + +ADD download-and-start.sh /download-and-start + +ENV JENKINS_HOME /data +VOLUME ["/data"] +EXPOSE 8080 + +CMD ["/download-and-start"] diff --git a/jenkins/README.md b/jenkins/README.md new file mode 100644 index 00000000..ff96ddc1 --- /dev/null +++ b/jenkins/README.md @@ -0,0 +1,25 @@ +A self-upgrading [Jenkins CI](http://jenkins-ci.org/) server + +# Basic Usage + +To start Jenkins with the latest version: + + ID=$(docker run -d -p 8080:8080 itzg/jenkins) + +At a later time, you can upgrade by restarting the container: + + docker stop $ID + docker start $ID + +# Attaching host directory to Jenkins home directory + +The Jenkins home directory is attachable at `/data`, so attaching to a host volume +would be: + + ID=$(docker run -d -p 8080:8080 -v /SOME_HOST_DIR:/data itzg/jenkins + +# Entering the container to perform manual config + +As with any Docker container, you can run a shell within the running container: + + docker exec -it $ID bash diff --git a/jenkins/download-and-start.sh b/jenkins/download-and-start.sh new file mode 100755 index 00000000..a930a0b9 --- /dev/null +++ b/jenkins/download-and-start.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +mirrorUrl=http://mirrors.jenkins-ci.org/war/latest/jenkins.war +url=$(curl -s --head $mirrorUrl|awk -F': ' '$1 == "Location" { print $2 }' | sed 's/[[:space:]]*$//') +version=$(echo $url | sed 's#.*/war/\(.*\)/jenkins.war#\1#') + +mkdir -p /opt/jenkins +trackingFile=/opt/jenkins/INSTALLED + +installed= +if [ -f $trackingFile ]; then + installed=$(cat $trackingFile) + echo "Version installed is $installed" +fi + +if [ $version != "$installed" ]; then + echo "Downloading $version from '$url'" + while ! curl -s -o /opt/jenkins/jenkins.war "$url" + do + echo "Trying again in 5 seconds" + sleep 5 + done + + echo $version > $trackingFile +fi + + +cd /opt/jenkins +exec java -jar jenkins.war