Skip to content

Download war from mirrors unless we are publishing a release #2059

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions HACKING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ Create a new dedicated target repository in your Docker Hub account, and use it

[source,bash]
--
export DOCKERHUB_ORGANISATION=batmat
export DOCKERHUB_REPO=test-jenkins
export DOCKERHUB_ORGANISATION=markewaite
export DOCKERHUB_REPO=experiments
# The log below will help confirm this override was taken in account:
./publish.sh
.ci/publish.sh
Docker repository in Use:
* JENKINS_REPO: batmat/test-jenkins
* JENKINS_REPO: markewaite/experiments
...
--
11 changes: 5 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ H 6,21 * * 3''')])

properties(listOfProperties)

// Default environment variable set to allow images publication
def envVars = ['PUBLISH=true']
// Only publish images from trusted.ci.jenkins.io
def envVars = ['PUBLISH=' + env.JENKINS_URL.startsWith('https://trusted.ci.jenkins.io')]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should not need this detection (see my comment about default value)


// Set to true in a replay to simulate a LTS build on ci.jenkins.io
// It will set the environment variables needed for a LTS
Expand All @@ -21,10 +21,9 @@ def SIMULATE_LTS_BUILD = false

if (SIMULATE_LTS_BUILD) {
envVars = [
'PUBLISH=false',
'TAG_NAME=2.462.3',
'JENKINS_VERSION=2.462.3',
'JENKINS_SHA=3e53b52a816405e3b10ad07f1c48cd0cb5cb3f893207ef7f9de28415806b93c1'
'TAG_NAME=2.516.1',
'JENKINS_VERSION=2.516.1',
'JENKINS_SHA=c308a27e81f4ce3aa6787e96caf771534f7f206fefbb83969d77b15fc7f2700a'
]
}

Expand Down
6 changes: 3 additions & 3 deletions alpine/hotspot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ RUN mkdir -p ${REF}/init.groovy.d

# jenkins version being bundled in this docker image
ARG JENKINS_VERSION
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.504}
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.516.1}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.516.1}
ENV JENKINS_VERSION=${JENKINS_VERSION}

In order to avoid spreading the same value on multiple locations, which makes it tedious to maintain, WDYT about avoiding passing any default version?

We keep the ENV to ensure the resolved value is stored in the image (ARG is only available during build) but no default value as we rely on docker bake and docker-compose


# jenkins.war checksum, download will be validated using it
ARG JENKINS_SHA=efc91d6be8d79dd078e7f930fc4a5f135602d0822a5efe9091808fdd74607d32
ARG JENKINS_SHA=c308a27e81f4ce3aa6787e96caf771534f7f206fefbb83969d77b15fc7f2700a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ARG JENKINS_SHA=c308a27e81f4ce3aa6787e96caf771534f7f206fefbb83969d77b15fc7f2700a
ARG JENKINS_SHA

WDYT we apply the same pattern as other ARGs and we rely only on docker bake/compose to avoid spreading the values on many locations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That changes the development experience by requiring that every invocation of make must provide a value for JENKINS_SHA and JENKINS_VERSION. We might be able to overcome that by allowing the Makefile to request the SHA based on the JENKINS_VERSION using the same technique that is in the .ci/publish.sh script, but that seems like it will increase the complexity and remove some of the simplification that you would like to see.


# Can be used to customize where jenkins.war get downloaded from
ARG JENKINS_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war
ARG JENKINS_URL

# could use ADD but this one does not check Last-Modified header neither does it allow to control checksum
# see https://github.com/docker/docker/issues/8331
Expand Down
2 changes: 2 additions & 0 deletions build-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
JAVA_HOME: "C:/openjdk-17"
JAVA_VERSION: 17.0.16_8
JENKINS_SHA: ${JENKINS_SHA}
JENKINS_URL: ${JENKINS_URL}
JENKINS_VERSION: ${JENKINS_VERSION}
TOOLS_WINDOWS_VERSION: ${TOOLS_WINDOWS_VERSION}
WINDOWS_VERSION: ${WINDOWS_VERSION}
Expand All @@ -24,6 +25,7 @@ services:
JAVA_HOME: "C:/openjdk-21"
JAVA_VERSION: 21.0.8_9
JENKINS_SHA: ${JENKINS_SHA}
JENKINS_URL: ${JENKINS_URL}
JENKINS_VERSION: ${JENKINS_VERSION}
TOOLS_WINDOWS_VERSION: ${TOOLS_WINDOWS_VERSION}
WINDOWS_VERSION: ${WINDOWS_VERSION}
Expand Down
6 changes: 3 additions & 3 deletions debian/bookworm-slim/hotspot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ RUN mkdir -p ${REF}/init.groovy.d

# jenkins version being bundled in this docker image
ARG JENKINS_VERSION
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.504}
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.516.1}

# jenkins.war checksum, download will be validated using it
ARG JENKINS_SHA=efc91d6be8d79dd078e7f930fc4a5f135602d0822a5efe9091808fdd74607d32
ARG JENKINS_SHA=c308a27e81f4ce3aa6787e96caf771534f7f206fefbb83969d77b15fc7f2700a

# Can be used to customize where jenkins.war get downloaded from
ARG JENKINS_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war
ARG JENKINS_URL

# could use ADD but this one does not check Last-Modified header neither does it allow to control checksum
# see https://github.com/docker/docker/issues/8331
Expand Down
6 changes: 3 additions & 3 deletions debian/bookworm/hotspot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ RUN mkdir -p ${REF}/init.groovy.d

# jenkins version being bundled in this docker image
ARG JENKINS_VERSION
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.504}
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.516.1}

# jenkins.war checksum, download will be validated using it
ARG JENKINS_SHA=efc91d6be8d79dd078e7f930fc4a5f135602d0822a5efe9091808fdd74607d32
ARG JENKINS_SHA=c308a27e81f4ce3aa6787e96caf771534f7f206fefbb83969d77b15fc7f2700a

# Can be used to customize where jenkins.war get downloaded from
ARG JENKINS_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war
ARG JENKINS_URL

# could use ADD but this one does not check Last-Modified header neither does it allow to control checksum
# see https://github.com/docker/docker/issues/8331
Expand Down
34 changes: 32 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ group "linux-ppc64le" {
# ---- variables ----

variable "JENKINS_VERSION" {
default = "2.504"
default = "2.516.1"
}

variable "JENKINS_SHA" {
default = "efc91d6be8d79dd078e7f930fc4a5f135602d0822a5efe9091808fdd74607d32"
default = "c308a27e81f4ce3aa6787e96caf771534f7f206fefbb83969d77b15fc7f2700a"
}

variable "REGISTRY" {
Expand Down Expand Up @@ -94,6 +94,12 @@ variable "BOOKWORM_TAG" {
default = "20250721"
}

variable "JENKINS_URL" { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
variable "JENKINS_URL" { }
variable "JENKINS_URL" {
default = "https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war"
}

WDYT if we define the "most common" value here (e.g. the current default which will be kept) and we only define a custom URL on the ci.jenkins.io pipeline? The goal would be to avoid the tedious logic around our "war" / "war-stable" detection. Your code works marvelously but it is still some branching code to maintain inside a declarative (docker bake) system

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that as one of my first iterations and was unable to persuade the bake file to expand the value of JENKINS_VERSION at the correct time. I abandoned the idea because no other variable in the file uses other variables to expand them.

If there is a way to do that, I'm open to it. I couldn't make it work with my efforts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to take a shot at it. Is this PR urgent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to take a shot at it. Is this PR urgent?

Not at all. I'd love to have you look at it when you're back from vacation.


variable "PUBLISH" {
default = "false"
}

# ---- user-defined functions ----

# return a tag prefixed by the Jenkins version
Expand All @@ -120,6 +126,22 @@ function "tag_lts" {
result = equal(LATEST_LTS, "true") ? tag(prepend_jenkins_version, tag) : ""
}

# return release line based on Jenkins version
function "release_line" {
# If there is more than one sequence of digits with a trailing literal '.', this is LTS
# 2.523 has only one sequence of digits with a trailing literal '.'
# 2.516.1 has two sequences of digits with a trailing literal '.'
# https://developer.hashicorp.com/terraform/language/functions/regexall describes the technique
params = []
result = length(regexall("[0-9]+[.]", JENKINS_VERSION)) < 2 ? "war" : "war-stable"
}

# return Jenkins URL based on Jenkins version and release line
function "jenkins_url" {
params = []
result = equal("true",PUBLISH) ? "https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war" : "https://get.jenkins.io/${release_line()}/${JENKINS_VERSION}/jenkins.war"
}

# ---- targets ----

target "alpine_jdk17" {
Expand All @@ -132,6 +154,7 @@ target "alpine_jdk17" {
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
ALPINE_TAG = ALPINE_FULL_TAG
JAVA_VERSION = JAVA17_VERSION
JENKINS_URL = jenkins_url()
}
tags = [
tag(true, "alpine-jdk17"),
Expand All @@ -152,6 +175,7 @@ target "alpine_jdk21" {
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
ALPINE_TAG = ALPINE_FULL_TAG
JAVA_VERSION = JAVA21_VERSION
JENKINS_URL = jenkins_url()
}
tags = [
tag(true, "alpine"),
Expand All @@ -176,6 +200,7 @@ target "debian_jdk17" {
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
BOOKWORM_TAG = BOOKWORM_TAG
JAVA_VERSION = JAVA17_VERSION
JENKINS_URL = jenkins_url()
}
tags = [
tag(true, "jdk17"),
Expand All @@ -197,6 +222,7 @@ target "debian_jdk21" {
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
BOOKWORM_TAG = BOOKWORM_TAG
JAVA_VERSION = JAVA21_VERSION
JENKINS_URL = jenkins_url()
}
tags = [
tag(true, ""),
Expand All @@ -222,6 +248,7 @@ target "debian_slim_jdk17" {
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
BOOKWORM_TAG = BOOKWORM_TAG
JAVA_VERSION = JAVA17_VERSION
JENKINS_URL = jenkins_url()
}
tags = [
tag(true, "slim-jdk17"),
Expand All @@ -241,6 +268,7 @@ target "debian_slim_jdk21" {
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
BOOKWORM_TAG = BOOKWORM_TAG
JAVA_VERSION = JAVA21_VERSION
JENKINS_URL = jenkins_url()
}
tags = [
tag(true, "slim"),
Expand All @@ -263,6 +291,7 @@ target "rhel_ubi9_jdk17" {
COMMIT_SHA = COMMIT_SHA
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
JAVA_VERSION = JAVA17_VERSION
JENKINS_URL = jenkins_url()
}
tags = [
tag(true, "rhel-ubi9-jdk17"),
Expand All @@ -282,6 +311,7 @@ target "rhel_ubi9_jdk21" {
COMMIT_SHA = COMMIT_SHA
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
JAVA_VERSION = JAVA21_VERSION
JENKINS_URL = jenkins_url()
}
tags = [
tag(true, "rhel-ubi9-jdk21"),
Expand Down
Binary file added jenkins.war
Binary file not shown.
20 changes: 18 additions & 2 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Param(
[Parameter(Position=1)]
[String] $Target = 'build',
[String] $JenkinsVersion = '2.504',
[String] $JenkinsVersion = '2.516.1',
[switch] $DryRun = $false
)

Expand Down Expand Up @@ -57,8 +57,24 @@ $env:JENKINS_SHA = $webClient.DownloadString($jenkinsShaURL).ToUpper()

$env:COMMIT_SHA=$(git rev-parse HEAD)

# Set JENKINS_URL build argument and JENKINS_URL environment variable
$JenkinsURL = ''
if($env:PUBLISH -eq $true -or $DryRun -eq $true) {
$JenkinsURL = 'https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/' + $JenkinsVersion + '/jenkins-war-' + $JenkinsVersion + '.war'
} else {
# Not publishing - use mirrors
$ReleaseLine = 'war'
if([regex]::Matches($JenkinsVersion, "[0-9]+[.]").count -gt 1) {
# Building the LTS version
$ReleaseLine = 'war-stable'
}
$JenkinsURL = 'https://get.jenkins.io/' + $ReleaseLine + '/' + $JenkinsVersion + '/jenkins.war'
}
$JenkinsURLArg = '--build-arg JENKINS_URL=' + $JenkinsURL
$env:JENKINS_URL = "$JenkinsURL"

$baseDockerCmd = 'docker-compose --file=build-windows.yaml'
$baseDockerBuildCmd = '{0} build --parallel --pull' -f $baseDockerCmd
$baseDockerBuildCmd = '{0} build --parallel --pull {1}' -f $baseDockerCmd, $JenkinsURLArg

Write-Host "= PREPARE: List of $Organisation/$Repository images and tags to be processed:"
Invoke-Expression "$baseDockerCmd config"
Expand Down
6 changes: 3 additions & 3 deletions rhel/ubi9/hotspot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ RUN curl -fsSL "https://github.com/krallin/tini/releases/download/${TINI_VERSION

# jenkins version being bundled in this docker image
ARG JENKINS_VERSION
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.504}
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.516.1}

# jenkins.war checksum, download will be validated using it
ARG JENKINS_SHA=efc91d6be8d79dd078e7f930fc4a5f135602d0822a5efe9091808fdd74607d32
ARG JENKINS_SHA=c308a27e81f4ce3aa6787e96caf771534f7f206fefbb83969d77b15fc7f2700a

# Can be used to customize where jenkins.war get downloaded from
ARG JENKINS_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war
ARG JENKINS_URL

# could use ADD but this one does not check Last-Modified header neither does it allow to control checksum
# see https://github.com/docker/docker/issues/8331
Expand Down
2 changes: 1 addition & 1 deletion tests/test_helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function Run-Program($cmd, $params, $verbose=$false) {
}

function Build-Docker($tag) {
$exitCode, $stdout, $stderr = Run-Program 'docker-compose' '--file=build-windows.yaml build --parallel'
$exitCode, $stdout, $stderr = Run-Program 'docker-compose' '--file=build-windows.yaml build --parallel --build-arg JENKINS_URL=' + $env:JENKINS_URL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if($exitCode -ne 0) {
return $exitCode, $stdout, $stderr
}
Expand Down
6 changes: 3 additions & 3 deletions windows/windowsservercore/hotspot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ RUN New-Item -ItemType Directory -Force -Path C:/ProgramData/Jenkins/Reference/i

# jenkins version being bundled in this docker image
ARG JENKINS_VERSION
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.504}
ENV JENKINS_VERSION=${JENKINS_VERSION:-2.516.1}

# jenkins.war checksum, download will be validated using it
ARG JENKINS_SHA=efc91d6be8d79dd078e7f930fc4a5f135602d0822a5efe9091808fdd74607d32
ARG JENKINS_SHA=c308a27e81f4ce3aa6787e96caf771534f7f206fefbb83969d77b15fc7f2700a

# Can be used to customize where jenkins.war get downloaded from
ARG JENKINS_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war
ARG JENKINS_URL

# could use ADD but this one does not check Last-Modified header neither does it allow to control checksum
# see https://github.com/docker/docker/issues/8331
Expand Down