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

breaking: use a ltsc2019 base image for windowsservercore-ltsc2019 agent images #459

Merged
merged 32 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
560bc47
feat: add `nanoserver-ltsc2019` tags
lemeurherve Jul 8, 2023
89f829d
Merge branch 'master' into patch-4
lemeurherve Jul 10, 2023
59bff44
Merge branch 'master' into patch-4
lemeurherve Jul 10, 2023
7dfd8e3
debug prepared images list
lemeurherve Jul 10, 2023
815db71
fixup
lemeurherve Jul 10, 2023
b486c16
fixup
lemeurherve Jul 10, 2023
cd8c998
remove output, done in https://github.com/jenkinsci/docker-agent/pull…
lemeurherve Jul 12, 2023
23509f0
Merge branch 'master' into patch-4
lemeurherve Jul 12, 2023
bb6f520
Merge branch 'master' into patch-4
dduportal Jul 24, 2023
0b43eac
Also take care of the default jdk image tag 'nanoserver-ltsc2019'
lemeurherve Jul 24, 2023
c331622
fixup
lemeurherve Jul 24, 2023
98eb64d
ticks around jdk in comments
lemeurherve Jul 24, 2023
580ef8b
fix: additional nanoserver-ltsc2019 image and tags
lemeurherve Jul 28, 2023
32094fd
introduce IMAGE_TYPE
lemeurherve Jul 31, 2023
24b8891
Merge branch 'master' into patch-4
lemeurherve Jul 31, 2023
e8ec3c7
Switch from powershell:<windows_flavor>-<windows_tag> to windows/<win…
lemeurherve Jul 31, 2023
23bffe8
do not build additional images for now
lemeurherve Aug 6, 2023
d630bf4
Add `windowsservercore-1809` image
lemeurherve Aug 7, 2023
23c6c2f
simplify
lemeurherve Aug 7, 2023
8048622
'real' context
lemeurherve Aug 7, 2023
9c8cc5b
add --dockerfile to windows tests
lemeurherve Aug 7, 2023
fa57555
show org/repo in logs
lemeurherve Aug 7, 2023
a800236
fix env var name in test
lemeurherve Aug 7, 2023
5819d4d
don't use snake case for env vars used only in the tests
lemeurherve Aug 7, 2023
903f427
Merge branch 'master' into patch-4
lemeurherve Aug 7, 2023
eb4d1f6
Merge branch 'master' into patch-4
lemeurherve Aug 8, 2023
31a258b
Merge branch 'master' into patch-4
lemeurherve Aug 22, 2023
458f4c7
Update build-windows.yaml
dduportal Sep 2, 2023
0e667d7
Merge branch 'master' into patch-4
dduportal Sep 2, 2023
736c1f4
Merge branch 'master' into patch-4
dduportal Sep 2, 2023
2ac08d4
replace WINDOWS_VERSION_FALLBACK_TAG by TOOLS_WINDOWS_VERSION
lemeurherve Sep 2, 2023
7c2cec1
revert to CRLF on build.ps1
lemeurherve Sep 2, 2023
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
23 changes: 18 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
def agentSelector(String imageType) {
// Image type running on a Linux agent
if (imageType == 'linux') {
return 'linux'
}
// Image types running on a Windows Server Core 2022 agent
if (imageType.contains('2022')) {
return 'windows-2022'
}
// Remaining image types running on a Windows Server Core 2019 agent: (nanoserver|windowservercore)-(1809|2019)
return 'windows-2019'
}

