Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev committed May 27, 2015
0 parents commit 7177e66
Show file tree
Hide file tree
Showing 53 changed files with 3,575 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target
work

demo/Dockerfile
demo/.cache/
# TODO: remove once this plugin is released
demo/JENKINS_HOME/plugins/
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License

Copyright (c) 2015, CloudBees, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CloudBees Docker Workflow Plugin
=====================================

Jenkins plugin, which allows building and using Docker containers from workflows.

Summary
---
The plugin provides:
* DSL commands for building and running Docker images
* Wrapper blocks defining Docker server and registry endpoints
* Actions displaying images related to the build (to be merged with docker-commons)
* etc.

More info is available on the plugin's [Wiki page](http://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Workflow+Plugin)

Demo
---
The plugin has a Docker-based demo. See the [demo README](demo/README.md) page for setup and launch guidelines.

License
---
[MIT License](http://opensource.org/licenses/MIT)
1 change: 1 addition & 0 deletions demo/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cache
59 changes: 59 additions & 0 deletions demo/Dockerfile_release
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
##
# The MIT License
#
# Copyright (c) 2015, CloudBees, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
##

FROM jenkinsci/workflow-demo:1.7-alpha-1

###############################################################
# Docker in Docker https://github.com/jpetazzo/dind

# Install Docker from Docker Inc. repositories.
RUN curl -sSL https://get.docker.com/ubuntu/ | sh

# Install the magic wrapper.
ADD wrapdocker /usr/local/bin/wrapdocker
RUN chmod +x /usr/local/bin/wrapdocker

# Define additional metadata for our image.
VOLUME /var/lib/docker

#
###############################################################

COPY workflow-reg-proxy.conf /tmp/files/regup/workflow-reg-proxy.conf
COPY gen-security-data.sh /usr/local/bin/gen-security-data.sh
RUN /usr/local/bin/gen-security-data.sh /tmp/files/regup/sec
RUN apt-get install -y apparmor
COPY run-demo.sh /usr/local/bin/run-demo.sh

COPY plugins.txt /tmp/files/
RUN /usr/local/bin/plugins.sh /tmp/files/plugins.txt
RUN touch /usr/share/jenkins/ref/plugins/credentials.jpi.pinned

ADD JENKINS_HOME /usr/share/jenkins/ref

# TODO until https://github.com/jenkinsci/docker/pull/89 is picked up upstream, shut up please:
RUN perl -i -p -e 's/ *echo.+//g' /usr/local/bin/jenkins.sh

# wrapdocker has been modified to launch Jenkins via the installed run.sh script
CMD ["wrapdocker"]
60 changes: 60 additions & 0 deletions demo/Dockerfile_snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
##
# The MIT License
#
# Copyright (c) 2015, CloudBees, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
##

FROM jenkinsci/workflow-demo:SNAPSHOT

###############################################################
# Docker in Docker https://github.com/jpetazzo/dind

# Install Docker from Docker Inc. repositories.
RUN curl -sSL https://get.docker.com/ubuntu/ | sh

# Install the magic wrapper.
ADD wrapdocker /usr/local/bin/wrapdocker
RUN chmod +x /usr/local/bin/wrapdocker

# Define additional metadata for our image.
VOLUME /var/lib/docker

#
###############################################################

RUN apt-get install -y apparmor apache2-utils

COPY workflow-reg-proxy.conf /tmp/files/regup/workflow-reg-proxy.conf
COPY gen-security-data.sh /usr/local/bin/gen-security-data.sh
RUN /usr/local/bin/gen-security-data.sh /tmp/files/regup/sec
COPY run-demo.sh /usr/local/bin/run-demo.sh

COPY plugins.txt /tmp/files/
RUN /usr/local/bin/plugins.sh /tmp/files/plugins.txt
RUN touch /usr/share/jenkins/ref/plugins/credentials.jpi.pinned

ADD JENKINS_HOME /usr/share/jenkins/ref

# TODO until https://github.com/jenkinsci/docker/pull/89 is picked up upstream, shut up please:
RUN perl -i -p -e 's/ *echo.+//g' /usr/local/bin/jenkins.sh

# wrapdocker has been modified to launch Jenkins via the installed run.sh script
CMD ["wrapdocker"]
34 changes: 34 additions & 0 deletions demo/JENKINS_HOME/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson>
<disabledAdministrativeMonitors/>
<version>1.0</version>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/>
<securityRealm class="hudson.security.SecurityRealm$None"/>
<disableRememberMe>false</disableRememberMe>
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
<workspaceDir>${ITEM_ROOTDIR}/workspace</workspaceDir>
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir>
<jdks/>
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
<clouds/>
<slaves/>
<scmCheckoutRetryCount>0</scmCheckoutRetryCount>
<views>
<hudson.model.AllView>
<owner class="hudson" reference="../../.."/>
<name>All</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
</hudson.model.AllView>
</views>
<primaryView>All</primaryView>
<slaveAgentPort>0</slaveAgentPort>
<label></label>
<nodeProperties/>
<globalNodeProperties/>
</hudson>
19 changes: 19 additions & 0 deletions demo/JENKINS_HOME/credentials.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version='1.0' encoding='UTF-8'?>
<com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="[email protected]">
<domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash">
<entry>
<com.cloudbees.plugins.credentials.domains.Domain>
<specifications/>
</com.cloudbees.plugins.credentials.domains.Domain>
<java.util.concurrent.CopyOnWriteArrayList>
<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
<scope>GLOBAL</scope>
<id>docker-registry-login</id>
<description></description>
<username>workflowuser</username>
<password>123123123</password>
</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
</java.util.concurrent.CopyOnWriteArrayList>
</entry>
</domainCredentialsMap>
</com.cloudbees.plugins.credentials.SystemCredentialsProvider>
72 changes: 72 additions & 0 deletions demo/JENKINS_HOME/jobs/docker-workflow/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version='1.0' encoding='UTF-8'?>
<flow-definition>
<actions/>
<description>Demonstrates Jenkins Workflow integration with Docker based on&#xd;
&lt;a href=&quot;https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Workflow+Plugin&quot;&gt;CloudBees Docker Workflow&lt;/a&gt; plugin
</description>
<keepDependencies>false</keepDependencies>
<properties/>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition">
<script>node {
def maven32 = docker.image(&apos;maven:3.2-jdk-7-onbuild&apos;); // https://registry.hub.docker.com/_/maven/;

stage &apos;Mirror&apos;
// First make sure the slave has this image.
// (If you could set your registry below to mirror Docker Hub,
// this would be unnecessary as maven32.inside would pull the image.)
maven32.pull()
// We are pushing to a private secure docker registry in this demo.
// &apos;docker-registry-login&apos; is the username/password credentials ID as defined in Jenkins Credentials.
// This is used to authenticate the docker client to the registry.
docker.withRegistry(&apos;https://docker.example.com/&apos;, &apos;docker-registry-login&apos;) {

stage &apos;Build&apos;

// spin up a Maven container to build the petclinic app from source
// (we are only using -v here to share the Maven local repository across demo runs; otherwise would set localRepository=${pwd}/m2repo)
maven32.inside(&apos;-v /m2repo:/m2repo&apos;) {
// Check out the source code.
git &apos;https://github.com/tfennelly/spring-petclinic.git&apos;

// Set up a shared Maven repo so we don&apos;t need to download all dependencies on every build.
writeFile file: &apos;settings.xml&apos;, text: &apos;&lt;settings&gt;&lt;localRepository&gt;/m2repo&lt;/localRepository&gt;&lt;/settings&gt;&apos;
// Build with Maven settings.xml file that specs the local Maven repo.
sh &apos;mvn -B -s settings.xml clean install -DskipTests&apos;

// The app .war and Dockerfile are now available in the workspace. See below.
}

stage &apos;Bake Docker image&apos;
// use the spring-petclinic Dockerfile (see above &apos;maven32.inside()&apos; block)
// to build container that can run the app. The Dockerfile is in the cwd of the active workspace
// (see above maven32.inside() block), so we pass &apos;.&apos; as the build PATH param. The Dockerfile
// (see https://github.com/tfennelly/spring-petclinic/blob/master/Dockerfile) expects the petclinic.war
// file to be in the &apos;target&apos; dir of the workspace, which will be the case.
def pcImg = docker.build(&quot;examplecorp/spring-petclinic:${env.BUILD_TAG}&quot;, &apos;.&apos;)

// Let&apos;s tag and push the newly built image. Will tag using the image name provided
// in the &apos;docker.build&apos; call above (which included the build number on the tag).
pcImg.push();

stage &apos;Test Image&apos;
// Run the petclinic app in its own docker container
pcImg.withRun {petclinic -&gt;
// Spin up a maven test container, linking it to the petclinic app container allowing
// the maven tests to fire HTTP requests between the containers.
maven32.inside(&quot;-v /m2repo:/m2repo --link=${petclinic.id}:petclinic&quot;) {
git &apos;https://github.com/tfennelly/spring-petclinic-tests.git&apos;

writeFile file: &apos;settings.xml&apos;, text: &apos;&lt;settings&gt;&lt;localRepository&gt;/m2repo&lt;/localRepository&gt;&lt;/settings&gt;&apos;
sh &apos;mvn -B -s settings.xml clean package&apos;
}
}

stage name: &apos;Promote Image&apos;, concurrency: 1
// All the tests passed. We can now retag and push the &apos;latest&apos; image
pcImg.push(&apos;latest&apos;);
}
}</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
</flow-definition>
73 changes: 73 additions & 0 deletions demo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
##
# The MIT License
#
# Copyright (c) 2015, CloudBees, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
##
TAG=$(shell cat workflow-version.txt)
IMAGE=jenkinsci/docker-workflow-demo
CACHE=$(shell pwd)/.cache

#
# Build from the Dockerfile_release Dockerfile
# Only run this target when the project pom dependencies are RELEASED dependencies.
#
# TODO: Remove and delete ./get-snapshots.sh once this plugin is released. See comment in ./get-snapshots.sh
#
build:
./get-snapshots.sh
docker build -t $(IMAGE):$(TAG) -f Dockerfile_release .

#
# Build from the Dockerfile_release Dockerfile
# Only run this target when the project pom dependencies are SNAPSHOT dependencies.
#
# TODO: Remove and delete ./get-snapshots.sh once this plugin is released. See comment in ./get-snapshots.sh
#
build-snapshot:
./get-snapshots.sh
docker build -t $(IMAGE):SNAPSHOT -f Dockerfile_snapshot .

#
# To connect a Java debugger to the Jenkins instance running in the docker container, simply add the following
# options to the "docker run" command (just after the port mappings):
#
# -p 5500:5500 -e JAVA_OPTS=-Xrunjdwp:transport=dt_socket,server=y,address=5500,suspend=n
#
# If using boot2docker, you need to tell your remote debugger to use the boot2docker VM ip (ala boot2docker ip).
#

run:
docker run --rm -p 8080:8080 -p 8081:8081 -p 8022:22 -p 18080:18080 --add-host=docker.example.com:127.0.0.1 -ti --privileged $(IMAGE):$(TAG)

run-snapshot:
docker run --rm -p 8080:8080 -p 8081:8081 -p 8022:22 -p 18080:18080 --add-host=docker.example.com:127.0.0.1 -ti --privileged $(IMAGE):SNAPSHOT

run-snapshot-cached:
mkdir -p $(CACHE)/docker
sudo rm -rf $(CACHE)/docker/containers $(CACHE)/docker/linkgraph.db
mkdir -p $(CACHE)/maven
docker run --rm -p 8080:8080 -p 8081:8081 -p 8022:22 -p 18080:18080 --add-host=docker.example.com:127.0.0.1 -ti --privileged -v $(CACHE)/docker:/var/lib/docker -v $(CACHE)/maven:/m2repo $(IMAGE):SNAPSHOT

clean:
rm -rf JENKINS_HOME/plugins

push:
docker push $(IMAGE):SNAPSHOT
Loading

0 comments on commit 7177e66

Please sign in to comment.