Skip to content

Commit

Permalink
Add bootstrap wrapper script for Docker
Browse files Browse the repository at this point in the history
This allows users to pass "cli" or "run" as Docker CMD to easily
switch modes without having to set environment variables. Also provides
the DEBUG environment variable that used to be provided by the
launcher script (which is no longer used as of this).

Also removes the FORCE_JENKINS_CLI environment variables as it's no
longer necessary.

as per #207 (comment)
  • Loading branch information
literalplus committed Oct 26, 2019
1 parent 6aeca51 commit f2c00fd
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 32 deletions.
6 changes: 5 additions & 1 deletion DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ Optionally, if you need special Jenkins configuration, you can mount JCasC YAML
for available options and the [JCasC demo](demo/casc/README.md) for an example.

To get an interactive Jenkins CLI shell in the container, pass
`-i -e FORCE_JENKINS_CLI=true` to `docker run` as extra parameters.
`-i` to `docker run` and append `cli` after the image name like this:

```bash
docker run -i --rm jenkinsfile-runner:my-production-jenkins cli
```

## Debug
In case you want to debug Jenkinsfile Runner, you need to use the "Vanilla" Docker image built following the steps mentioned in the section above.
Expand Down
33 changes: 18 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Define maven version for other stages
FROM maven:3.5.4 as maven

ARG JENKINS_REF=/usr/share/jenkins/ref
ARG JENKINS_HOME=/app/jenkins

FROM maven as jenkinsfilerunner-mvncache
ADD pom.xml /src/pom.xml
ADD app/pom.xml /src/app/pom.xml
Expand All @@ -20,25 +23,25 @@ ENV MAVEN_OPTS=-Dmaven.repo.local=/mavenrepo
COPY --from=jenkinsfilerunner-mvncache /mavenrepo /mavenrepo
ADD . /jenkinsfile-runner
RUN cd /jenkinsfile-runner && mvn package
RUN mkdir /app && unzip /jenkinsfile-runner/vanilla-package/target/war/jenkins.war -d /app/jenkins && \
rm -rf /app/jenkins/scripts /app/jenkins/jsbundles /app/jenkins/css /app/jenkins/images /app/jenkins/help /app/jenkins/WEB-INF/detached-plugins /app/jenkins/winstone.jar /app/jenkins/WEB-INF/jenkins-cli.jar /app/jenkins/WEB-INF/lib/jna-4.5.2.jar
RUN mkdir /app && \
unzip /jenkinsfile-runner/vanilla-package/target/war/jenkins.war -d ${JENKINS_HOME} && \
rm -rf ${JENKINS_HOME}/scripts ${JENKINS_HOME}/jsbundles ${JENKINS_HOME}/css ${JENKINS_HOME}/images ${JENKINS_HOME}/help ${JENKINS_HOME}/WEB-INF/detached-plugins ${JENKINS_HOME}/winstone.jar ${JENKINS_HOME}/WEB-INF/jenkins-cli.jar ${JENKINS_HOME}/WEB-INF/lib/jna-4.5.2.jar

FROM openjdk:8-jdk
ENV JENKINS_UC https://updates.jenkins.io
ENV CASC_JENKINS_CONFIG /usr/share/jenkins/ref/casc

ENV JENKINS_REF ${JENKINS_REF}
ENV JENKINS_HOME ${JENKINS_HOME}

USER root
RUN mkdir -p /app /usr/share/jenkins/ref/plugins /usr/share/jenkins/ref/casc
RUN echo "jenkins: {}" >/usr/share/jenkins/ref/casc/jenkins.yaml
COPY --from=jenkinsfilerunner-build /app/jenkins /app/jenkins
RUN mkdir -p /app ${JENKINS_REF}/plugins ${JENKINS_REF}/casc
COPY jfr-docker.sh /usr/local/bin
COPY --from=jenkinsfilerunner-build ${JENKINS_HOME} ${JENKINS_HOME}
COPY --from=jenkinsfilerunner-build /jenkinsfile-runner/app/target/appassembler /app
COPY --from=jenkinsfilerunner-build /jenkinsfile-runner/vanilla-package/target/plugins /usr/share/jenkins/ref/plugins
COPY jenkinsfile-runner-launcher /app/bin
COPY --from=jenkinsfilerunner-build /jenkinsfile-runner/vanilla-package/target/plugins ${JENKINS_REF}/plugins

VOLUME /build
VOLUME /usr/share/jenkins/ref/casc
VOLUME ${JENKINS_REF}/casc

ENTRYPOINT ["/usr/local/bin/jfr-docker.sh"]

ENTRYPOINT ["/app/bin/jenkinsfile-runner-launcher", \
"-w", "/app/jenkins",\
"-p", "/usr/share/jenkins/ref/plugins",\
"-f", "/workspace", \
"--runWorkspace", "/build"]
CMD ["run"]
28 changes: 16 additions & 12 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
# To avoid downloading everything from the internet and using developer's cache

FROM openjdk:8-jdk
ENV JENKINS_UC https://updates.jenkins.io
ENV CASC_JENKINS_CONFIG /usr/share/jenkins/ref/casc