pipeline {
agent none

Expand All @@ -10,14 +23,14 @@ pipeline {
matrix {
axes {
axis {
name 'AGENT_TYPE'
values 'linux', 'windows-2019', 'windows-2022'
name 'IMAGE_TYPE'
values 'linux', 'nanoserver-1809', 'nanoserver-ltsc2022', 'windowsservercore-1809', 'windowsservercore-ltsc2019', 'windowsservercore-ltsc2022'
}
}
stages {
stage('Main') {
agent {
label env.AGENT_TYPE
label agentSelector(env.IMAGE_TYPE)
}
options {
timeout(time: 30, unit: 'MINUTES')
Expand All @@ -28,7 +41,7 @@ pipeline {
stages {
stage('Prepare Docker') {
when {
environment name: 'AGENT_TYPE', value: 'linux'
environment name: 'IMAGE_TYPE', value: 'linux'
}
steps {
sh '''
Expand All @@ -50,7 +63,7 @@ pipeline {
// If the tests are passing for Linux AMD64, then we can build all the CPU architectures
sh 'docker buildx bake --file docker-bake.hcl linux'
} else {
powershell "& ./build.ps1 test"
powershell '& ./build.ps1 test'
}
}
}
Expand Down
34 changes: 10 additions & 24 deletions build-windows.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
services:
jdk11-nanoserver:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I can't remember why we "simplified" so much the compose file. As much as I want to factorize the Dockerfile (which has duplicated logic), I wonder if using the docker-compose to describe (and pass) all kinds of definition we need, like the bakefile, wouldn't help to clarify (and avoid tedious "if then else" in the powershell) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is related to #459 (comment)

There is no "else" in the PowerShell script, what are the tedious parts you're alluding to?

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I remember, #459 (comment) was before you worked into splitting the image build in different lines (in different agents) so I considered it outdated.

There is no "else" in the PowerShell script, what are the tedious parts you're alluding to?

https://github.com/jenkinsci/docker-agent/pull/459/files#diff-3258bc4162690adead72c70b672093e68c92e86a4628148f0015d61738f21b5aR75-R77

While reviewing the PR, I realized that we store part of the definitions in the compose YAML manifest and the other part in code like this one. I have not a solution for it yet (and it is not blocking the PR) but I believe that we should be able to define the logic ltsc2019 (tools at 1809, base at ltsc2019) / 1809 (all in 1809) / ltsc2022 (all in ltsc2022) in one (or multiple) compose files to avoid splitting intelligence between "definition" and "programmatic".

I can totally take a try at this once we have started to deliver the image if ok for you?

Copy link
Contributor

Choose a reason for hiding this comment

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

(don't get me wrong, your work is really good here, I'm nitpicking here!)

image: jdk11-nanoserver-${NANOSERVER_VERSION_NAME}
jdk11:
image: jdk11-${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG}
build:
context: ./windows/nanoserver/
context: ./
dockerfile: ./windows/${WINDOWS_FLAVOR}/Dockerfile
args:
JAVA_HOME: "C:/openjdk-11"
JAVA_VERSION: 11.0.20.1_1
VERSION: ${REMOTING_VERSION}
WINDOWS_VERSION_TAG: ${WINDOWS_VERSION_TAG}
jdk17-nanoserver:
image: jdk17-nanoserver-${NANOSERVER_VERSION_NAME}
TOOLS_WINDOWS_VERSION: ${TOOLS_WINDOWS_VERSION}
jdk17:
image: jdk17-${WINDOWS_FLAVOR}-${WINDOWS_VERSION_TAG}
build:
context: ./windows/nanoserver/
args:
JAVA_HOME: "C:/openjdk-17"
JAVA_VERSION: 17.0.8.1_1
VERSION: ${REMOTING_VERSION}
WINDOWS_VERSION_TAG: ${WINDOWS_VERSION_TAG}
jdk11-windowsservercore:
image: jdk11-windowsservercore-${WINDOWS_VERSION_NAME}
build:
context: ./windows/windowsservercore/
args:
JAVA_HOME: "C:/openjdk-11"
JAVA_VERSION: 11.0.20.1_1
VERSION: ${REMOTING_VERSION}
WINDOWS_VERSION_TAG: ${WINDOWS_VERSION_TAG}
jdk17-windowsservercore:
image: jdk17-windowsservercore-${WINDOWS_VERSION_NAME}
build:
context: ./windows/windowsservercore/
context: ./
dockerfile: ./windows/${WINDOWS_FLAVOR}/Dockerfile
args:
JAVA_HOME: "C:/openjdk-17"
JAVA_VERSION: 17.0.8.1_1
VERSION: ${REMOTING_VERSION}
WINDOWS_VERSION_TAG: ${WINDOWS_VERSION_TAG}
TOOLS_WINDOWS_VERSION: ${TOOLS_WINDOWS_VERSION}
48 changes: 23 additions & 25 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Param(
$ErrorActionPreference = 'Stop'
$Repository = 'agent'
$Organization = 'jenkins'
$AgentType = 'windows-2019'
$ImageType = 'windows-ltsc2019'

if(!$DisableEnvProps) {
Get-Content env.props | ForEach-Object {
Expand All @@ -37,8 +37,8 @@ if(![String]::IsNullOrWhiteSpace($env:REMOTING_VERSION)) {
$RemotingVersion = $env:REMOTING_VERSION
}

if(![String]::IsNullOrWhiteSpace($env:AGENT_TYPE)) {
$AgentType = $env:AGENT_TYPE
if(![String]::IsNullOrWhiteSpace($env:IMAGE_TYPE)) {
$ImageType = $env:IMAGE_TYPE
}

# Check for required commands
Expand Down Expand Up @@ -67,15 +67,16 @@ Function Test-CommandExists {
$defaultJdk = '11'
$builds = @{}
$env:REMOTING_VERSION = "$RemotingVersion"
$env:WINDOWS_VERSION_NAME = $AgentType.replace('windows-', 'ltsc')
$env:NANOSERVER_VERSION_NAME = $env:WINDOWS_VERSION_NAME
$env:WINDOWS_VERSION_TAG = $env:WINDOWS_VERSION_NAME
# Unconsistent naming for the 2019 version, needed as while nanoserver-ltsc2019 and windowsserver-ltsc2019 tags exist eclipse-temurin:<...>-ltsc2019 does not
# We also need to keep the `jdkN-nanoserver-1809` images for now, cf https://github.com/jenkinsci/docker-agent/issues/451
if ($AgentType -eq 'windows-2019') {
$env:WINDOWS_VERSION_TAG = 1809
$env:NANOSERVER_VERSION_NAME = 1809

$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 eclipse-temurin:*-ltsc2019 or mcr.microsoft.com/powershell:*-ltsc2019 docker images unfortunately, only "1809" ones
$env:TOOLS_WINDOWS_VERSION = '1809'
}

$ProgressPreference = 'SilentlyContinue' # Disable Progress bar for faster downloads

Test-CommandExists "docker"
Expand All @@ -86,17 +87,15 @@ $baseDockerCmd = 'docker-compose --file=build-windows.yaml'
$baseDockerBuildCmd = '{0} build --parallel --pull' -f $baseDockerCmd

Invoke-Expression "$baseDockerCmd config --services" 2>$null | ForEach-Object {
$image = '{0}-{1}' -f $_, $env:WINDOWS_VERSION_NAME
# Special case for nanoserver-1809 images
$image = $image.replace('nanoserver-ltsc2019', 'nanoserver-1809')
$items = $image.Split("-")
$jdkMajorVersion = $items[0].Remove(0,3)
$windowsType = $items[1]
$windowsVersion = $items[2]

$baseImage = "${windowsType}-${windowsVersion}"
$image = '{0}-{1}-{2}' -f $_, $env:WINDOWS_FLAVOR, $env:WINDOWS_VERSION_TAG # Ex: "jdk11-nanoserver-1809"

# Remove the 'jdk' prefix
$jdkMajorVersion = $_.Remove(0,3)

$baseImage = "${env:WINDOWS_FLAVOR}-${env:WINDOWS_VERSION_TAG}"
$versionTag = "${RemotingVersion}-${BuildNumber}-${image}"
$tags = @( $image, $versionTag )
# Additional image tag without any 'jdk' prefix for the default JDK
if($jdkMajorVersion -eq "$defaultJdk") {
$tags += $baseImage
}
Expand All @@ -106,7 +105,7 @@ Invoke-Expression "$baseDockerCmd config --services" 2>$null | ForEach-Object {
}
}

Write-Host '= PREPARE: List of images and tags to be processed:'
Write-Host "= PREPARE: List of $Organization/$Repository images and tags to be processed:"
ConvertTo-Json $builds

if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) {
Expand All @@ -132,11 +131,10 @@ function Test-Image {
Write-Host "= TEST: Testing image ${ImageName}:"

$env:AGENT_IMAGE = $ImageName
$serviceName = $ImageName.SubString(0, $ImageName.LastIndexOf('-'))
$env:IMAGE_FOLDER = Invoke-Expression "$baseDockerCmd config" 2>$null | yq -r ".services.${serviceName}.build.context"
$serviceName = $ImageName.SubString(0, $ImageName.IndexOf('-'))
$env:BUILD_CONTEXT = Invoke-Expression "$baseDockerCmd config" 2>$null | yq -r ".services.${serviceName}.build.context"
$env:VERSION = "$RemotingVersion-$BuildNumber"


if(Test-Path ".\target\$ImageName") {
Remove-Item -Recurse -Force ".\target\$ImageName"
}
Expand All @@ -150,7 +148,7 @@ function Test-Image {
Write-Host "There were $($TestResults.PassedCount) passed tests out of $($TestResults.TotalCount) in $ImageName"
}
Remove-Item env:\AGENT_IMAGE
Remove-Item env:\IMAGE_FOLDER
Remove-Item env:\BUILD_CONTEXT
Remove-Item env:\VERSION
}

Expand Down
17 changes: 10 additions & 7 deletions tests/agent.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
Import-Module -DisableNameChecking -Force $PSScriptRoot/test_helpers.psm1

$global:AGENT_IMAGE = Get-EnvOrDefault 'AGENT_IMAGE' ''
$global:IMAGE_FOLDER = Get-EnvOrDefault 'IMAGE_FOLDER' ''
$global:BUILD_CONTEXT = Get-EnvOrDefault 'BUILD_CONTEXT' ''
$global:VERSION = Get-EnvOrDefault 'VERSION' ''
$global:WINDOWS_VERSION_TAG = Get-EnvOrDefault 'WINDOWS_VERSION_TAG' ''

$items = $global:AGENT_IMAGE.Split("-")

# Remove the 'jdk' prefix (3 first characters)
$global:JDKMAJORVERSION = $items[0].Remove(0,3)
# Remove the 'jdk' prefix
$global:JAVAMAJORVERSION = $items[0].Remove(0,3)
$global:WINDOWSFLAVOR = $items[1]
$global:WINDOWSVERSION = $items[2]
$global:WINDOWSVERSIONTAG = $items[2]
$global:WINDOWSVERSIONFALLBACKTAG = $items[2]
if ($items[2] -eq 'ltsc2019') {
$global:WINDOWSVERSIONFALLBACKTAG = '1809'
}

# TODO: make this name unique for concurency
$global:CONTAINERNAME = 'pester-jenkins-agent-{0}' -f $global:AGENT_IMAGE
Expand Down Expand Up @@ -52,7 +55,7 @@ Describe "[$global:AGENT_IMAGE] image has correct applications in the PATH" {
$r = [regex] "^openjdk version `"(?<major>\d+)"
$m = $r.Match($stdout)
$m | Should -Not -Be $null
$m.Groups['major'].ToString() | Should -Be $global:JDKMAJORVERSION
$m.Groups['major'].ToString() | Should -Be $global:JAVAMAJORVERSION
}

It 'has AGENT_WORKDIR in the environment' {
Expand Down Expand Up @@ -127,7 +130,7 @@ Describe "[$global:AGENT_IMAGE] can be built with custom build arguments" {
BeforeAll {
Push-Location -StackName 'agent' -Path "$PSScriptRoot/.."

$exitCode, $stdout, $stderr = Run-Program 'docker' "build --build-arg `"VERSION=${global:TEST_VERSION}`" --build-arg `"WINDOWS_VERSION_TAG=${global:WINDOWS_VERSION_TAG}`" --build-arg `"user=${global:TEST_USER}`" --build-arg `"AGENT_WORKDIR=${global:TEST_AGENT_WORKDIR}`" -t ${global:AGENT_IMAGE} ${global:IMAGE_FOLDER}"
$exitCode, $stdout, $stderr = Run-Program 'docker' "build --build-arg `"VERSION=${global:TEST_VERSION}`" --build-arg `"WINDOWS_VERSION_TAG=${global:WINDOWSVERSIONTAG}`" --build-arg `"TOOLS_WINDOWS_VERSION=${global:WINDOWSVERSIONFALLBACKTAG}`" --build-arg `"user=${global:TEST_USER}`" --build-arg `"AGENT_WORKDIR=${global:TEST_AGENT_WORKDIR}`" --tag ${global:AGENT_IMAGE} --file ./windows/${global:WINDOWSFLAVOR}/Dockerfile ${global:BUILD_CONTEXT}"
$exitCode | Should -Be 0

docker run -d -it --name "$global:CONTAINERNAME" -P "$global:AGENT_IMAGE" "$global:CONTAINERSHELL"
Expand Down
5 changes: 4 additions & 1 deletion tests/test_helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ function Run-Program($cmd, $params) {
$stderr = $proc.StandardError.ReadToEnd()
$proc.WaitForExit()
if($proc.ExitCode -ne 0) {
Write-Host "`n`nstdout:`n$stdout`n`nstderr:`n$stderr`n`ncmd:`n$cmd`n`nparams:`n$param`n`n"
Write-Host "[err] stdout:`n$stdout"
Write-Host "[err] stderr:`n$stderr"
Write-Host "[err] cmd:`n$cmd"
Write-Host "[err] params:`n$param"
}

return $proc.ExitCode, $stdout, $stderr
Expand Down
12 changes: 9 additions & 3 deletions windows/nanoserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@
# THE SOFTWARE.

ARG JAVA_VERSION=17.0.7_7
ARG WINDOWS_VERSION_TAG=1809
FROM eclipse-temurin:"${JAVA_VERSION}"-jdk-windowsservercore-"${WINDOWS_VERSION_TAG}" AS jdk-core
ARG WINDOWS_VERSION_TAG=ltsc2019
ARG TOOLS_WINDOWS_VERSION=1809
FROM eclipse-temurin:"${JAVA_VERSION}"-jdk-windowsservercore-"${TOOLS_WINDOWS_VERSION}" AS jdk-core

FROM mcr.microsoft.com/powershell:nanoserver-"${WINDOWS_VERSION_TAG}"
FROM mcr.microsoft.com/powershell:nanoserver-"${TOOLS_WINDOWS_VERSION}" AS pwsh-source

FROM mcr.microsoft.com/windows/nanoserver:"${WINDOWS_VERSION_TAG}"

ARG JAVA_HOME="C:\openjdk-17"
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
Expand Down
7 changes: 4 additions & 3 deletions windows/windowsservercore/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
# THE SOFTWARE.

ARG JAVA_VERSION=17.0.7_7
ARG WINDOWS_VERSION_TAG=1809
FROM eclipse-temurin:"${JAVA_VERSION}"-jdk-windowsservercore-"${WINDOWS_VERSION_TAG}" AS jdk-core
ARG WINDOWS_VERSION_TAG=ltsc2019
ARG TOOLS_WINDOWS_VERSION=1809
FROM eclipse-temurin:"${JAVA_VERSION}"-jdk-windowsservercore-"${TOOLS_WINDOWS_VERSION}" AS jdk-core

FROM mcr.microsoft.com/powershell:windowsservercore-"${WINDOWS_VERSION_TAG}"
FROM mcr.microsoft.com/windows/servercore:"${WINDOWS_VERSION_TAG}"

ARG JAVA_HOME="C:\openjdk-17"
ENV JAVA_HOME=${JAVA_HOME}
Expand Down