From 4cc014ef4c7e4f0f9b4d207d3a5524f554fd9010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Sun, 23 Jun 2024 00:32:28 +0200 Subject: [PATCH] chore: use docker bake to generate docker compose file --- .gitignore | 2 +- Jenkinsfile | 3 +- Makefile | 5 +- build-windows.yaml | 45 ------- build.ps1 | 176 ++++++++++++++++----------- docker-bake.hcl | 143 ++++++++++++++++++++-- tests/agent.Tests.ps1 | 7 +- tests/inbound-agent.Tests.ps1 | 7 +- tests/test_helpers.psm1 | 3 - updatecli/updatecli.d/jdk11.yaml | 11 -- updatecli/updatecli.d/jdk17.yaml | 13 -- updatecli/updatecli.d/jdk21.yaml | 11 -- windows/nanoserver/Dockerfile | 1 + windows/windowsservercore/Dockerfile | 3 +- 14 files changed, 254 insertions(+), 176 deletions(-) delete mode 100644 build-windows.yaml diff --git a/.gitignore b/.gitignore index 069b0c8f1..43d42f3b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ bats-core/ bats/ target/ -build-windows-current.yaml +build-windows_*.yaml diff --git a/Jenkinsfile b/Jenkinsfile index 073c1ed2c..943cca61a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,7 +54,7 @@ pipeline { } steps { script { - if(isUnix()) { + if (isUnix()) { sh './build.sh' sh './build.sh test' // If the tests are passing for Linux AMD64, then we can build all the CPU architectures @@ -66,6 +66,7 @@ pipeline { } post { always { + archiveArtifacts artifacts: 'build-windows_*.yaml', allowEmptyArchive: true junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results*.xml') } } diff --git a/Makefile b/Makefile index be6266edc..d7b6f7bc8 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,6 @@ check_cli = type "$(1)" >/dev/null 2>&1 || { echo "Error: command '$(1)' require ## Check if a given image exists in the current manifest docker-bake.hcl check_image = make --silent list | grep -w '$(1)' >/dev/null 2>&1 || { echo "Error: the image '$(1)' does not exist in manifest for the platform 'linux/$(ARCH)'. Please check the output of 'make list'. Exiting." ; exit 1 ; } ## Base "docker buildx base" command to be reused everywhere -bake_base_cli := docker buildx bake -f docker-bake.hcl --load bake_base_cli := docker buildx bake --file docker-bake.hcl bake_cli := $(bake_base_cli) --load @@ -39,12 +38,12 @@ docker-init: check-reqs docker run --rm --privileged multiarch/qemu-user-static --reset -p yes build: check-reqs - @set -x; $(bake_cli) --set '*.platform=linux/$(ARCH)' $(shell make --silent list) + @set -x; $(bake_cli) $(shell make --silent list) --set '*.platform=linux/$(ARCH)' build-%: @$(call check_image,$*) @echo "== building $*" - @set -x; $(bake_cli) --set '*.platform=linux/$(ARCH)' '$*' + @set -x; $(bake_cli) '$*' --set '*.platform=linux/$(ARCH)' every-build: check-reqs @set -x; $(bake_base_cli) linux diff --git a/build-windows.yaml b/build-windows.yaml deleted file mode 100644 index 5e9dcc74d..000000000 --- a/build-windows.yaml +++ /dev/null @@ -1,45 +0,0 @@ -services: - jdk11: - image: ${DOCKERHUB_ORGANISATION}/${DOCKERHUB_REPO}:jdk11-${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG} - build: - context: ./ - dockerfile: ./windows/${WINDOWS_FLAVOR}/Dockerfile - args: - JAVA_HOME: "C:/openjdk-11" - JAVA_VERSION: 11.0.23+9 - VERSION: ${REMOTING_VERSION} - WINDOWS_VERSION_TAG: ${WINDOWS_VERSION_TAG} - WINDOWS_VERSION_DIGEST: ${WINDOWS_VERSION_DIGEST} - TOOLS_WINDOWS_VERSION: ${TOOLS_WINDOWS_VERSION} - tags: - - "${DOCKERHUB_ORGANISATION}/${DOCKERHUB_REPO}:${REMOTING_VERSION}-${BUILD_NUMBER}-jdk11-${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG}" - jdk17: - image: ${DOCKERHUB_ORGANISATION}/${DOCKERHUB_REPO}:jdk17-${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG} - build: - context: ./ - dockerfile: ./windows/${WINDOWS_FLAVOR}/Dockerfile - args: - JAVA_HOME: "C:/openjdk-17" - JAVA_VERSION: 17.0.11+9 - VERSION: ${REMOTING_VERSION} - WINDOWS_VERSION_TAG: ${WINDOWS_VERSION_TAG} - WINDOWS_VERSION_DIGEST: ${WINDOWS_VERSION_DIGEST} - TOOLS_WINDOWS_VERSION: ${TOOLS_WINDOWS_VERSION} - tags: - - "${DOCKERHUB_ORGANISATION}/${DOCKERHUB_REPO}:${REMOTING_VERSION}-${BUILD_NUMBER}-jdk17-${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG}" - - "${DOCKERHUB_ORGANISATION}/${DOCKERHUB_REPO}:${REMOTING_VERSION}-${BUILD_NUMBER}-${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG}" - - "${DOCKERHUB_ORGANISATION}/${DOCKERHUB_REPO}:${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG}" - jdk21: - image: ${DOCKERHUB_ORGANISATION}/${DOCKERHUB_REPO}:jdk21-${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG} - build: - context: ./ - dockerfile: ./windows/${WINDOWS_FLAVOR}/Dockerfile - args: - JAVA_HOME: "C:/openjdk-21" - JAVA_VERSION: 21.0.3+9 - VERSION: ${REMOTING_VERSION} - WINDOWS_VERSION_TAG: ${WINDOWS_VERSION_TAG} - WINDOWS_VERSION_DIGEST: ${WINDOWS_VERSION_DIGEST} - TOOLS_WINDOWS_VERSION: ${TOOLS_WINDOWS_VERSION} - tags: - - "${DOCKERHUB_ORGANISATION}/${DOCKERHUB_REPO}:${REMOTING_VERSION}-${BUILD_NUMBER}-jdk21-${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG}" diff --git a/build.ps1 b/build.ps1 index 90ad742bd..18909db60 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,41 +1,40 @@ [CmdletBinding()] Param( - [Parameter(Position=1)] + [Parameter(Position = 1)] + # Default build.ps1 target [String] $Target = 'build', + # Remoting version to include [String] $RemotingVersion = '3256.v88a_f6e922152', + # Type of agent ("agent" or "inbound-agent") [String] $AgentType = '', + # Windows flavor and windows version to build + [String] $ImageType = 'nanoserver-ltsc2019', + # Image build number [String] $BuildNumber = '1', - [switch] $DisableEnvProps = $false, + # Generate a docker compose file even if it already exists + [switch] $OverwriteDockerComposeFile = $false, + # Print the build and publish command instead of executing them if set [switch] $DryRun = $false, - # Output debug info for tests. Accepted values: - # - empty (no additional test output) - # - 'debug' (test cmd & stderr outputed) - # - 'verbose' (test cmd, stderr, stdout outputed) + # Output debug info for tests: 'empty' (no additional test output), 'debug' (test cmd & stderr outputed), 'verbose' (test cmd, stderr, stdout outputed) [String] $TestsDebug = '' ) $ErrorActionPreference = 'Stop' +$ProgressPreference = 'SilentlyContinue' # Disable Progress bar for faster downloads + +if (![String]::IsNullOrWhiteSpace($env:TESTS_DEBUG)) { + $TestsDebug = $env:TESTS_DEBUG +} +$env:TESTS_DEBUG = $TestsDebug -$originalDockerComposeFile = 'build-windows.yaml' -$finalDockerComposeFile = 'build-windows-current.yaml' -$baseDockerCmd = 'docker-compose --file={0}' -f $finalDockerComposeFile -$baseDockerBuildCmd = '{0} build --parallel --pull' -f $baseDockerCmd +if (![String]::IsNullOrWhiteSpace($env:AGENT_TYPE)) { + $AgentType = $env:AGENT_TYPE +} $AgentTypes = @('agent', 'inbound-agent') if ($AgentType -ne '' -and $AgentType -in $AgentTypes) { $AgentTypes = @($AgentType) } -$ImageType = 'windowsservercore-ltsc2019' -$Organisation = 'jenkins4eval' -$Repository = @{ - 'agent' = 'agent' - 'inbound-agent' = 'inbound-agent' -} - -if (![String]::IsNullOrWhiteSpace($env:TESTS_DEBUG)) { - $TestsDebug = $env:TESTS_DEBUG -} -$env:TESTS_DEBUG = $TestsDebug if (!$DisableEnvProps) { Get-Content env.props | ForEach-Object { @@ -48,18 +47,6 @@ if (!$DisableEnvProps) { } } -if (![String]::IsNullOrWhiteSpace($env:DOCKERHUB_ORGANISATION)) { - $Organisation = $env:DOCKERHUB_ORGANISATION -} - -if (![String]::IsNullOrWhiteSpace($env:DOCKERHUB_REPO_AGENT)) { - $Repository['agent'] = $env:DOCKERHUB_REPO_AGENT -} - -if (![String]::IsNullOrWhiteSpace($env:DOCKERHUB_REPO_INBOUND_AGENT)) { - $Repository['inbound-agent'] = $env:DOCKERHUB_REPO_INBOUND_AGENT -} - if (![String]::IsNullOrWhiteSpace($env:REMOTING_VERSION)) { $RemotingVersion = $env:REMOTING_VERSION } @@ -72,6 +59,16 @@ if (![String]::IsNullOrWhiteSpace($env:IMAGE_TYPE)) { $ImageType = $env:IMAGE_TYPE } +$Organisation = 'jenkins4eval' +if (![String]::IsNullOrWhiteSpace($env:DOCKERHUB_ORGANISATION)) { + $Organisation = $env:DOCKERHUB_ORGANISATION +} + +# Ensure constant env vars used in docker-bake.hcl are defined +$env:REGISTRY_ORG = "$Organisation" +$env:REMOTING_VERSION = "$RemotingVersion" +$env:BUILD_NUMBER = $BuildNumber + # Check for required commands Function Test-CommandExists { # From https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/ @@ -82,8 +79,14 @@ Function Test-CommandExists { $oldPreference = $ErrorActionPreference $ErrorActionPreference = 'stop' try { - if (Get-Command $command){ + # Special case to test "docker buildx" + if ($command.Contains(' ')) { + Invoke-Expression $command | Out-Null Write-Debug "$command exists" + } else { + if(Get-Command $command){ + Write-Debug "$command exists" + } } } Catch { @@ -94,36 +97,15 @@ Function Test-CommandExists { } } -# Ensure constant env vars used in the docker compose file are defined -$env:DOCKERHUB_ORGANISATION = "$Organisation" -$env:REMOTING_VERSION = "$RemotingVersion" -$env:BUILD_NUMBER = $BuildNumber - -$items = $ImageType.Split('-') -$env:WINDOWS_FLAVOR = $items[0] -$env:WINDOWS_VERSION_TAG = $items[1] -$env:TOOLS_WINDOWS_VERSION = $items[1] -if ($items[1] -eq 'ltsc2019') { - # There are no mcr.microsoft.com/powershell:*-ltsc2019 docker images unfortunately, only "1809" ones - $env:TOOLS_WINDOWS_VERSION = '1809' - # Workaround for 2019 only until https://github.com/microsoft/Windows-Containers/issues/493 is solved - $env:WINDOWS_VERSION_DIGEST = '@sha256:6fdf140282a2f809dae9b13fe441635867f0a27c33a438771673b8da8f3348a4' -} - -$ProgressPreference = 'SilentlyContinue' # Disable Progress bar for faster downloads - -Test-CommandExists 'docker' -Test-CommandExists 'docker-compose' -Test-CommandExists 'yq' - function Test-Image { param ( - $AgentTypeAndImageName + [String] $AgentTypeAndImageName ) + # Ex: agent|docker.io/jenkins/agent:jdk21-windowsservercore-ltsc2019|21.0.3_9 $items = $AgentTypeAndImageName.Split('|') $agentType = $items[0] - $imageName = $items[1] + $imageName = $items[1] -replace 'docker.io/', '' $javaVersion = $items[2] $imageNameItems = $imageName.Split(':') $imageTag = $imageNameItems[1] @@ -157,19 +139,71 @@ function Test-Image { return $failed } +function Initialize-DockerComposeFile { + param ( + [String] $AgentType, + [String] $ImageType, + [String] $DockerComposeFile + ) + + $baseDockerBakeCmd = 'docker buildx bake --progress=plain --file=docker-bake.hcl' + + $items = $ImageType.Split('-') + $windowsFlavor = $items[0] + $windowsVersion = $items[1] + + # Override the list of Windows versions taken defined in docker-bake.hcl by the version from image type + $env:WINDOWS_VERSION_OVERRIDE = $windowsVersion + + # Override the list of agent types defined in docker-bake.hcl by the specified agent type + $env:WINDOWS_AGENT_TYPE_OVERRIDE = $AgentType + + # Retrieve the targets from docker buildx bake --print output + # Remove the 'output' section (unsupported by docker compose) + # For each target name as service key, return a map consisting of: + # - 'image' set to the first tag value + # - 'build' set to the content of the bake target + $yqMainQuery = '''.target[]' + ` + ' | del(.output)' + ` + ' | {(. | key): {\"image\": .tags[0], \"build\": .}}''' + # Encapsulate under a top level 'services' map + $yqServicesQuery = '''{\"services\": .}''' + + # - Use docker buildx bake to output image definitions from the "" bake target + # - Convert with yq to the format expected by docker compose + # - Store the result in the docker compose file + $generateDockerComposeFileCmd = ' {0} {1} --print' -f $baseDockerBakeCmd, $windowsFlavor + ` + ' | yq --prettyPrint {0} | yq {1}' -f $yqMainQuery, $yqServicesQuery + ` + ' | Out-File -FilePath {0}' -f $DockerComposeFile + + Write-Host "= PREPARE: Docker compose file generation command`n$generateDockerComposeFileCmd" + + Invoke-Expression $generateDockerComposeFileCmd + + # Remove override + Remove-Item env:\WINDOWS_VERSION_OVERRIDE + Remove-Item env:\WINDOWS_AGENT_TYPE_OVERRIDE +} + +Test-CommandExists 'docker' +Test-CommandExists 'docker-compose' +Test-CommandExists 'docker buildx' +Test-CommandExists 'yq' + foreach($agentType in $AgentTypes) { - # Ensure remaining env vars used in the docker compose file are defined - $env:AGENT_TYPE = $agentType - $env:DOCKERHUB_REPO = $Repository[$agentType] - - # Temporary docker compose file (git ignored) - Copy-Item -Path $originalDockerComposeFile -Destination $finalDockerComposeFile - # If it's an "agent" type, add the corresponding target - if ($agentType -eq 'agent') { - yq '.services.[].build.target = \"agent\"' $originalDockerComposeFile | Out-File -FilePath $finalDockerComposeFile + $dockerComposeFile = 'build-windows_{0}_{1}.yaml' -f $AgentType, $ImageType + $baseDockerCmd = 'docker-compose --file={0}' -f $dockerComposeFile + $baseDockerBuildCmd = '{0} build --parallel --pull' -f $baseDockerCmd + + # Generate the docker compose file if it doesn't exists or if the parameter OverwriteDockerComposeFile is set + if ((Test-Path $dockerComposeFile) -and -not $OverwriteDockerComposeFile) { + Write-Host "= PREPARE: The docker compose file '$dockerComposeFile' containing the image definitions already exists." + } else { + Write-Host "= PREPARE: Initialize the docker compose file '$dockerComposeFile' containing the image definitions." + Initialize-DockerComposeFile -AgentType $AgentType -ImageType $ImageType -DockerComposeFile $dockerComposeFile } - Write-Host "= PREPARE: List of $Organisation/$env:DOCKERHUB_REPO images and tags to be processed:" + Write-Host '= PREPARE: List of images and tags to be processed:' Invoke-Expression "$baseDockerCmd config" Write-Host '= BUILD: Building all images...' @@ -216,9 +250,9 @@ foreach($agentType in $AgentTypes) { Write-Host "= TEST: Testing all ${agentType} images..." # Only fail the run afterwards in case of any test failures $testFailed = $false - $jdks = Invoke-Expression "$baseDockerCmd config" | yq -r --output-format json '.services' | ConvertFrom-Json - foreach ($jdk in $jdks.PSObject.Properties) { - $testFailed = $testFailed -or (Test-Image ('{0}|{1}|{2}' -f $agentType, $jdk.Value.image, $jdk.Value.build.args.JAVA_VERSION)) + $imageDefinitions = Invoke-Expression "$baseDockerCmd config" | yq --unwrapScalar --output-format json '.services' | ConvertFrom-Json + foreach ($imageDefinition in $imageDefinitions.PSObject.Properties) { + $testFailed = $testFailed -or (Test-Image ('{0}|{1}|{2}' -f $agentType, $imageDefinition.Value.image, $imageDefinition.Value.build.args.JAVA_VERSION)) } # Fail if any test failures diff --git a/docker-bake.hcl b/docker-bake.hcl index eec7f6780..d61d291fa 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -6,6 +6,13 @@ group "linux" { ] } +group "windows" { + targets = [ + "nanoserver", + "windowsservercore" + ] +} + group "linux-agent-only" { targets = [ "agent_archlinux_jdk11", @@ -56,6 +63,10 @@ group "linux-ppc64le" { ] } +variable "agent_types_to_build" { + default = ["agent", "inbound-agent"] +} + variable "jdks_to_build" { default = [11, 17, 21] } @@ -64,6 +75,18 @@ variable "default_jdk" { default = 17 } +variable "JAVA11_VERSION" { + default = "11.0.23_9" +} + +variable "JAVA17_VERSION" { + default = "17.0.11_9" +} + +variable "JAVA21_VERSION" { + default = "21.0.3_9" +} + variable "REMOTING_VERSION" { default = "3256.v88a_f6e922152" } @@ -104,18 +127,18 @@ variable "DEBIAN_RELEASE" { default = "bookworm-20240612" } -variable "JAVA11_VERSION" { - default = "11.0.23_9" +# Set this value to a specific Windows version to override Windows versions to build returned by windowsversions function +variable "WINDOWS_VERSION_OVERRIDE" { + default = "" } -variable "JAVA17_VERSION" { - default = "17.0.11_9" -} - -variable "JAVA21_VERSION" { - default = "21.0.3_9" +# Set this value to a specific agent type to override agent type to build returned by windowsagenttypes function +variable "WINDOWS_AGENT_TYPE_OVERRIDE" { + default = "" } +## Common functions +# Return the registry organization and repository depending on the agent type function "orgrepo" { params = [agentType] result = equal("agent", agentType) ? "${REGISTRY_ORG}/${REGISTRY_REPO_AGENT}" : "${REGISTRY_ORG}/${REGISTRY_REPO_INBOUND_AGENT}" @@ -137,6 +160,7 @@ function "javaversion" { : "${JAVA21_VERSION}")) } +## Specific functions # Return an array of Alpine platforms to use depending on the jdk passed as parameter function "alpine_platforms" { params = [jdk] @@ -155,9 +179,50 @@ function "debian_platforms" { : ["linux/amd64", "linux/arm64", "linux/ppc64le", "linux/s390x"])) } + +# Return array of Windows version(s) to build +# There is no mcr.microsoft.com/windows/servercore:1809 image +# Can be overriden by setting WINDOWS_VERSION_OVERRIDE to a specific Windows version +# Ex: WINDOWS_VERSION_OVERRIDE=1809 docker buildx bake windows +function "windowsversions" { + params = [flavor] + result = (notequal(WINDOWS_VERSION_OVERRIDE, "") + ? [WINDOWS_VERSION_OVERRIDE] + : (equal(flavor, "windowsservercore") + ? ["ltsc2019", "ltsc2022"] + : ["1809", "ltsc2019", "ltsc2022"])) +} + +# Return array of agent type(s) to build +# Can be overriden to a specific agent type +function "windowsagenttypes" { + params = [override] + result = (notequal(override, "") + ? [override] + : agent_types_to_build) +} + +# Return the Windows version to use as base image for the Windows version passed as parameter +# There is no mcr.microsoft.com/powershell ltsc2019 base image, using a "1809" instead +function "toolsversion" { + params = [version] + result = (equal("ltsc2019", version) + ? "1809" + : version) +} + +# Return the Windows version digest to use for windowsservercore ltsc2019 image +# TODO: workaround, to be removed when https://github.com/microsoft/Windows-Containers/issues/493 is resolved +function "windowsversiondigest" { + params = [version] + result = (equal("ltsc2019", version) + ? "@sha256:6fdf140282a2f809dae9b13fe441635867f0a27c33a438771673b8da8f3348a4" + : "") +} + target "alpine" { matrix = { - type = ["agent", "inbound-agent"] + type = agent_types_to_build jdk = jdks_to_build } name = "${type}_alpine_jdk${jdk}" @@ -191,7 +256,7 @@ target "alpine" { target "debian" { matrix = { - type = ["agent", "inbound-agent"] + type = agent_types_to_build jdk = jdks_to_build } name = "${type}_debian_jdk${jdk}" @@ -237,3 +302,61 @@ target "agent_archlinux_jdk11" { ] platforms = ["linux/amd64"] } + +target "nanoserver" { + matrix = { + type = windowsagenttypes(WINDOWS_AGENT_TYPE_OVERRIDE) + jdk = jdks_to_build + windows_version = windowsversions("nanoserver") + } + name = "${type}_nanoserver-${windows_version}_jdk${jdk}" + dockerfile = "windows/nanoserver/Dockerfile" + context = "." + args = { + JAVA_HOME = "C:/openjdk-${jdk}" + JAVA_VERSION = "${replace(javaversion(jdk), "_", "+")}" + TOOLS_WINDOWS_VERSION = "${toolsversion(windows_version)}" + VERSION = REMOTING_VERSION + WINDOWS_VERSION_DIGEST = windowsversiondigest(windows_version) + WINDOWS_VERSION_TAG = windows_version + } + target = type + tags = [ + # If there is a tag, add versioned tag containing the jdk + equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-jdk${jdk}-nanoserver-${windows_version}" : "", + # If there is a tag and if the jdk is the default one, add versioned and short tags + equal(ON_TAG, "true") ? (is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-nanoserver-${windows_version}" : "") : "", + equal(ON_TAG, "true") ? (is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:nanoserver-${windows_version}" : "") : "", + "${REGISTRY}/${orgrepo(type)}:jdk${jdk}-nanoserver-${windows_version}", + ] + platforms = ["windows/amd64"] +} + +target "windowsservercore" { + matrix = { + type = windowsagenttypes(WINDOWS_AGENT_TYPE_OVERRIDE) + jdk = jdks_to_build + windows_version = windowsversions("windowsservercore") + } + name = "${type}_windowsservercore-${windows_version}_jdk${jdk}" + dockerfile = "windows/windowsservercore/Dockerfile" + context = "." + args = { + JAVA_HOME = "C:/openjdk-${jdk}" + JAVA_VERSION = "${replace(javaversion(jdk), "_", "+")}" + TOOLS_WINDOWS_VERSION = "${toolsversion(windows_version)}" + VERSION = REMOTING_VERSION + WINDOWS_VERSION_DIGEST = windowsversiondigest(windows_version) + WINDOWS_VERSION_TAG = windows_version + } + target = type + tags = [ + # If there is a tag, add versioned tag containing the jdk + equal(ON_TAG, "true") ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-jdk${jdk}-windowsservercore-${windows_version}" : "", + # If there is a tag and if the jdk is the default one, add versioned and short tags + equal(ON_TAG, "true") ? (is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:${REMOTING_VERSION}-${BUILD_NUMBER}-windowsservercore-${windows_version}" : "") : "", + equal(ON_TAG, "true") ? (is_default_jdk(jdk) ? "${REGISTRY}/${orgrepo(type)}:windowsservercore-${windows_version}" : "") : "", + "${REGISTRY}/${orgrepo(type)}:jdk${jdk}-windowsservercore-${windows_version}", + ] + platforms = ["windows/amd64"] +} diff --git a/tests/agent.Tests.ps1 b/tests/agent.Tests.ps1 index 0c1a65769..ed196dce1 100644 --- a/tests/agent.Tests.ps1 +++ b/tests/agent.Tests.ps1 @@ -1,6 +1,6 @@ Import-Module -DisableNameChecking -Force $PSScriptRoot/test_helpers.psm1 -$global:IMAGE_NAME = Get-EnvOrDefault 'IMAGE_NAME' '' +$global:IMAGE_NAME = Get-EnvOrDefault 'IMAGE_NAME' '' # Ex: jenkins/agent:jdk17-nanoserver-1809 $global:VERSION = Get-EnvOrDefault 'VERSION' '' $global:JAVA_VERSION = Get-EnvOrDefault 'JAVA_VERSION' '' @@ -19,8 +19,9 @@ if ($items[2] -eq 'ltsc2019') { $global:WINDOWSVERSIONFALLBACKTAG = '1809' } -# TODO: make this name unique for concurency -$global:CONTAINERNAME = 'pester-jenkins-agent-{0}' -f $global:IMAGE_TAG +$random = Get-Random +$global:CONTAINERNAME = 'pester-jenkins-agent_{0}_{1}' -f $global:IMAGE_TAG, $random +Write-Host "= TESTS: container name $global:CONTAINERNAME" $global:CONTAINERSHELL = 'powershell.exe' if ($global:WINDOWSFLAVOR -eq 'nanoserver') { diff --git a/tests/inbound-agent.Tests.ps1 b/tests/inbound-agent.Tests.ps1 index 605099eb5..5d0cf9244 100644 --- a/tests/inbound-agent.Tests.ps1 +++ b/tests/inbound-agent.Tests.ps1 @@ -1,6 +1,6 @@ Import-Module -DisableNameChecking -Force $PSScriptRoot/test_helpers.psm1 -$global:IMAGE_NAME = Get-EnvOrDefault 'IMAGE_NAME' '' +$global:IMAGE_NAME = Get-EnvOrDefault 'IMAGE_NAME' '' # Ex: jenkins/inbound-agent:jdk17-nanoserver-1809 $global:VERSION = Get-EnvOrDefault 'VERSION' '' $global:JAVA_VERSION = Get-EnvOrDefault 'JAVA_VERSION' '' @@ -15,8 +15,9 @@ $global:JAVAMAJORVERSION = $items[0].Remove(0,3) $global:WINDOWSFLAVOR = $items[1] $global:WINDOWSVERSIONTAG = $items[2] -# TODO: make this name unique for concurency -$global:CONTAINERNAME = 'pester-jenkins-inbound-agent-{0}' -f $global:IMAGE_TAG +$random = Get-Random +$global:CONTAINERNAME = 'pester-jenkins-inbound-agent_{0}_{1}' -f $global:IMAGE_TAG, $random +Write-Host "= TESTS: container name $global:CONTAINERNAME" $global:CONTAINERSHELL = 'powershell.exe' if ($global:WINDOWSFLAVOR -eq 'nanoserver') { diff --git a/tests/test_helpers.psm1 b/tests/test_helpers.psm1 index 18399978a..59243160f 100644 --- a/tests/test_helpers.psm1 +++ b/tests/test_helpers.psm1 @@ -98,9 +98,6 @@ function Is-ContainerRunning($container='') { } function Run-Program($cmd, $params) { - if(-not $quiet) { - Write-Host "cmd & params: $cmd $params" - } $psi = New-Object System.Diagnostics.ProcessStartInfo $psi.CreateNoWindow = $true $psi.UseShellExecute = $false diff --git a/updatecli/updatecli.d/jdk11.yaml b/updatecli/updatecli.d/jdk11.yaml index 07c2fdafe..3baadee4c 100644 --- a/updatecli/updatecli.d/jdk11.yaml +++ b/updatecli/updatecli.d/jdk11.yaml @@ -95,17 +95,6 @@ targets: file: docker-bake.hcl path: variable.JAVA11_VERSION.default scmid: default - setJDK11VersionDockerCompose: - name: "Bump JDK11 version for Windows images in the build-windows.yaml file" - kind: yaml - spec: - file: build-windows.yaml - key: $.services.jdk11.build.args.JAVA_VERSION - scmid: default - transformers: - - replacer: - from: _ - to: + actions: default: diff --git a/updatecli/updatecli.d/jdk17.yaml b/updatecli/updatecli.d/jdk17.yaml index bf001835d..9b93a7bb4 100644 --- a/updatecli/updatecli.d/jdk17.yaml +++ b/updatecli/updatecli.d/jdk17.yaml @@ -88,7 +88,6 @@ conditions: image: eclipse-temurin targets: - ## Global config files setJDK17VersionDockerBake: name: "Bump JDK17 version for Linux images in the docker-bake.hcl file" kind: hcl @@ -96,18 +95,6 @@ targets: file: docker-bake.hcl path: variable.JAVA17_VERSION.default scmid: default - setJDK17VersionDockerCompose: - name: "Bump JDK17 version for Windows images in the build-windows.yaml file" - kind: yaml - spec: - file: build-windows.yaml - key: $.services.jdk17.build.args.JAVA_VERSION - scmid: default - transformers: - - replacer: - from: _ - to: + - ## Dockerfiles setJDK17VersionAlpine: name: "Bump JDK17 default ARG version on Alpine Dockerfile" kind: dockerfile diff --git a/updatecli/updatecli.d/jdk21.yaml b/updatecli/updatecli.d/jdk21.yaml index 7ce7e4109..16bb8b0d3 100644 --- a/updatecli/updatecli.d/jdk21.yaml +++ b/updatecli/updatecli.d/jdk21.yaml @@ -100,17 +100,6 @@ targets: file: docker-bake.hcl path: variable.JAVA21_VERSION.default scmid: default - setJDK21VersionDockerCompose: - name: "Bump JDK21 version for Windows images in the build-windows.yaml file" - kind: yaml - spec: - file: build-windows.yaml - key: $.services.jdk21.build.args.JAVA_VERSION - scmid: default - transformers: - - replacer: - from: _ - to: + actions: default: diff --git a/windows/nanoserver/Dockerfile b/windows/nanoserver/Dockerfile index 40b144164..a31737bd0 100644 --- a/windows/nanoserver/Dockerfile +++ b/windows/nanoserver/Dockerfile @@ -24,6 +24,7 @@ ARG WINDOWS_VERSION_TAG=ltsc2019 ARG TOOLS_WINDOWS_VERSION=1809 +# TODO: workaround, to be removed when https://github.com/microsoft/Windows-Containers/issues/493 is resolved ARG WINDOWS_VERSION_DIGEST # Empty by default FROM mcr.microsoft.com/windows/servercore:"${WINDOWS_VERSION_TAG}${WINDOWS_VERSION_DIGEST}" AS jdk-core diff --git a/windows/windowsservercore/Dockerfile b/windows/windowsservercore/Dockerfile index 6271c3a3d..cd2dc4aea 100644 --- a/windows/windowsservercore/Dockerfile +++ b/windows/windowsservercore/Dockerfile @@ -23,8 +23,9 @@ # THE SOFTWARE. ARG WINDOWS_VERSION_TAG=ltsc2019 -ARG WINDOWS_VERSION_DIGEST # Empty by default ARG TOOLS_WINDOWS_VERSION # Empty (only used on nanoserver) +# TODO: workaround, to be removed when https://github.com/microsoft/Windows-Containers/issues/493 is resolved +ARG WINDOWS_VERSION_DIGEST # Empty by default FROM mcr.microsoft.com/windows/servercore:"${WINDOWS_VERSION_TAG}${WINDOWS_VERSION_DIGEST}" AS jdk-core # $ProgressPreference: https://github.com/PowerShell/PowerShell/issues/2138#issuecomment-251261324