Add Docker image for Jenkins
This is a customized image of Jenkins for Docker that will fetch
these scripts and automatically run the Jenkins job builder from
jobs specified in the jenkins directory. There are some caveats
for running this image in boot2docker; see README.md for details.
The image does consume a large amount of memory and disk space!
Change-Id: I800d9997c2488fb70935732385d887bccdfd28af
diff --git a/jenkins-docker/Dockerfile b/jenkins-docker/Dockerfile
new file mode 100644
index 0000000..dbd330d
--- /dev/null
+++ b/jenkins-docker/Dockerfile
@@ -0,0 +1,55 @@
+FROM jenkins
+
+USER root
+
+RUN apt-get update && apt-get install -y \
+ python-pip \
+ python-yaml \
+ python-jenkins \
+ ant \
+ default-jdk \
+ autoconf \
+ automake \
+ maven \
+ && rm -rf /var/lib/apt/lists/*
+
+RUN mkdir -p /opt/ && git clone https://git.openstack.org/openstack-infra/jenkins-job-builder /opt/jenkins_job_builder
+
+RUN pip install /opt/jenkins_job_builder
+
+RUN git clone https://github.com/facebook/buck /opt/buck && \
+ cd /opt/buck && ant && \
+ mkdir -p /opt/buck/bin && \
+ ln -s `pwd`/bin/buck /usr/bin/ && \
+ ln -s `pwd`/bin/buckd /usr/bin/ && \
+ chown -R jenkins:jenkins /opt/buck
+
+## NOTE ##
+# Watchman can be enabled (to enable buckd) by uncommenting the following
+# lines. Note that because this caches some build results, it can lead to
+# unpredictable behavior in a continuous integration setting.
+# ENABLE AT YOUR OWN RISK!
+#
+#RUN git clone https://github.com/facebook/watchman.git /opt/watchman && \
+# cd /opt/watchman && \
+# ./autogen.sh && \
+# ./configure && \
+# make && \
+# make install
+#
+## END WATCHMAN SECTION ##
+
+RUN mkdir -p /etc/jenkins_jobs
+COPY jenkins_jobs.ini /etc/jenkins_jobs/jenkins_jobs.ini
+
+USER jenkins
+
+COPY plugins.txt /usr/share/jenkins/ref/
+RUN plugins.sh /usr/share/jenkins/ref/plugins.txt
+COPY number-executors.groovy /usr/share/jenkins/ref/init.groovy.d/
+RUN mkdir -p /usr/share/jenkins/ref/jobs/gerrit-ci-scripts/
+COPY gerrit-ci-scripts.xml /usr/share/jenkins/ref/jobs/gerrit-ci-scripts/config.xml
+RUN mkdir -p /usr/share/jenkins/ref/jobs/gerrit-ci-scripts-manual/
+COPY gerrit-ci-scripts-manual.xml /usr/share/jenkins/ref/jobs/gerrit-ci-scripts-manual/config.xml
+
+COPY gitconfig /usr/share/jenkins/ref/.gitconfig
diff --git a/jenkins-docker/README.md b/jenkins-docker/README.md
new file mode 100644
index 0000000..2a83bce
--- /dev/null
+++ b/jenkins-docker/README.md
@@ -0,0 +1,30 @@
+# Gerrit CI Docker Image
+
+This is a Docker image based on the Jenkins Docker image that allows users
+to build and test the Gerrit CI jobs automatically, based on the configuration
+at https://gerrit.googlesource.com/gerrit-ci-scripts/
+
+In turn, these CI scripts are based on
+http://docs.openstack.org/infra/jenkins-job-builder/ -- which builds Jenkins
+jobs based on YAML configurations.
+
+In this particular image, the YAML configurations are updated and jobs
+reloaded every 5 minutes via the Jenkins SCM trigger. These jobs are fetched
+from the gerrit-ci-scripts repository and automatically reloaded.
+
+It is also possible to run the gerrit-ci-scripts-manual job and provide the
+legacy Change ID number and a particular revision to build: Jenkins will fetch
+this particular change and load any job configurations changed in this revision.
+Note that it will not inhibit the main gerrit-ci-scripts trigger from polling.
+
+## Notes for users of boot2docker
+
+If you're using boot2docker, the stock drive image and memory will not be enough.
+I would recommend growing your boot2docker volume to at least 40GB, and perhaps
+adding an extra 2-4GB swap space at the end of the volume. Additionally, you
+may wish to increase the amount of memory allocated to your boot2docker VM to
+at least 3GB (4GB+ preferred). Failing to do this may result in unusual
+failures of the VM or build errors.
+
+For more information on enlarging the boot2docker volume, please see:
+https://docs.docker.com/articles/b2d_volume_resize/
diff --git a/jenkins-docker/gerrit-ci-scripts-manual.xml b/jenkins-docker/gerrit-ci-scripts-manual.xml
new file mode 100644
index 0000000..3975b24
--- /dev/null
+++ b/jenkins-docker/gerrit-ci-scripts-manual.xml
@@ -0,0 +1,52 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<project>
+ <actions/>
+ <description>Manually rebuild gerrit-ci-scripts from a specific Change ID and revision</description>
+ <keepDependencies>false</keepDependencies>
+ <properties>
+ <hudson.model.ParametersDefinitionProperty>
+ <parameterDefinitions>
+ <hudson.model.StringParameterDefinition>
+ <name>CHANGE_NUMBER</name>
+ <description>Legacy Change ID of patch to build</description>
+ <defaultValue></defaultValue>
+ </hudson.model.StringParameterDefinition>
+ <hudson.model.StringParameterDefinition>
+ <name>CHANGE_REVISION</name>
+ <description>Revision number of patch to build</description>
+ <defaultValue>1</defaultValue>
+ </hudson.model.StringParameterDefinition>
+ </parameterDefinitions>
+ </hudson.model.ParametersDefinitionProperty>
+ </properties>
+ <scm class="hudson.plugins.git.GitSCM" plugin="git@2.3.5">
+ <configVersion>2</configVersion>
+ <userRemoteConfigs>
+ <hudson.plugins.git.UserRemoteConfig>
+ <refspec>+refs/changes/*:refs/remotes/origin/*</refspec>
+ <url>https://gerrit-review.googlesource.com/gerrit-ci-scripts</url>
+ </hudson.plugins.git.UserRemoteConfig>
+ </userRemoteConfigs>
+ <branches>
+ <hudson.plugins.git.BranchSpec>
+ <name>**/$CHANGE_NUMBER/$CHANGE_REVISION</name>
+ </hudson.plugins.git.BranchSpec>
+ </branches>
+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
+ <submoduleCfg class="list"/>
+ <extensions/>
+ </scm>
+ <canRoam>true</canRoam>
+ <disabled>false</disabled>
+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
+ <triggers/>
+ <concurrentBuild>false</concurrentBuild>
+ <builders>
+ <hudson.tasks.Shell>
+ <command>jenkins-jobs update jenkins</command>
+ </hudson.tasks.Shell>
+ </builders>
+ <publishers/>
+ <buildWrappers/>
+</project>
diff --git a/jenkins-docker/gerrit-ci-scripts.xml b/jenkins-docker/gerrit-ci-scripts.xml
new file mode 100644
index 0000000..54512a3
--- /dev/null
+++ b/jenkins-docker/gerrit-ci-scripts.xml
@@ -0,0 +1,50 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<project>
+ <actions/>
+ <description>gerrit-ci-scripts update jobs via jenkins-job-builder</description>
+ <logRotator class="hudson.tasks.LogRotator">
+ <daysToKeep>-1</daysToKeep>
+ <numToKeep>10</numToKeep>
+ <artifactDaysToKeep>-1</artifactDaysToKeep>
+ <artifactNumToKeep>1</artifactNumToKeep>
+ </logRotator>
+ <keepDependencies>false</keepDependencies>
+ <properties/>
+ <scm class="hudson.plugins.git.GitSCM" plugin="git@2.3.5">
+ <configVersion>2</configVersion>
+ <userRemoteConfigs>
+ <hudson.plugins.git.UserRemoteConfig>
+ <url>https://gerrit.googlesource.com/gerrit-ci-scripts</url>
+ </hudson.plugins.git.UserRemoteConfig>
+ </userRemoteConfigs>
+ <branches>
+ <hudson.plugins.git.BranchSpec>
+ <name>*/master</name>
+ </hudson.plugins.git.BranchSpec>
+ </branches>
+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
+ <browser class="hudson.plugins.git.browser.Gitiles">
+ <url>https://gerrit.googlesource.com/gerrit-ci-scripts</url>
+ </browser>
+ <submoduleCfg class="list"/>
+ <extensions/>
+ </scm>
+ <canRoam>true</canRoam>
+ <disabled>false</disabled>
+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
+ <triggers>
+ <hudson.triggers.SCMTrigger>
+ <spec>H/5 * * * *</spec>
+ <ignorePostCommitHooks>false</ignorePostCommitHooks>
+ </hudson.triggers.SCMTrigger>
+ </triggers>
+ <concurrentBuild>false</concurrentBuild>
+ <builders>
+ <hudson.tasks.Shell>
+ <command>jenkins-jobs update jenkins</command>
+ </hudson.tasks.Shell>
+ </builders>
+ <publishers/>
+ <buildWrappers/>
+</project>
diff --git a/jenkins-docker/gitconfig b/jenkins-docker/gitconfig
new file mode 100644
index 0000000..3995d4a
--- /dev/null
+++ b/jenkins-docker/gitconfig
@@ -0,0 +1,3 @@
+[user]
+ name = Jenkins
+ email = jenkins@localhost
diff --git a/jenkins-docker/jenkins_jobs.ini b/jenkins-docker/jenkins_jobs.ini
new file mode 100644
index 0000000..521de5d
--- /dev/null
+++ b/jenkins-docker/jenkins_jobs.ini
@@ -0,0 +1,12 @@
+[job_builder]
+ignore_cache=True
+keep_descriptions=False
+include_path=~/gerrit-ci-scripts/jenkins
+recursive=False
+allow_duplicates=False
+
+[jenkins]
+#user=
+#password=1234567890abcdef1234567890abcdef
+url=http://127.0.0.1:8080
+query_plugins_info=False
diff --git a/jenkins-docker/number-executors.groovy b/jenkins-docker/number-executors.groovy
new file mode 100644
index 0000000..491715f
--- /dev/null
+++ b/jenkins-docker/number-executors.groovy
@@ -0,0 +1,10 @@
+import hudson.model.*;
+import jenkins.model.*;
+
+
+Thread.start {
+ sleep 10000
+ println "--> setting maximum number of executors on master"
+ Jenkins.instance.setNumExecutors(1)
+ Jenkins.instance.reload()
+}
diff --git a/jenkins-docker/plugins.txt b/jenkins-docker/plugins.txt
new file mode 100644
index 0000000..3e774b2
--- /dev/null
+++ b/jenkins-docker/plugins.txt
@@ -0,0 +1,4 @@
+git:latest
+git-client:latest
+scm-api:latest
+credentials:latest