Skip to content

Commit

Permalink
[PATCH] Merge pull request jenkinsci/docker-inbound-agent#363 from le…
Browse files Browse the repository at this point in the history
…meurherve/refactor-windows-builds-like-docker-agent

refactor: build `docker-inbound-agent` like `docker-agent`
  • Loading branch information
lemeurherve committed Nov 28, 2023
1 parent 9432ae3 commit 243cc5a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions tests/inboundAgent.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
Import-Module -DisableNameChecking -Force $PSScriptRoot/test_helpers.psm1

$global:AGENT_IMAGE = Get-EnvOrDefault 'AGENT_IMAGE' ''
$global:FOLDER = Get-EnvOrDefault 'FOLDER' ''
$global:JAVA_MAJOR_VERSION = Get-EnvOrDefault 'JAVA_MAJOR_VERSION' ''
$global:VERSION = Get-EnvOrDefault 'VERSION' ''
$global:BUILD_CONTEXT = Get-EnvOrDefault 'BUILD_CONTEXT' ''
$global:version = Get-EnvOrDefault 'VERSION' ''
$global:WINDOWS_VERSION_TAG = Get-EnvOrDefault 'WINDOWS_VERSION_TAG' ''

# TODO: make this name unique for concurency
$global:CONTAINERNAME = 'pester-jenkins-inbound-agent-{0}' -f $global:AGENT_IMAGE

$REAL_FOLDER=Resolve-Path -Path "$PSScriptRoot/../${global:FOLDER}"

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

# Remove the 'jdk' prefix (3 first characters)
$global:JDKMAJORVERSION = $items[0].Remove(0,3)
$global:JAVA_MAJOR_VERSION = $items[0].Remove(0,3)
$global:WINDOWSFLAVOR = $items[1]
$global:WINDOWSVERSION = $items[2]

$global:CONTAINERSHELL="powershell.exe"
if($global:WINDOWSFLAVOR -eq 'nanoserver') {
$global:CONTAINERSHELL = "pwsh.exe"
# Special case for nanoserver-1809
if($global:WINDOWSVERSION -eq '1809') {
$global:WINDOWS_VERSION_TAG = '1809'
}
}


Cleanup($global:CONTAINERNAME)
Cleanup("nmap")
CleanupNetwork("jnlp-network")

BuildNcatImage
BuildNcatImage($global:WINDOWS_VERSION_TAG)

Describe "[$global:AGENT_IMAGE] build image" {
It 'builds image' {
$exitCode, $stdout, $stderr = Run-Program 'docker' "build --build-arg version=${global:VERSION} --build-arg JAVA_MAJOR_VERSION=${global:JAVA_MAJOR_VERSION} --tag=${global:AGENT_IMAGE} --file $global:FOLDER/Dockerfile ./"
$exitCode, $stdout, $stderr = Run-Program 'docker' "build --build-arg version=${global:version} --build-arg `"WINDOWS_VERSION_TAG=${global:WINDOWS_VERSION_TAG}`" --build-arg JAVA_MAJOR_VERSION=${global:JAVA_MAJOR_VERSION} --tag=${global:AGENT_IMAGE} --file ./windows/${global:WINDOWSFLAVOR}/Dockerfile ${global:BUILD_CONTEXT}"
$exitCode | Should -Be 0
}
}
Expand Down Expand Up @@ -114,15 +116,15 @@ Describe "[$global:AGENT_IMAGE] custom build args" {
BeforeAll {
Push-Location -StackName 'agent' -Path "$PSScriptRoot/.."
# Old version used to test overriding the build arguments.
# This old version must have the same tag suffixes as the current 4 windows images (`-jdk11-nanoserver` etc.)
$TEST_VERSION = "3046.v38db_38a_b_7a_86"
$DOCKER_AGENT_VERSION_SUFFIX = "1"
$ARG_TEST_VERSION = "${TEST_VERSION}-${DOCKER_AGENT_VERSION_SUFFIX}"
# This old version must have the same tag suffixes as the current windows images (`-jdk11-nanoserver` etc.), and the same Windows version (2019, 2022, etc.)
$TEST_VERSION = "3131.vf2b_b_798b_ce99"
$PARENT_IMAGE_VERSION_SUFFIX = "4"
$ARG_TEST_VERSION = "${TEST_VERSION}-${PARENT_IMAGE_VERSION_SUFFIX}"
$customImageName = "custom-${global:AGENT_IMAGE}"
}

It 'builds image with arguments' {
$exitCode, $stdout, $stderr = Run-Program 'docker' "build --build-arg version=${ARG_TEST_VERSION} --build-arg JAVA_MAJOR_VERSION=${global:JAVA_MAJOR_VERSION} --tag=${customImageName} --file=${global:FOLDER}/Dockerfile ./"
$exitCode, $stdout, $stderr = Run-Program 'docker' "build --build-arg version=${ARG_TEST_VERSION} --build-arg `"WINDOWS_VERSION_TAG=${global:WINDOWS_VERSION_TAG}`" --build-arg JAVA_MAJOR_VERSION=${global:JAVA_MAJOR_VERSION} --tag=${customImageName} --file=./windows/${global:WINDOWSFLAVOR}/Dockerfile ${global:BUILD_CONTEXT}"
$exitCode | Should -Be 0

$exitCode, $stdout, $stderr = Run-Program 'docker' "run --detach --tty --name $global:CONTAINERNAME $customImageName -Cmd $global:CONTAINERSHELL"
Expand Down Expand Up @@ -165,7 +167,7 @@ Describe "[$global:AGENT_IMAGE] passing JVM options (slow test)" {
Is-ContainerRunning $global:CONTAINERNAME | Should -BeTrue
$exitCode, $stdout, $stderr = Run-Program 'docker' "logs $global:CONTAINERNAME"
$exitCode | Should -Be 0
$stdout | Should -Match "OpenJDK Runtime Environment Temurin-${global:JDKMAJORVERSION}"
$stdout | Should -Match "OpenJDK Runtime Environment Temurin-${global:JAVA_MAJOR_VERSION}"
}

AfterAll {
Expand Down

0 comments on commit 243cc5a

Please sign in to comment.