ARG JENKINS_REF=/usr/share/jenkins/ref
ARG JENKINS_HOME=/app/jenkins

ENV JENKINS_REF ${JENKINS_REF}
ENV JENKINS_HOME ${JENKINS_HOME}

USER root
RUN mkdir -p /app /usr/share/jenkins/ref/plugins /usr/share/jenkins/ref/casc
RUN echo "jenkins: {}" >/usr/share/jenkins/ref/casc/jenkins.yaml
RUN mkdir -p /app ${JENKINS_REF}/plugins ${JENKINS_REF}/casc

COPY jfr-docker.sh /usr/local/bin
COPY app/target/appassembler /app
COPY vanilla-package/target/war/jenkins.war /usr/share/jenkins/jenkins.war
RUN unzip /usr/share/jenkins/jenkins.war -d /app/jenkins && \
rm -rf /app/jenkins/scripts /app/jenkins/jsbundles /app/jenkins/css /app/jenkins/images /app/jenkins/help /app/jenkins/WEB-INF/detached-plugins /app/jenkins/winstone.jar /app/jenkins/WEB-INF/jenkins-cli.jar /app/jenkins/WEB-INF/lib/jna-4.5.2.jar
COPY vanilla-package/target/plugins /usr/share/jenkins/ref/plugins
RUN unzip /usr/share/jenkins/jenkins.war -d ${JENKINS_HOME} && \
rm -rf ${JENKINS_HOME}/scripts ${JENKINS_HOME}/jsbundles ${JENKINS_HOME}/css ${JENKINS_HOME}/images ${JENKINS_HOME}/help ${JENKINS_HOME}/WEB-INF/detached-plugins ${JENKINS_HOME}/winstone.jar ${JENKINS_HOME}/WEB-INF/jenkins-cli.jar ${JENKINS_HOME}/WEB-INF/lib/jna-4.5.2.jar
COPY vanilla-package/target/plugins ${JENKINS_REF}/plugins

VOLUME ${JENKINS_REF}/casc

VOLUME /usr/share/jenkins/ref/casc
ENTRYPOINT ["/usr/local/bin/jfr-docker.sh"]

ENTRYPOINT ["/app/bin/jenkinsfile-runner", \
"-w", "/app/jenkins",\
"-p", "/usr/share/jenkins/ref/plugins",\
"-f", "/workspace"]
CMD ["run"]
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ private void postConstruct(CmdLineParser parser) throws IOException {
System.exit(0);
}

if (System.getenv("FORCE_JENKINS_CLI") != null) {
this.cliOnly = true;
}

if (this.version != null && !isVersionSupported()) {
System.err.printf("Jenkins version [%s] not suported by this jenkinsfile-runner version (requires %s). \n",
this.version,
Expand Down
54 changes: 54 additions & 0 deletions jfr-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

if [[ -z "${JENKINS_HOME}" ]] || [[ -z "${JENKINS_REF}" ]]; then
echo "$0: Environment variables JENKINS_HOME and JENKINS_REF need to be set!" >&2
exit 1
elif [[ ! -d "${JENKINS_HOME}" ]]; then
echo "$0: JENKINS_HOME at ${JENKINS_HOME} does not exist." >&2
exit 1
elif [[ ! -d "${JENKINS_REF}" ]]; then
echo "$0: JENKINS_REF at ${JENKINS_REF} does not exist." >&2
exit 1
fi

export JENKINS_WORKSPACE="${JENKINS_WORKSPACE:-/workspace}"
export JENKINS_BUILD_DIR="${JENKINS_BUILD_DIR:-/build}"
export CASC_JENKINS_CONFIG="${CASC_JENKINS_CONFIG:-${JENKINS_REF}/casc}"
export JENKINS_PLUGIN_DIR="${JENKINS_PLUGIN_DIR:-${JENKINS_REF}/plugins}"

export JENKINS_UC="${JENKINS_UC:-https://updates.jenkins.io}"

LAUNCHER_PARAMS=("-w" "${JENKINS_HOME}" "-p" "${JENKINS_REF}/plugins")

if [[ -n "${DEBUG}" ]]; then
export JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 ${JAVA_OPTS:-}"
echo "$0: Make sure to expose the port by providing -p 5005:5005 to docker run"
fi

if [[ "$#" -gt 0 ]]; then
case "$1" in
run)
LAUNCHER_PARAMS+=("-f" "${JENKINS_WORKSPACE}" "--runWorkspace" "${JENKINS_BUILD_DIR}")
;;
cli)
LAUNCHER_PARAMS+=("--cli")
;;
*)
echo "$0: Unknown action $1. Try $0 [run|cli]"
echo " run: Launch a Jenkinsfile build."
echo " cli: Attach an interactive Jenkins shell."
exit 1
;;
esac

if [[ "$#" -gt 1 ]]; then
LAUNCHER_PARAMS+=("${@:1}")
fi
fi

if [[ -x "/app/bin/jenkinsfile-runner" ]]; then
/app/bin/jenkinsfile-runner "${LAUNCHER_PARAMS[@]}"
else
echo "$0: /app/bin/jenkinsfile-runner needs to be an executable file." >&2
exit 1
fi

0 comments on commit f2c00fd

Please sign in to comment.