Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker bootstrap script #213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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: 19 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,34 @@ ENV MAVEN_OPTS=-Dmaven.repo.local=/mavenrepo
RUN mvn compile dependency:resolve dependency:resolve-plugins

FROM maven as jenkinsfilerunner-build

ARG JENKINS_REF=/usr/share/jenkins/ref
ARG JENKINS_HOME=/app/jenkins
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

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
COPY --from=jenkinsfilerunner-build /app/jenkins /app/jenkins
RUN mkdir -p /app ${JENKINS_REF}/plugins ${JENKINS_REF}/casc
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 --from=jenkinsfilerunner-build /jenkinsfile-runner/vanilla-package/target/plugins ${JENKINS_REF}/plugins
COPY jenkinsfile-runner-launcher /app/bin

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

ENTRYPOINT ["/app/bin/jenkinsfile-runner-launcher"]

ENTRYPOINT ["/app/bin/jenkinsfile-runner-launcher", \
"-w", "/app/jenkins",\
"-p", "/usr/share/jenkins/ref/plugins",\
"-f", "/workspace", \
"--runWorkspace", "/build"]
CMD ["run"]
27 changes: 15 additions & 12 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +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 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
COPY jenkinsfile-runner-launcher /app/bin

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

ENTRYPOINT ["/app/bin/jenkinsfile-runner-launcher"]

ENTRYPOINT ["/app/bin/jenkinsfile-runner-launcher", \
"-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
55 changes: 51 additions & 4 deletions jenkinsfile-runner-launcher
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
#!/bin/sh
#!/usr/bin/env bash

if [ -n "$DEBUG" ] ; then
export JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 $JAVA_OPTS"
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

. /app/bin/jenkinsfile-runner
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 "Make sure to expose the debug 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