diff --git a/Jenkinsfile b/Jenkinsfile index bd28e5c5..cba8b85f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,7 @@ final String cronExpr = env.BRANCH_IS_PRIMARY ? '@daily' : '' properties([ buildDiscarder(logRotator(numToKeepStr: '10')), - disableConcurrentBuilds(abortPrevious: true), + // disableConcurrentBuilds(abortPrevious: true), pipelineTriggers([cron(cronExpr)]), ]) @@ -17,9 +17,9 @@ def agentSelector(String imageType) { return 'docker-highmem' } } - // Windows Server Core 2022 agent - if (imageType.contains('2022')) { - return 'windows-2022' + // Windows Server Core 2025 can build both 2022 and 2025 images + if (imageType.contains('2022') || imageType.contains('2025')) { + return 'windows-2025' } // Windows Server Core 2019 agent (for nanoserver 1809 & ltsc2019 and for windowservercore ltsc2019) return 'windows-2019' @@ -43,13 +43,15 @@ def spotAgentSelector(String agentLabel, int counter) { // Specify parallel stages def parallelStages = [failFast: false] [ - 'linux', - 'nanoserver-1809', + // 'linux', + // 'nanoserver-1809', 'nanoserver-ltsc2019', 'nanoserver-ltsc2022', - 'windowsservercore-1809', - 'windowsservercore-ltsc2019', - 'windowsservercore-ltsc2022' + 'nanoserver-ltsc2025', + // 'windowsservercore-1809', + // 'windowsservercore-ltsc2019', + // 'windowsservercore-ltsc2022', + // 'windowsservercore-ltsc2025' ].each { imageType -> parallelStages[imageType] = { withEnv([ @@ -64,9 +66,13 @@ def parallelStages = [failFast: false] node(resolvedAgentLabel) { timeout(time: 60, unit: 'MINUTES') { checkout scm - if (imageType == "linux") { - stage('Prepare Docker') { + stage('Prepare Docker') { + if (isUnix()) { sh 'make docker-init' + } else { + // Check CPU name + powershell 'Get-CimInstance -ClassName Win32_Processor | Out-String' + powershell './build.ps1 docker-init' } } // This function is defined in the jenkins-infra/pipeline-library @@ -94,7 +100,11 @@ def parallelStages = [failFast: false] if (isUnix()) { sh 'make build' } else { + // Free space before building images + powershell 'Invoke-Command -ScriptBlock { ((Get-PSDrive -Name C).Free / 1GB) }' powershell '& ./build.ps1 build' + // Free space remaining after building images + powershell 'Invoke-Command -ScriptBlock { ((Get-PSDrive -Name C).Free / 1GB) }' archiveArtifacts artifacts: 'build-windows.yaml', allowEmptyArchive: true } } @@ -102,7 +112,11 @@ def parallelStages = [failFast: false] if (isUnix()) { sh 'make test' } else { - powershell '& ./build.ps1 test' + // Free space before testing images + powershell 'Invoke-Command -ScriptBlock { ((Get-PSDrive -Name C).Free / 1GB) }' + powershell '& ./build.ps1 test -TestsDebug verbose' + // Free space remaining after testing images + powershell 'Invoke-Command -ScriptBlock { ((Get-PSDrive -Name C).Free / 1GB) }' } junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml') } diff --git a/Makefile b/Makefile index c92ea616..47680aff 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ else docker buildx create --use --bootstrap --driver docker-container endif docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + docker info build: check-reqs @set -x; $(bake_cli) $(shell make --silent list) --set '*.platform=linux/$(ARCH)' diff --git a/build.ps1 b/build.ps1 index 6da2568b..121889f0 100644 --- a/build.ps1 +++ b/build.ps1 @@ -97,7 +97,7 @@ function Test-Image { $env:JAVA_VERSION = "$javaVersion" $targetPath = '.\target\{0}' -f $imageTag - if(Test-Path $targetPath) { + if (Test-Path $targetPath) { Remove-Item -Recurse -Force $targetPath } New-Item -Path $targetPath -Type Directory | Out-Null @@ -116,6 +116,28 @@ function Test-Image { return $failed } +function Initialize-Docker() { + # Cf https://github.com/jenkins-infra/jenkins-infra/blob/production/modules/profile/templates/jenkinscontroller/casc/clouds-ec2.yaml.erb + $dockerDaemonConfigPath = 'C:\ProgramData\Docker\config\daemon.json' + if (Test-Path $dockerDaemonConfigPath) { + $dockerDaemonConfig = Get-Content -Path $dockerDaemonConfigPath -Raw | ConvertFrom-Json + Write-Host "${dockerDaemonConfigPath} file content:" + $dockerDaemonConfig | ConvertTo-Json + # Remove docker daemon config setting "data-root" to Z:\docker (NVMe mount) to avoid hitting moby/moby#48093 + Remove-Item -Path $dockerDaemonConfigPath + Restart-Service docker + # Push-Location -Path 'C:\Windows' + # Rename-Item SystemTemp SystemTemp.old + # cmd.exe /c 'mklink /D SystemTemp {0}' -f $dockerDaemonConfig.PSObject.Properties['data-root'].Value + # Pop-Location + } + Get-ComputerInfo | Select-Object OsName, OsBuildNumber, WindowsVersion + Get-WindowsFeature Containers | Out-String + Invoke-Expression 'docker info' + Get-CimInstance -ClassName Win32_Processor + Get-ChildItem env: | Select-Object Name, Value +} + function Initialize-DockerComposeFile { $baseDockerBakeCmd = 'docker buildx bake --progress=plain --file=docker-bake.hcl' @@ -146,7 +168,7 @@ function Initialize-DockerComposeFile { Write-Host "= PREPARE: Docker compose file generation command`n$generateDockerComposeFileCmd" - Invoke-Expression $generateDockerComposeFileCmd + Invoke-Expression $generateDockerComposeFileCmd | Out-Null # Remove override Remove-Item env:\WINDOWS_VERSION_OVERRIDE @@ -157,6 +179,10 @@ Test-CommandExists 'docker-compose' Test-CommandExists 'docker buildx' Test-CommandExists 'yq' +if($target -eq 'docker-init') { + Initialize-Docker +} + # 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." diff --git a/docker-bake.hcl b/docker-bake.hcl index 3acfd3da..3594356a 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -32,7 +32,8 @@ group "linux-ppc64le" { } variable "jdks_to_build" { - default = [17, 21, 25] + # default = [17, 21, 25] + default = [25] } variable "default_jdk" { @@ -80,6 +81,7 @@ variable "DEBIAN_RELEASE" { } # Set this value to a specific Windows version to override Windows versions to build returned by windowsversions function +# Accept multiple coma-separated versions, ex: ltsc2022,ltsc2025 variable "WINDOWS_VERSION_OVERRIDE" { default = "" } @@ -120,24 +122,27 @@ function "debian_platforms" { # 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 +# Can be overriden by setting WINDOWS_VERSION_OVERRIDE to one or many specific Windows version # Ex: WINDOWS_VERSION_OVERRIDE=1809 docker buildx bake windows function "windowsversions" { params = [flavor] result = (notequal(WINDOWS_VERSION_OVERRIDE, "") - ? [WINDOWS_VERSION_OVERRIDE] + ? split(",", WINDOWS_VERSION_OVERRIDE) : (equal(flavor, "windowsservercore") ? ["ltsc2019", "ltsc2022"] - : ["1809", "ltsc2019", "ltsc2022"])) + : ["1809", "ltsc2019", "ltsc2022", "ltsc2025"])) } # 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 +# There is no mcr.microsoft.com/powershell ltsc2025 base image, using a ltsc2022 instead function "toolsversion" { params = [version] result = (equal("ltsc2019", version) ? "1809" - : version) + : (equal("ltsc2025", version) + ? "ltsc2022" + : version)) } target "alpine" { diff --git a/tests/sshAgent.Tests.ps1 b/tests/sshAgent.Tests.ps1 index 61cda852..a1da5b0d 100644 --- a/tests/sshAgent.Tests.ps1 +++ b/tests/sshAgent.Tests.ps1 @@ -18,6 +18,10 @@ $global:TOOLSWINDOWSVERSION = $items[1] if ($items[1] -eq 'ltsc2019') { $global:TOOLSWINDOWSVERSION = '1809' } +# There is no mcr.microsoft.com/powershell:*-ltsc2025 docker images unfortunately, using a ltsc2022 instead +if ($items[1] -eq 'ltsc2025') { + $global:TOOLSWINDOWSVERSION = 'ltsc2022' +} # TODO: make this name unique for concurency $global:CONTAINERNAME = 'pester-jenkins-ssh-agent-{0}' -f $global:IMAGE_TAG diff --git a/windows/nanoserver/Dockerfile b/windows/nanoserver/Dockerfile index 9c6ed73c..714b95a0 100644 --- a/windows/nanoserver/Dockerfile +++ b/windows/nanoserver/Dockerfile @@ -38,6 +38,26 @@ RUN New-Item -ItemType Directory -Path C:\temp | Out-Null ; ` $proc.WaitForExit() ; ` Remove-Item -Path C:\temp -Recurse | Out-Null +# FROM mcr.microsoft.com/windows/nanoserver:"${WINDOWS_VERSION_TAG}" + +# SHELL ["cmd.exe", "/c"] + +# ARG JAVA_HOME + +# # Download and install PowerShell 7 +# ARG POWERSHELL_VERSION=7.5.4 +# ENV POWERSHELL_VERSION=${POWERSHELL_VERSION} +# ENV PATH="C:\Windows\system32;C:\Windows;C:\Program Files\Powershell;" +# RUN curl.exe --silent --location "https://github.com/PowerShell/PowerShell/releases/download/v%POWERSHELL_VERSION%/PowerShell-%POWERSHELL_VERSION%-win-x64.zip" --output C:/windows/TEMP/pwsh.zip ` +# && mkdir "C:\Program Files\Powershell" ` +# && tar.exe -xf C:\windows\TEMP\pwsh.zip -C "C:\Program Files\Powershell" ` +# && if exist "C:\windows\TEMP\pwsh.zip" del "C:\windows\TEMP\pwsh.zip" + +# SHELL ["pwsh.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] +# USER ContainerAdministrator + +# ENV PSHOME="C:\Program Files\PowerShell" + FROM mcr.microsoft.com/powershell:nanoserver-"${TOOLS_WINDOWS_VERSION}" AS pwsh-source FROM mcr.microsoft.com/windows/nanoserver:"${WINDOWS_VERSION_TAG}" @@ -47,13 +67,12 @@ ENV PSHOME="C:\Program Files\PowerShell" ENV PATH="C:\Windows\system32;C:\Windows;${PSHOME};" # The nanoserver image is nice and small, but we need a couple of things to get SSH working -COPY --from=jdk-core /windows/system32/netapi32.dll /windows/system32/netapi32.dll COPY --from=jdk-core /windows/system32/whoami.exe /windows/system32/whoami.exe COPY --from=jdk-core $JAVA_HOME $JAVA_HOME COPY --from=pwsh-source $PSHOME $PSHOME - -SHELL ["pwsh.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] -USER ContainerAdministrator +# While nanoserver-ltsc2025 includes netapi32.dll, older versions don't +COPY --from=jdk-core /windows/system32/netapi32.dll $PSHOME/netapi32.dll +RUN If (!(Test-Path 'C:/windows/system32/netapi32.dll') -And (Test-Path "$env:PSHOME/netapi32.dll")) { Move-Item "$env:PSHOME/netapi32.dll" 'C:/windows/system32/netapi32.dll' } Else { Write-Host "No $env:PSHOME/netapi32.dll or windows/system32/netapi32.dll alreay exists" } # Backward compatibility with version <= 5.x: create a symlink to the "new" JAVA_HOME RUN $javaMajorVersion = $env:JAVA_HOME.Substring($env:JAVA_HOME.Length - 2); `