Skip to content

Commit c5db033

Browse files
committed
cleanup for review
1 parent f479f35 commit c5db033

File tree

8 files changed

+43
-235
lines changed

8 files changed

+43
-235
lines changed

Jenkinsfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ final String cronExpr = env.BRANCH_IS_PRIMARY ? '@daily' : ''
22

33
properties([
44
buildDiscarder(logRotator(numToKeepStr: '10')),
5-
// disableConcurrentBuilds(abortPrevious: true),
5+
disableConcurrentBuilds(abortPrevious: true),
66
pipelineTriggers([cron(cronExpr)]),
77
])
88

@@ -52,7 +52,7 @@ def parallelStages = [failFast: false]
5252
'windowsservercore-ltsc2022'
5353
].each { imageType ->
5454
parallelStages[imageType] = {
55-
withEnv(["IMAGE_TYPE=${imageType}", "REGISTRY_ORG=${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}", "TESTS_MODE=not-sequential"]) {
55+
withEnv(["IMAGE_TYPE=${imageType}", "REGISTRY_ORG=${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}"]) {
5656
int retryCounter = 0
5757
retry(count: 2, conditions: [agent(), nonresumable()]) {
5858
// Use local variable to manage concurrency and increment BEFORE spinning up any agent
@@ -98,14 +98,14 @@ def parallelStages = [failFast: false]
9898
sh './build.sh test'
9999
} else {
100100
powershell '& ./build.ps1 test'
101-
// TODO: always archive even on failure
102101
archiveArtifacts artifacts: 'build-windows_*.yaml', allowEmptyArchive: true
103102
}
104103
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results*.xml')
105104
}
106105
// If the tests are passing for Linux AMD64, then we can build all the CPU architectures
107106
if (isUnix()) {
108107
stage('Multi-Arch Build') {
108+
109109
sh 'make every-build'
110110
}
111111
}

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ test-%: prepare-test
9898
set -x
9999
# Each type of image ("agent" or "inbound-agent") has its own tests suite
100100
ifeq ($(CI), true)
101+
# Execute the test harness and write result to a TAP file
101102
IMAGE=$* bats/bin/bats $(CURDIR)/tests/tests_$(shell echo $* | cut -d "_" -f 1).bats $(bats_flags) --formatter junit | tee target/junit-results-$*.xml
102103
else
103104
IMAGE=$* bats/bin/bats $(CURDIR)/tests/tests_$(shell echo $* | cut -d "_" -f 1).bats $(bats_flags)

build.ps1

Lines changed: 36 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Param(
2121

2222
$ErrorActionPreference = 'Stop'
2323
$ProgressPreference = 'SilentlyContinue' # Disable Progress bar for faster downloads
24-
$LogCommandLifecycleEvent = $true
2524

2625
if (![String]::IsNullOrWhiteSpace($env:TESTS_DEBUG)) {
2726
$TestsDebug = $env:TESTS_DEBUG
@@ -32,8 +31,7 @@ if (![String]::IsNullOrWhiteSpace($env:AGENT_TYPE)) {
3231
$AgentType = $env:AGENT_TYPE
3332
}
3433

35-
# $AgentTypes = @('agent', 'inbound-agent')
36-
$AgentTypes = @('inbound-agent')
34+
$AgentTypes = @('agent', 'inbound-agent')
3735
if ($AgentType -ne '' -and $AgentType -in $AgentTypes) {
3836
$AgentTypes = @($AgentType)
3937
}
@@ -175,119 +173,12 @@ Test-CommandExists 'docker-compose'
175173
Test-CommandExists 'docker buildx'
176174
Test-CommandExists 'yq'
177175

178-
# Doc: https://github.com/moby/buildkit/blob/master/docs/windows.md & https://docs.docker.com/build/buildkit/#buildkit-on-windows
179-
function Buildkit-Setup {
180-
param (
181-
[Boolean] $InstallContainerd = $false,
182-
[Boolean] $InstallBuildkitd = $false
183-
)
184-
185-
# Ensure Hyper-V and Containers Windows features are enabled
186-
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V, Containers -All
187-
188-
# https://github.com/containerd/containerd/blob/main/docs/getting-started.md#installing-containerd-on-windows
189-
if ($InstallContainerd) {
190-
# If containerd previously installed run:
191-
Stop-Service containerd
192-
193-
# Download and extract desired containerd Windows binaries
194-
$Version="1.7.13" # update to your preferred version
195-
$Arch = "amd64" # arm64 also available
196-
curl.exe -LO https://github.com/containerd/containerd/releases/download/v$Version/containerd-$Version-windows-$Arch.tar.gz
197-
tar.exe xvf .\containerd-$Version-windows-$Arch.tar.gz
198-
199-
# Copy
200-
Copy-Item -Path .\bin -Destination $Env:ProgramFiles\containerd -Recurse -Force
201-
202-
# add the binaries (containerd.exe, ctr.exe) in $env:Path
203-
$Path = [Environment]::GetEnvironmentVariable("PATH", "Machine") + [IO.Path]::PathSeparator + "$Env:ProgramFiles\containerd"
204-
[Environment]::SetEnvironmentVariable( "Path", $Path, "Machine")
205-
# reload path, so you don't have to open a new PS terminal later if needed
206-
$Env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
207-
208-
# configure
209-
containerd.exe config default | Out-File $Env:ProgramFiles\containerd\config.toml -Encoding ascii
210-
# Review the configuration. Depending on setup you may want to adjust:
211-
# - the sandbox_image (Kubernetes pause image)
212-
# - cni bin_dir and conf_dir locations
213-
Get-Content $Env:ProgramFiles\containerd\config.toml
214-
215-
# Register and start service
216-
containerd.exe --register-service
217-
Start-Service containerd
218-
}
219-
220-
if ($InstallBuildkitd) {
221-
## Download and extract
222-
$url = "https://api.github.com/repos/moby/buildkit/releases/latest"
223-
$version = (Invoke-RestMethod -Uri $url -UseBasicParsing).tag_name
224-
$arch = "amd64" # arm64 binary available too
225-
curl.exe -fSLO https://github.com/moby/buildkit/releases/download/$version/buildkit-$version.windows-$arch.tar.gz
226-
# there could be another `.\bin` directory from containerd instructions
227-
# you can move those
228-
mv bin bin2
229-
tar.exe xvf .\buildkit-$version.windows-$arch.tar.gz
230-
## x bin/
231-
## x bin/buildctl.exe
232-
## x bin/buildkitd.exe
233-
234-
## Setup buildkitd binaries
235-
# after the binaries are extracted in the bin directory
236-
# move them to an appropriate path in your $Env:PATH directories or:
237-
Copy-Item -Path ".\bin" -Destination "$Env:ProgramFiles\buildkit" -Recurse -Force
238-
# add `buildkitd.exe` and `buildctl.exe` binaries in the $Env:PATH
239-
$Path = [Environment]::GetEnvironmentVariable("PATH", "Machine") + `
240-
[IO.Path]::PathSeparator + "$Env:ProgramFiles\buildkit"
241-
[Environment]::SetEnvironmentVariable( "Path", $Path, "Machine")
242-
$Env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + `
243-
[System.Environment]::GetEnvironmentVariable("Path","User")
244-
}
245-
}
246-
try {
247-
Test-CommandExists 'ctr'
248-
} catch {
249-
Write-Host 'containerd not found'
250-
}
251-
try {
252-
Test-CommandExists 'buildkitd'
253-
} catch {
254-
Write-Host 'buildkitd not found'
255-
}
256-
# try {
257-
# Buildkit-Setup -InstallContainerd $false -InstallBuildkitd $false
258-
# } catch {}
259-
260-
# Sanity checks
261-
Invoke-Expression 'docker info'
262-
Write-Host 'Checking for Microsoft-Hyper-V feature...'
263-
Get-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Hyper-V'
264-
265-
# Docker warmup (TODO: proper improvement incoming to pull only the base images from docker bake/compose file)
266-
Write-Host '= PREPARE: Docker warmup (pull base images)'
267-
$warmupImages = @(
268-
'mcr.microsoft.com/windows/servercore:ltsc2019',
269-
'mcr.microsoft.com/powershell:nanoserver-1809',
270-
'mcr.microsoft.com/windows/nanoserver:ltsc2019'
271-
)
272-
273-
$warmupJobs = @()
274-
foreach ($image in $warmupImages) {
275-
$warmupJobs += Start-Job -ScriptBlock {
276-
param($img)
277-
Write-Host "== PREPARE: pulling $img"
278-
Invoke-Expression "docker pull $img"
279-
} -ArgumentList $image
280-
}
281-
# Wait for all pulls to finish
282-
$warmupJobs | ForEach-Object { Receive-Job -Job $_ -Wait; Remove-Job $_ }
283-
Invoke-Expression 'docker images ls --tree'
284-
285176
$testImageFunction = ${function:Test-Image}
286177
$workspacePath = (Get-Location).Path
287178
foreach($agentType in $AgentTypes) {
288179
$dockerComposeFile = 'build-windows_{0}_{1}.yaml' -f $AgentType, $ImageType
289180
$baseDockerCmd = 'docker-compose --file={0}' -f $dockerComposeFile
290-
$baseDockerBuildCmd = '{0} build --parallel' -f $baseDockerCmd
181+
$baseDockerBuildCmd = '{0} build --parallel --pull' -f $baseDockerCmd
291182

292183
# Generate the docker compose file if it doesn't exists or if the parameter OverwriteDockerComposeFile is set
293184
if ((Test-Path $dockerComposeFile) -and -not $OverwriteDockerComposeFile) {
@@ -333,63 +224,42 @@ foreach($agentType in $AgentTypes) {
333224
Write-Host "= TEST: Testing all ${agentType} images..."
334225
$jdks = Invoke-Expression "$baseDockerCmd config" | yq --unwrapScalar --output-format json '.services' | ConvertFrom-Json
335226

336-
$testMode = $env:TESTS_MODE
337-
338-
if ($testMode -eq 'sequential') {
339-
Write-Host "== TEST: Setting up Pester environment for $anImage testing..."
340-
Import-Module Pester
341-
$configuration = [PesterConfiguration]::Default
342-
$configuration.Run.PassThru = $true
343-
$configuration.Run.Path = '{0}\tests' -f $workspacePath
344-
$configuration.Run.Exit = $true
345-
$configuration.TestResult.Enabled = $true
346-
$configuration.TestResult.OutputFormat = 'JUnitXml'
347-
$configuration.Output.Verbosity = 'Diagnostic'
348-
$configuration.CodeCoverage.Enabled = $false
349-
350-
# Run Test-Image sequentially for each JDK
351-
Write-Host "= TEST: Starting ${image} tests sequentially..."
352-
foreach ($jdk in $jdks.PSObject.Properties) {
353-
$testFailed = $testFailed -or (Test-Image -AgentType $agentType -RemotingVersion $RemotingVersion -ImageName $jdk.Value.image -JavaVersion $jdk.Value.build.args.JAVA_VERSION)
354-
}
355-
} else {
356-
# Run Test-Image in parallel for each JDK
357-
$jobs = @()
358-
foreach ($jdk in $jdks.PSObject.Properties) {
359-
$image = $jdk.Value.image
360-
$javaVersion = $jdk.Value.build.args.JAVA_VERSION
361-
Write-Host "= TEST: Starting ${image} tests in parallel..."
362-
$jobs += Start-Job -ScriptBlock {
363-
param($anAgentType, $aRemotingVersion, $anImage, $aJavaVersion, $aTestImageFunction, $aWorkspacePath)
364-
365-
Write-Host "== TEST: Setting up Pester environment for $anImage testing..."
366-
Import-Module Pester
367-
$configuration = [PesterConfiguration]::Default
368-
$configuration.Run.PassThru = $true
369-
$configuration.Run.Path = '{0}\tests' -f $aWorkspacePath
370-
$configuration.Run.Exit = $true
371-
$configuration.TestResult.Enabled = $true
372-
$configuration.TestResult.OutputFormat = 'JUnitXml'
373-
$configuration.Output.Verbosity = 'Diagnostic'
374-
$configuration.CodeCoverage.Enabled = $false
375-
Set-Item -Path Function:Test-Image -Value $aTestImageFunction
376-
Set-Location -Path $aWorkspacePath
377-
378-
Test-Image -AgentType $anAgentType -RemotingVersion $aRemotingVersion -ImageName $anImage -JavaVersion $aJavaVersion
379-
} -ArgumentList $agentType, $RemotingVersion, $image, $javaVersion, $testImageFunction, $workspacePath
380-
}
227+
# Run Test-Image in parallel for each JDK
228+
$jobs = @()
229+
foreach ($jdk in $jdks.PSObject.Properties) {
230+
$image = $jdk.Value.image
231+
$javaVersion = $jdk.Value.build.args.JAVA_VERSION
232+
Write-Host "= TEST: Starting ${image} tests in parallel..."
233+
$jobs += Start-Job -ScriptBlock {
234+
param($anAgentType, $aRemotingVersion, $anImage, $aJavaVersion, $aTestImageFunction, $aWorkspacePath)
235+
236+
Write-Host "== TEST: Setting up Pester environment for $anImage testing..."
237+
Import-Module Pester
238+
$configuration = [PesterConfiguration]::Default
239+
$configuration.Run.PassThru = $true
240+
$configuration.Run.Path = '{0}\tests' -f $aWorkspacePath
241+
$configuration.Run.Exit = $true
242+
$configuration.TestResult.Enabled = $true
243+
$configuration.TestResult.OutputFormat = 'JUnitXml'
244+
$configuration.Output.Verbosity = 'Diagnostic'
245+
$configuration.CodeCoverage.Enabled = $false
246+
Set-Item -Path Function:Test-Image -Value $aTestImageFunction
247+
Set-Location -Path $aWorkspacePath
248+
249+
Test-Image -AgentType $anAgentType -RemotingVersion $aRemotingVersion -ImageName $anImage -JavaVersion $aJavaVersion
250+
} -ArgumentList $agentType, $RemotingVersion, $image, $javaVersion, $testImageFunction, $workspacePath
251+
}
381252

382-
# Wait for all jobs to finish and collect results
383-
$testFailed = $false
384-
foreach ($job in $jobs) {
385-
$result = Receive-Job -Job $job -Wait
386-
if ($result.Failed) {
387-
Write-Host "= TEST: Error(s), see the results below"
388-
$result.Tests | ConvertTo-Json | Write-Host
389-
$testFailed = $true
390-
}
391-
Remove-Job $job
253+
# Wait for all jobs to finish and collect results
254+
$testFailed = $false
255+
foreach ($job in $jobs) {
256+
$result = Receive-Job -Job $job -Wait
257+
if ($result.Failed) {
258+
Write-Host "= TEST: Error(s), see the results below"
259+
$result.Tests | ConvertTo-Json | Write-Host
260+
$testFailed = $true
392261
}
262+
Remove-Job $job
393263
}
394264

395265
# Fail if any test failures

debian/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ RUN apt-get update \
9595
&& apt-get clean \
9696
&& rm -rf /tmp/* /var/cache/* /var/lib/apt/lists/*
9797

98-
# TODO: put remoting retrieval in a lower layer to allow better caching (ex in tests)
9998
ARG VERSION=3345.v03dee9b_f88fc
100-
# TODO: retrieve from get.jenkins.io?
10199
ADD --chown="${user}":"${group}" "https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/${VERSION}/remoting-${VERSION}.jar" /usr/share/jenkins/agent.jar
102100
RUN chmod 0644 /usr/share/jenkins/agent.jar \
103101
&& ln -sf /usr/share/jenkins/agent.jar /usr/share/jenkins/slave.jar

docker-bake.hcl

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -274,54 +274,6 @@ function "windows_tags" {
274274
]
275275
}
276276

277-
# # From https://docs.docker.com/guides/bake/#exporting-build-artifacts
278-
# target "bin" {
279-
# target = "bin"
280-
# output = ["build/bin"]
281-
# platforms = ["local"]
282-
# }
283-
284-
# # FROM scratch AS bin
285-
# # COPY --from=build "/usr/bin/bakeme" /
286-
287-
# target "bin-cross" {
288-
# inherits = ["bin"]
289-
# platforms = [
290-
# "linux/amd64",
291-
# "linux/arm64",
292-
# "linux/riscv64",
293-
# ]
294-
# }
295-
296-
# target "bin-all" {
297-
# inherits = ["bin-cross"]
298-
# matrix = {
299-
# mode = ["release", "debug"]
300-
# }
301-
# name = "bin-${mode}"
302-
# args = {
303-
# BUILD_TAGS = mode
304-
# }
305-
# output = ["build/bin/${mode}"]
306-
# }
307-
308-
target "_common" {
309-
context = "."
310-
args = {
311-
VERSION = REMOTING_VERSION
312-
}
313-
annotations = [
314-
"org.opencontainers.image.vendor=Jenkins project",
315-
"org.opencontainers.image.url=https://www.jenkins.io/",
316-
"org.opencontainers.image.source=https://github.com/jenkinsci/docker-agent",
317-
"org.opencontainers.image.licenses=MIT"
318-
]
319-
attest = [
320-
"type=provenance,mode=max",
321-
"type=sbom"
322-
]
323-
}
324-
325277
target "alpine" {
326278
matrix = {
327279
type = agent_types_to_build

tests/inbound-agent.Tests.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ $global:CONTAINERNAME = 'pester-jenkins-inbound-agent_{0}_{1}' -f $global:IMAGE_
2020
$global:JNLPNETWORKNAME = 'jnlp-{0}' -f $random
2121
$global:NMAPCONTAINERNAME = 'nmap-{0}' -f $random
2222
Write-Host "= TESTS: container name $global:CONTAINERNAME"
23-
Write-Host "= TESTS: jnlp network name $global:JNLPNETWORKNAME"
24-
Write-Host "= TESTS: nmap container name $global:NMAPCONTAINERNAME"
25-
2623

2724
$global:CONTAINERSHELL = 'powershell.exe'
2825
if ($global:WINDOWSFLAVOR -eq 'nanoserver') {
@@ -39,7 +36,7 @@ Cleanup($global:CONTAINERNAME)
3936
Cleanup($global:NMAPCONTAINERNAME)
4037
CleanupNetwork($global:JNLPNETWORKNAME)
4138

42-
BuildNmapImage($global:WINDOWSVERSIONTAG)
39+
BuildNcatImage($global:WINDOWSVERSIONTAG)
4340

4441
Describe "[$global:IMAGE_NAME] build image" {
4542
It 'builds image' {

tests/test_helpers.psm1

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ function Run-Program($cmd, $params) {
112112
$stdout = $proc.StandardOutput.ReadToEnd()
113113
$stderr = $proc.StandardError.ReadToEnd()
114114
$proc.WaitForExit()
115-
# TODO: use https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.5#debugpreference
116-
# $DebugPreference = "Continue"
117-
# Write-Debug -Message "Hello, World"
118-
# use also https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.5#informationpreference
119-
# or https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.5#verbosepreference
120115
if (($env:TESTS_DEBUG -eq 'debug') -or ($env:TESTS_DEBUG -eq 'verbose')) {
121116
Write-Host -ForegroundColor DarkBlue "[cmd] $cmd $params"
122117
if ($env:TESTS_DEBUG -eq 'verbose') {
@@ -130,11 +125,10 @@ function Run-Program($cmd, $params) {
130125
return $proc.ExitCode, $stdout, $stderr
131126
}
132127

133-
function BuildNmapImage($windowsVersionTag) {
134-
Write-Host "Inspecting nmap image..."
128+
function BuildNcatImage($windowsVersionTag) {
129+
Write-Host "Building nmap image (Windows version '${windowsVersionTag}') for testing"
135130
$exitCode, $stdout, $stderr = Run-Program 'docker.exe' "inspect --type=image nmap" $true
136131
if ($exitCode -ne 0) {
137-
Write-Host "Building nmap image (Windows version '${windowsVersionTag}') for testing"
138132
Push-Location -StackName 'agent' -Path "$PSScriptRoot/.."
139133
$exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build -t nmap --build-arg `"WINDOWS_VERSION_TAG=${windowsVersionTag}`" -f ./tests/netcat-helper/Dockerfile-windows ./tests/netcat-helper"
140134
$exitCode | Should -Be 0

windows/nanoserver/Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ FROM agent AS inbound-agent
133133

134134
COPY jenkins-agent.ps1 C:/ProgramData/Jenkins
135135

136-
# TODO: remove
137-
RUN Write-Host "env:JAVA_HOME = $env:JAVA_HOME" ; `
138-
java -version
139-
140136
LABEL `
141137
org.opencontainers.image.vendor="Jenkins project" `
142138
org.opencontainers.image.title="Official Jenkins Inbound Agent Base Docker image" `

0 commit comments

Comments
 (0)