Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-48711] - Create a PCT Docker image, mostly works
  • Loading branch information
oleg-nenashev committed Dec 26, 2017
1 parent ae156ca commit 4109ff4
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,3 +14,4 @@ reports
work/
^jenkins/
.idea
out
53 changes: 53 additions & 0 deletions Dockerfile
@@ -0,0 +1,53 @@
# The MIT License
#
# Copyright (c) 2017 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 maven:3.5.2-jdk-8
LABEL Description="Base image for running Jenkins Plugin Compat Tester (PCT) against custom plugins and Jenkins cores" Vendor="Jenkins project"

# Local build
COPY plugins-compat-tester-cli/target/ /pct/src/plugins-compat-tester-cli/target/

#TODO: Uncomment once Jenkins Artifactory is recovered
# https://issues.jenkins-ci.org/browse/INFRA-1447
# Copy sources
#COPY plugins-compat-tester/ /pct/src/plugins-compat-tester/
#COPY plugins-compat-tester-cli/ /pct/src/plugins-compat-tester-cli/
#COPY plugins-compat-tester-gae/ /pct/src/plugins-compat-tester-gae/
#COPY plugins-compat-tester-gae-client/ /pct/src/plugins-compat-tester-gae-client/
#COPY plugins-compat-tester-model/ /pct/src/plugins-compat-tester-model/
#COPY *.xml /pct/src/
#COPY LICENSE.txt /pct/src/LICENSE.txt

#WORKDIR /opt/pct/src/
#RUN ls -l && mvn clean package

ENV JENKINS_WAR_PATH=/pct/jenkins.war
ENV PCT_OUTPUT_DIR=/pct/out
ENV PCT_TMP=/pct/tmp

COPY src/main/docker/run-pct.sh /usr/local/bin/run-pct

VOLUME /pct/plugin-src
VOLUME /pct/jenkins.war
VOLUME /pct/out
VOLUME /root/.m2
ENTRYPOINT ["run-pct"]
35 changes: 35 additions & 0 deletions README.md
Expand Up @@ -7,6 +7,41 @@ See https://wiki.jenkins-ci.org/display/JENKINS/Plugin+Compatibility+Tester for

## Running PCT

### Running PCT in Docker

It is recommended to run PCT in the prepared Docker image.
You can find it [here](hub.docker.com/r/jenkins/pct/).

#### Examples

This command will clone of a repository and run PCT against the latest Jenkins Core:

```shell
docker run --rm -v maven-repo:/root/.m2 -v $(pwd)/out:/pct/out -e ARTIFACT_ID=job-restrictions -e VERSION=job-restrictions-0.6 -i jenkins/pct
```

This command will run PCT against custom versions of Jenkins and the plugin specified by volumes:

```shell
docker run --rm -v maven-repo:/root/.m2 -v $(pwd)/out:/pct/out -v my/jenkins.war:/pct/jenkins.war:ro -v my/plugin:/pct/plugin-src:ro -e ARTIFACT_ID=job-restrictions -i jenkins/pct
```

#### Configuration

Environment variables:

* `ARTIFACT_ID` - ID of the artifact to be tested.
This is the only **mandatory** parameter.
* `VERSION` - tag/commit/branch to be checked out and tested. `master` by default
* `CHECKOUT_SRC` - Custom Git clone source (e.g. `https://github.com/oleg-nenashev/job-restrictions-plugin.git`). `https://github.com/jenkinsci/${ARTIFACT_ID}-plugin.git` by default

Volumes:

* `/pct/plugin-src` - Plugin sources to be used for the PCT run. Sources will be checked out if not specified
* `/pct/jenkins.war` - Jenkins WAR file to be used for the PCT run
* `/pct/out` - Output directory for PCT. All reports will be stored there
* `/root/.m2` - Maven repository. It can be used to pass settings.xml or to cache artifacts

### Running PCT manually

PCT offers the CLI interface which can be used to run PCT locally.
Expand Down
77 changes: 77 additions & 0 deletions src/main/docker/run-pct.sh
@@ -0,0 +1,77 @@
#!/bin/bash
set -e
set -x

if [ $# -eq 1 ]; then
# if `docker run` only has one argument, we assume that the user is running an alternate command
# like `bash` to inspect the image. All options passed to the executable shoud have at least 2 arguments.
echo "Only one argument is specified, running a custom command"
exec "$@"
exit 0
fi

###
# Process arguments
###
if [ -n "${ARTIFACT_ID}" ]; then
echo "Running PCT for plugin ${ARTIFACT_ID}"
else
echo "ERROR: Artifact ID is not specified. Use environment variable, e.g. \"-e ARTIFACT_ID=credentials\""
exit -1
fi

if [ -n "${CHECKOUT_SRC}" ] ; then
echo "Using custom checkout source: ${CHECKOUT_SRC}"
else
CHECKOUT_SRC="https://github.com/jenkinsci/${ARTIFACT_ID}-plugin.git"
fi

if [ -n "${VERSION}"] ; then
VERSION="master"
fi

if [ -f "${JENKINS_WAR_PATH}" ]; then
echo "Using custom Jenkins WAR from ${JENKINS_WAR_PATH}"
mkdir -p "${PCT_TMP}"
# WAR is accessed many times in the PCT runs, let's keep it local insead of pulling it from a volume
cp "${JENKINS_WAR_PATH}" "${PCT_TMP}/jenkins.war"
WAR_PATH_OPT="-war ${PCT_TMP}/jenkins.war "
else
WAR_PATH_OPT=""
fi

###
# Checkout sources
###
mkdir -p "${PCT_TMP}/localCheckoutDir"
cd "${PCT_TMP}/localCheckoutDir"
if [ -e "/pct/plugin-src/pom.xml" ] ; then
echo "Located custom plugin sources"
mkdir "${ARTIFACT_ID}"
cp -R /pct/plugin-src/* "${ARTIFACT_ID}/"
# Due to whatever reason PCT blows up if you have work in the repo
cd "${ARTIFACT_ID}" && mvn clean && rm -rf work
else
echo "Checking out from ${CHECKOUT_SRC}:${VERSION}"
git clone "${CHECKOUT_SRC}"
mv $(ls .) ${ARTIFACT_ID}
cd ${ARTIFACT_ID} && git checkout "${VERSION}"
fi

###
# Run PCT
###
cd /pct
PCT_CLI=$(ls src/plugins-compat-tester-cli/target/plugins-compat-tester-cli-*.jar )
if [ -e "${PCT_CLI}" ] ; then
echo "Using PCT CLI ${PCT_CLI}"
else
echo "Failed to locate PCT CLI"
exit -1
fi

mkdir -p "${PCT_TMP}/work"
mkdir -p "${PCT_OUTPUT_DIR}"

# The image always uses external Maven due to https://issues.jenkins-ci.org/browse/JENKINS-48710
exec java -jar ${PCT_CLI} -reportFile ${PCT_OUTPUT_DIR}/pct-report.xml -workDirectory "${PCT_TMP}/work" ${WAR_PATH_OPT} -skipTestCache true -localCheckoutDir "${PCT_TMP}/localCheckoutDir/${ARTIFACT_ID}" -includePlugins "${ARTIFACT_ID}" -mvn "/usr/bin/mvn" "$@"

0 comments on commit 4109ff4

Please sign in to comment.