Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,25 @@ A full description is available in the plugin’s [documentation](https://go.clo

Demo
---
The plugin has an outdated Docker-based demo. See the [demo README from v1.12](https://github.com/jenkinsci/docker-workflow-plugin/tree/docker-workflow-1.12/demo) for setup and launch guidelines.
The plugin has a Docker-based demo. See the [demo README](demo/README.md) page for setup and launch guidelines.

Releasing
---

Prior to release, edit `demo/plugins.txt` to use the snapshot version and run:

mvn -DskipTests clean install
make -C demo run

and verify that the demo works.

After the Maven release completes, update the `docker-workflow` version in `demo/plugins.txt` to the release version and run

make -C demo run

to sanity check, then

make -C demo push-latest

License
---
Expand Down
2 changes: 2 additions & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plugins/
certs/
71 changes: 71 additions & 0 deletions demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
##
# 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 jenkins/jenkins

USER root

# Install Docker client
ENV DOCKER_BUCKET get.docker.com
ENV DOCKER_VERSION 1.12.6

RUN set -x \
&& curl -fSL "https://${DOCKER_BUCKET}/builds/Linux/x86_64/docker-$DOCKER_VERSION.tgz" -o docker.tgz \
&& tar -xzvf docker.tgz \
&& mv docker/* /usr/local/bin/ \
&& rmdir docker \
&& rm docker.tgz \
&& docker -v

RUN cd /opt && \
curl -s https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz | tar xvfz - && \
ln -s /opt/apache-maven-3.8.6/bin/mvn /usr/bin && \
which mvn && \
mvn -version

ADD repo /tmp/repo
RUN git config --global user.email "demo@jenkins-ci.org" && git config --global user.name "Docker Workflow Demo" && cd /tmp/repo && git init && git add . && git commit -m 'demo'

# Run commands identical to those in Pipeline script to warm up the cache:
RUN echo '<settings><mirrors><mirror><id>central</id><url>http://repo.jenkins-ci.org/public/</url><mirrorOf>*</mirrorOf></mirror></mirrors></settings>' > settings.xml
RUN mvn -s settings.xml -Dmaven.repo.local=/usr/share/jenkins/ref/jobs/docker-workflow/workspace@tmp/m2repo -f /tmp/repo/app -B -DskipTests clean package && \
mvn -s settings.xml -Dmaven.repo.local=/usr/share/jenkins/ref/jobs/docker-workflow/workspace@tmp/m2repo -f /tmp/repo/test -B -Dmaven.test.failure.ignore clean test
# TODO switch to a persistent volume as in parallel-test-executor-demo, after making sure run-demo.sh starts by deleting snapshots from it

RUN jenkins-plugin-cli --plugins \
credentials-binding \
docker-workflow \
xvnc
COPY docker-workflow.jpi /usr/share/jenkins/ref/plugins

ADD JENKINS_HOME /usr/share/jenkins/ref

COPY run-demo.sh /usr/local/bin/run-demo.sh
ENV JAVA_OPTS -Djenkins.install.state=INITIAL_SECURITY_SETUP

RUN chown -R jenkins.jenkins /usr/share/jenkins/ref /tmp/repo

USER jenkins

CMD /usr/local/bin/run-demo.sh
7 changes: 7 additions & 0 deletions demo/Dockerfile-registry
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM registry:2.5.1
ADD certs/ca.crt certs/ca.key certs/docker-registry.htpasswd /var/registry/certs/
ENV REGISTRY_HTTP_TLS_CERTIFICATE /var/registry/certs/ca.crt
ENV REGISTRY_HTTP_TLS_KEY /var/registry/certs/ca.key
ENV REGISTRY_AUTH htpasswd
ENV REGISTRY_AUTH_HTPASSWD_REALM Registry Realm
ENV REGISTRY_AUTH_HTPASSWD_PATH /var/registry/certs/docker-registry.htpasswd
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="credentials@1.9.4">
<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>pipelineuser</username>
<password>123123123</password>
</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
</java.util.concurrent.CopyOnWriteArrayList>
</entry>
</domainCredentialsMap>
</com.cloudbees.plugins.credentials.SystemCredentialsProvider>
26 changes: 26 additions & 0 deletions demo/JENKINS_HOME/jobs/docker-workflow/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<flow-definition>
<actions/>
<description>Demonstrates Jenkins Pipeline integration with Docker based on the Docker Pipeline Plugin.</description>
<keepDependencies>false</keepDependencies>
<properties/>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition">
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>/tmp/repo</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/master</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions/>
</scm>
<scriptPath>flow.groovy</scriptPath>
</definition>
</flow-definition>
27 changes: 27 additions & 0 deletions demo/JENKINS_HOME/jobs/puller/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version='1.0' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@2.9">
<actions/>
<description>JENKINS-34276 verification; run after docker-workflow #1</description>
<keepDependencies>false</keepDependencies>
<properties>
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
<triggers/>
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@2.23">
<script>node {
echo 'Start with an empty local cache:'
sh &apos;(docker images -q examplecorp/spring-petclinic; docker images -q localhost/examplecorp/spring-petclinic) | xargs docker rmi --no-prune=true --force || :&apos;
docker.withRegistry(&apos;https://localhost/&apos;, &apos;docker-registry-login&apos;) {
echo 'Missing initially, should pull and get latest tag:'
docker.image(&apos;examplecorp/spring-petclinic&apos;).inside {
sh &apos;ls -l /tomcat7/webapps/petclinic.war&apos;
}
echo 'This time it should be in local cache and not need to pull:'
docker.image(&apos;examplecorp/spring-petclinic&apos;).inside {}
}
}</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
</flow-definition>
65 changes: 65 additions & 0 deletions demo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
##
# 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 date -I -u)
IMAGE=jenkinsci/docker-workflow-demo

build-registry:
./gen-security-data.sh certs
docker build -t registry:docker-workflow-demo -f Dockerfile-registry .

../target/docker-workflow.hpi: ../pom.xml $(shell find ../src ../.mvn)
mvn -f .. -Pquick-build clean package

build: ../target/docker-workflow.hpi build-registry
docker build -t $(IMAGE):$(TAG) .

# 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).

ifeq ($(shell uname -s),Darwin)
STAT_OPT = -f
else
STAT_OPT = -c
endif

DOCKER_RUN=docker run --rm -p 127.0.0.1:8080:8080 -v /var/run/docker.sock:/var/run/docker.sock --group-add=$(shell stat $(STAT_OPT) %g /var/run/docker.sock)

run: build
$(DOCKER_RUN) $(IMAGE):$(TAG)

clean:
rm -rf certs plugins

push:
docker push $(IMAGE):$(TAG)
echo "consider also: make push-latest"

push-latest: push
docker tag $(IMAGE):$(TAG) $(IMAGE):latest
docker push $(IMAGE):latest
33 changes: 33 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Docker image for Docker Pipeline demo
=====================================
This image contains a "Docker Pipeline" Job that demonstrates Jenkins Pipeline integration
with Docker via this plugin.

```bash
make run
```

The "Docker Pipeline" Job simply does the following:

1. Gets the Spring Pet Clinic demonstration application code from GitHub.
1. Builds the Pet Clinic application in a Docker container.
1. Builds a runnable Pet Clinic application Docker image.
1. Runs a Pet Clinic app container (from the Pet Clinic application Docker image) + a second maven3 container that runs automated tests against the Pet Clinic app container.
* The 2 containers are linked, allowing the test container to fire requests at the Pet Clinic app container.

The "Docker Pipeline" Job demonstrates how to use the `docker` DSL:

1. Use `docker.image` to define a DSL `Image` object (not to be confused with `build`) that can then be used to perform operations on a Docker image:
* use `Image.inside` to run a Docker container and execute commands in it. The build workspace is mounted as the working directory in the container.
* use `Image.run` to run a Docker container in detached mode, returning a DSL `Container` object that can be later used to stop the container (via `Container.stop`).
1. Use `docker.build` to build a Docker image from a `Dockerfile`, returning a DSL `Image` object that can then be used to perform operations on that image (as above).

The `docker` DSL supports some additional capabilities not shown in the "Docker Pipeline" Job:

1. Use the `docker.withRegistry` and `docker.withServer` to register endpoints for the Docker registry and host to be used when executing docker commands.
* `docker.withRegistry(<registryUrl>, <registryCredentialsId>)`
* `docker.withServer(<serverUri>, <serverCredentialsId>)`
1. Use the `Image.pull` to pull Docker image layers into the Docker host cache.
1. Use the `Image.push` to push a Docker image to the associated Docker Registry. See `docker.withRegistry` above.

The image needs to run Docker commands, so it assumes that your Docker daemon is listening to `/var/run/docker.sock` ([discussion](https://github.com/docker/docker/issues/1143)). This is not “Docker-in-Docker”; the container only runs the CLI and connects back to the host to start sister containers. The `run` target also makes reference to file paths on the Docker host, assuming they are where you are running that command, so this target *cannot work* on boot2docker. There may be some way to run this demo using boot2docker; if so, please contribute it.
39 changes: 39 additions & 0 deletions demo/gen-security-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

##
# 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.
##

set -e

rm -rfv $1
mkdir -p $1

pushd $1

docker run --entrypoint htpasswd registry:2.5.1 -Bbn pipelineuser 123123123 > docker-registry.htpasswd

# Create the CA Key and Certificate for signing Certs
openssl genrsa -des3 -passout pass:x -out ca.key 4096
openssl rsa -passin pass:x -in ca.key -out ca.key # remove password!
openssl req -new -x509 -days 365 -key ca.key -out ca.crt -subj "/C=US/ST=California/L=San Jose/O=Jenkins CI/OU=Pipeline Dept/CN=localhost"
20 changes: 20 additions & 0 deletions demo/repo/app/.springBeans
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[3.5.0.201404011509-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/resources/spring/datasource-config.xml</config>
<config>src/main/resources/spring/mvc-core-config.xml</config>
<config>src/main/resources/spring/mvc-view-config.xml</config>
<config>src/main/resources/spring/business-config.xml</config>
</configs>
<autoconfigs>
<config>src/main/resources/spring/tools-config.xml</config>
</autoconfigs>
<configSets>
</configSets>
</beansProjectDescription>
3 changes: 3 additions & 0 deletions demo/repo/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM tfennelly/tomcat7

ADD target/petclinic.war /tomcat7/webapps/petclinic.war
Loading