From f05ece5039a512aaec16c242336028509a6cf9c4 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Mon, 5 Aug 2019 15:19:50 +0200 Subject: [PATCH 1/2] Use Jenkins base image to avoid workaround for Docker packaging limitations --- Dockerfile | 31 ++------ jenkins-support | 189 ------------------------------------------------ 2 files changed, 8 insertions(+), 212 deletions(-) delete mode 100644 jenkins-support diff --git a/Dockerfile b/Dockerfile index f6fedbe..64c7b6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,16 @@ -FROM jenkins/jenkins:2.176.2 as install_scripts_source +FROM cloudbees/cloudbees-jenkins-distribution:2.176.2.3 as war_source -FROM cloudbees/cloudbees-jenkins-distribution:2.176.2.3 -COPY --from=install_scripts_source /usr/local/bin/jenkins-support /usr/local/bin/jenkins-support -COPY --from=install_scripts_source /usr/local/bin/install-plugins.sh /usr/local/bin/install-plugins.sh - -ENV JENKINS_UC http://jenkins-updates.cloudbees.com -ENV JENKINS_INCREMENTALS_REPO_MIRROR https://repo.jenkins-ci.org/incrementals - -# Workaround https://github.com/jenkinsci/docker/issues/857 -USER root -RUN mkdir -p /usr/share/jenkins/ && ln -s /usr/share/cloudbees-jenkins-distribution/cloudbees-jenkins-distribution.war /usr/share/jenkins/jenkins.war -USER cloudbees-jenkins-distribution +FROM jenkins/jenkins:2.176.2 +COPY --from=war_source /usr/share/cloudbees-jenkins-distribution/cloudbees-jenkins-distribution.war /usr/share/jenkins/jenkins.war # Startup all plugins included into the CloudBees Jenkins Distribution bundle ENV JAVA_OPTS "-Dcom.cloudbees.jenkins.cjp.installmanager.CJPPluginManager.allRequired=true" -# Install extra plugins -# REF_ROOT is consumed by jenkins-support in the https://github.com/jenkinsci/docker/issues/861 workaround -ENV REF_ROOT=/usr/share/cloudbees-jenkins-distribution/ref -ENV REF=${REF_ROOT}/plugins -COPY plugins.txt /usr/share/cloudbees-jenkins-distribution/ref/plugins.txt -RUN bash /usr/local/bin/install-plugins.sh < /usr/share/cloudbees-jenkins-distribution/ref/plugins.txt +# Install additional plugins including JCasC +ENV JENKINS_UC http://jenkins-updates.cloudbees.com +COPY plugins.txt /usr/share/jenkins/ref/plugins.txt +RUN bash /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt -# Apply JCasC +# Apply JCasC configuration COPY jenkins.yaml /cfg/jenkins.yaml ENV CASC_JENKINS_CONFIG /cfg/jenkins.yaml - -# Temporary override for jenkins-support to support custom ref-roots there -# TODO: remove once https://github.com/jenkinsci/docker/issues/861 is fixed -COPY jenkins-support /usr/local/bin/jenkins-support diff --git a/jenkins-support b/jenkins-support deleted file mode 100644 index 21c8404..0000000 --- a/jenkins-support +++ /dev/null @@ -1,189 +0,0 @@ -#!/bin/bash -eu -# This finle is a temporary workaround for https://github.com/jenkinsci/docker/issues/861 -# TODO: Remove the file once the issue is fixed - -set +x - -# compare if version1 < version2 -versionLT() { - local v1; v1=$(echo "$1" | cut -d '-' -f 1 ) - local q1; q1=$(echo "$1" | cut -s -d '-' -f 2- ) - local v2; v2=$(echo "$2" | cut -d '-' -f 1 ) - local q2; q2=$(echo "$2" | cut -s -d '-' -f 2- ) - if [ "$v1" = "$v2" ]; then - if [ "$q1" = "$q2" ]; then - return 1 - else - if [ -z "$q1" ]; then - return 1 - else - if [ -z "$q2" ]; then - return 0 - else - [ "$q1" = "$(echo -e "$q1\n$q2" | sort -V | head -n1)" ] - fi - fi - fi - else - [ "$v1" = "$(echo -e "$v1\n$v2" | sort -V | head -n1)" ] - fi -} - -# returns a plugin version from a plugin archive -get_plugin_version() { - local archive; archive=$1 - local version; version=$(unzip -p "$archive" META-INF/MANIFEST.MF | grep "^Plugin-Version: " | sed -e 's#^Plugin-Version: ##') - version=${version%%[[:space:]]} - echo "$version" -} - -# Copy files from $REF_ROOT (default: /usr/share/jenkins/ref) into $JENKINS_HOME -# So the initial JENKINS-HOME is set with expected content. -# Don't override, as this is just a reference setup, and use from UI -# can then change this, upgrade plugins, etc. -copy_reference_file() { - f="${1%/}" - refdir=${REF_ROOT:-/usr/share/jenkins/ref} - b="${f%.override}" - rel="${b#"$refdir"}" - echo "refdir=$refdir b=$b rel=$rel" - version_marker="${rel}.version_from_image" - dir=$(dirname "${b}") - reldir=${dir#"$refdir"} - - local action; - local reason; - local container_version; - local image_version; - local marker_version; - local log; log=false - if [[ ${rel} == plugins/*.jpi ]]; then - container_version=$(get_plugin_version "$JENKINS_HOME/${rel}") - image_version=$(get_plugin_version "${f}") - if [[ -e $JENKINS_HOME/${version_marker} ]]; then - marker_version=$(cat "$JENKINS_HOME/${version_marker}") - if versionLT "$marker_version" "$container_version"; then - if ( versionLT "$container_version" "$image_version" && [[ -n $PLUGINS_FORCE_UPGRADE ]]); then - action="UPGRADED" - reason="Manually upgraded version ($container_version) is older than image version $image_version" - log=true - else - action="SKIPPED" - reason="Installed version ($container_version) has been manually upgraded from initial version ($marker_version)" - log=true - fi - else - if [[ "$image_version" == "$container_version" ]]; then - action="SKIPPED" - reason="Version from image is the same as the installed version $image_version" - else - if versionLT "$image_version" "$container_version"; then - action="SKIPPED" - log=true - reason="Image version ($image_version) is older than installed version ($container_version)" - else - action="UPGRADED" - log=true - reason="Image version ($image_version) is newer than installed version ($container_version)" - fi - fi - fi - else - if [[ -n "$TRY_UPGRADE_IF_NO_MARKER" ]]; then - if [[ "$image_version" == "$container_version" ]]; then - action="SKIPPED" - reason="Version from image is the same as the installed version $image_version (no marker found)" - # Add marker for next time - echo "$image_version" > "$JENKINS_HOME/${version_marker}" - else - if versionLT "$image_version" "$container_version"; then - action="SKIPPED" - log=true - reason="Image version ($image_version) is older than installed version ($container_version) (no marker found)" - else - action="UPGRADED" - log=true - reason="Image version ($image_version) is newer than installed version ($container_version) (no marker found)" - fi - fi - fi - fi - if [[ ! -e $JENKINS_HOME/${rel} || "$action" == "UPGRADED" || $f = *.override ]]; then - action=${action:-"INSTALLED"} - log=true - mkdir -p "$JENKINS_HOME/${reldir}" - cp -pr "${f}" "$JENKINS_HOME/${rel}"; - # pin plugins on initial copy - touch "$JENKINS_HOME/${rel}.pinned" - echo "$image_version" > "$JENKINS_HOME/${version_marker}" - reason=${reason:-$image_version} - else - action=${action:-"SKIPPED"} - fi - else - if [[ ! -e $JENKINS_HOME/${rel} || $f = *.override ]] - then - action="INSTALLED" - log=true - mkdir -p "$JENKINS_HOME/${reldir}" - cp -pr "$(realpath "${f}")" "$JENKINS_HOME/${rel}"; - else - action="SKIPPED" - fi - fi - if [[ -n "$VERBOSE" || "$log" == "true" ]]; then - if [ -z "$reason" ]; then - echo "$action $rel" >> "$COPY_REFERENCE_FILE_LOG" - else - echo "$action $rel : $reason" >> "$COPY_REFERENCE_FILE_LOG" - fi - fi -} - -# Retries a command a configurable number of times with backoff. -# -# The retry count is given by ATTEMPTS (default 60), the initial backoff -# timeout is given by TIMEOUT in seconds (default 1.) -# -function retry_command() { - local max_attempts=${ATTEMPTS-3} - local timeout=${TIMEOUT-1} - local success_timeout=${SUCCESS_TIMEOUT-1} - local max_success_attempt=${SUCCESS_ATTEMPTS-1} - local attempt=0 - local success_attempt=0 - local exitCode=0 - - while (( attempt < max_attempts )) - do - set +e - "$@" - exitCode=$? - set -e - - if [[ $exitCode == 0 ]] - then - success_attempt=$(( success_attempt + 1 )) - if (( success_attempt >= max_success_attempt)) - then - break - else - sleep "$success_timeout" - continue - fi - fi - - echo "$(date -u '+%T') Failure ($exitCode) Retrying in $timeout seconds..." 1>&2 - sleep "$timeout" - success_attempt=0 - attempt=$(( attempt + 1 )) - timeout=$(( timeout )) - done - - if [[ $exitCode != 0 ]] - then - echo "$(date -u '+%T') Failed in the last attempt ($*)" 1>&2 - fi - - return $exitCode -} From 5a9dadaaa6d5da9e010bc0cabc49be8fce4a5f87 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Tue, 6 Aug 2019 09:42:43 +0200 Subject: [PATCH 2/2] Add comment about the COPY Step --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 64c7b6c..b16705a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM cloudbees/cloudbees-jenkins-distribution:2.176.2.3 as war_source FROM jenkins/jenkins:2.176.2 + +# Replace jenkins.war by CloudBees Jenkins Distribution WAR which includes plugins from CloudBees Assurance Program and other features COPY --from=war_source /usr/share/cloudbees-jenkins-distribution/cloudbees-jenkins-distribution.war /usr/share/jenkins/jenkins.war # Startup all plugins included into the CloudBees Jenkins Distribution bundle