From e32bb3ba7364f51704268d5ce6f91023e610e974 Mon Sep 17 00:00:00 2001 From: Alex Earl Date: Fri, 10 Apr 2020 12:42:58 -0700 Subject: [PATCH] Windows updates and cleanup - Cleanup MAINTAINER usage which is deprecated - Fix JAVA_HOME for nanoserver - Use 1809 for Windows OS version - Update Windows tests similar to jnlp and ssh agents - Change Windows tags to have jdk version at front when specified --- 11/buster/Dockerfile | 1 - 11/stretch/Dockerfile | 1 - 11/windows/nanoserver-1809/Dockerfile | 20 ++--- 11/windows/windowsservercore-1809/Dockerfile | 5 +- 8/alpine/Dockerfile | 1 - 8/stretch/Dockerfile | 1 - 8/windows/nanoserver-1809/Dockerfile | 18 ++-- 8/windows/windowsservercore-1809/Dockerfile | 5 +- make.ps1 | 86 +++++++++++--------- tests/agent.Tests.ps1 | 53 ++++++------ 10 files changed, 89 insertions(+), 102 deletions(-) diff --git a/11/buster/Dockerfile b/11/buster/Dockerfile index c9f7cf66b..24c32d28c 100644 --- a/11/buster/Dockerfile +++ b/11/buster/Dockerfile @@ -21,7 +21,6 @@ # THE SOFTWARE. FROM openjdk:11-jdk-buster -MAINTAINER Oleg Nenashev ARG VERSION=4.3 ARG user=jenkins diff --git a/11/stretch/Dockerfile b/11/stretch/Dockerfile index 5c98c04c5..f89a58f87 100644 --- a/11/stretch/Dockerfile +++ b/11/stretch/Dockerfile @@ -21,7 +21,6 @@ # THE SOFTWARE. FROM openjdk:11-jdk-stretch -MAINTAINER Oleg Nenashev ARG VERSION=4.3 ARG user=jenkins diff --git a/11/windows/nanoserver-1809/Dockerfile b/11/windows/nanoserver-1809/Dockerfile index e12a3ae86..724fd6abd 100644 --- a/11/windows/nanoserver-1809/Dockerfile +++ b/11/windows/nanoserver-1809/Dockerfile @@ -22,27 +22,19 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -ARG WINDOWS_DOCKER_TAG=1809 -ARG JAVA_VERSION=11.0.6+10 -ARG JAVA_SHA256=6fb8b6c254ec0e1091acd421ac79c1bb07b295de0b679c0595fd284caf7734e5 -ARG JAVA_HOME=C:\jdk-${JAVA_VERSION} # If you pass in a POWERSHELL_VERSION, make sure it ends with a hyphen, leaving it empty will # use the 'latest' ARG POWERSHELL_VERSION= +FROM mcr.microsoft.com/powershell:${POWERSHELL_VERSION}nanoserver-1809 -FROM mcr.microsoft.com/powershell:${POWERSHELL_VERSION}nanoserver-$WINDOWS_DOCKER_TAG -MAINTAINER Alex Earl - -ARG JAVA_VERSION -ARG JAVA_SHA256 -ARG JAVA_HOME +ARG JAVA_VERSION=11.0.6+10 +ARG JAVA_SHA256=6fb8b6c254ec0e1091acd421ac79c1bb07b295de0b679c0595fd284caf7734e5 +ARG JAVA_HOME=C:\jdk-${JAVA_VERSION} SHELL ["pwsh.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] USER ContainerAdministrator -# https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_windows_hotspot_11.0.6_10.zip - RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` $javaRoot = 'OpenJDK11U-jdk_x64_windows_hotspot_{0}' -f $env:JAVA_VERSION.Replace('+', '_') ; ` $url = 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-{0}/{1}.zip' -f [System.Uri]::EscapeDataString($env:JAVA_VERSION), $javaRoot ; ` @@ -52,9 +44,7 @@ RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tl Expand-Archive openjdk.zip -DestinationPath C:/ ; ` Remove-Item -Path openjdk.zip -ARG JAVA_HOME - -ARG VERSION=4.0.1 +ARG VERSION=4.3 LABEL Description="This is a base image, which provides the Jenkins agent executable (agent.jar)" Vendor="Jenkins project" Version="${VERSION}" ARG GIT_VERSION=2.26.0 diff --git a/11/windows/windowsservercore-1809/Dockerfile b/11/windows/windowsservercore-1809/Dockerfile index c7a97c0b5..76ff1d5d8 100644 --- a/11/windows/windowsservercore-1809/Dockerfile +++ b/11/windows/windowsservercore-1809/Dockerfile @@ -22,10 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -ARG WINDOWS_DOCKER_TAG=1809 - -FROM adoptopenjdk:11-jdk-hotspot-windowsservercore-$WINDOWS_DOCKER_TAG -MAINTAINER Alex Earl +FROM adoptopenjdk:11-jdk-hotspot-windowsservercore-1809 SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] diff --git a/8/alpine/Dockerfile b/8/alpine/Dockerfile index 1caaf8eb2..35e4b8217 100644 --- a/8/alpine/Dockerfile +++ b/8/alpine/Dockerfile @@ -21,7 +21,6 @@ # THE SOFTWARE. FROM openjdk:8-jdk-alpine3.9 -MAINTAINER Oleg Nenashev ARG VERSION=4.3 ARG user=jenkins diff --git a/8/stretch/Dockerfile b/8/stretch/Dockerfile index eb4ed255f..d9e1963e6 100644 --- a/8/stretch/Dockerfile +++ b/8/stretch/Dockerfile @@ -21,7 +21,6 @@ # THE SOFTWARE. FROM openjdk:8-jdk-stretch -MAINTAINER Oleg Nenashev ARG VERSION=4.3 ARG user=jenkins diff --git a/8/windows/nanoserver-1809/Dockerfile b/8/windows/nanoserver-1809/Dockerfile index d2530f7e9..9cdaf336c 100644 --- a/8/windows/nanoserver-1809/Dockerfile +++ b/8/windows/nanoserver-1809/Dockerfile @@ -22,20 +22,14 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -ARG WINDOWS_DOCKER_TAG=1809 -ARG JAVA_VERSION=8u242-b08 -ARG JAVA_SHA256=8288e4d0983019706db89c153d18bfce28d033f646be65c8ae1c33c6c65b943e -ARG JAVA_HOME=C:\jdk${JAVA_VERSION} # If you pass in a POWERSHELL_VERSION, make sure it ends with a hyphen, leaving it empty will # use the 'latest' ARG POWERSHELL_VERSION= +FROM mcr.microsoft.com/powershell:${POWERSHELL_VERSION}nanoserver-1809 -FROM mcr.microsoft.com/powershell:${POWERSHELL_VERSION}nanoserver-$WINDOWS_DOCKER_TAG -MAINTAINER Alex Earl - -ARG JAVA_VERSION -ARG JAVA_SHA256 -ARG JAVA_HOME +ARG JAVA_VERSION=8u242-b08 +ARG JAVA_SHA256=8288e4d0983019706db89c153d18bfce28d033f646be65c8ae1c33c6c65b943e +ARG JAVA_HOME=C:\jdk${JAVA_VERSION} SHELL ["pwsh.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] @@ -50,9 +44,7 @@ RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tl Expand-Archive openjdk.zip -DestinationPath C:/ ; ` Remove-Item -Path openjdk.zip -ARG JAVA_HOME - -ARG VERSION=4.0.1 +ARG VERSION=4.3 LABEL Description="This is a base image, which provides the Jenkins agent executable (agent.jar)" Vendor="Jenkins project" Version="${VERSION}" ARG GIT_VERSION=2.26.0 diff --git a/8/windows/windowsservercore-1809/Dockerfile b/8/windows/windowsservercore-1809/Dockerfile index dee1fb1eb..364c2409a 100644 --- a/8/windows/windowsservercore-1809/Dockerfile +++ b/8/windows/windowsservercore-1809/Dockerfile @@ -22,10 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -ARG WINDOWS_DOCKER_TAG=1809 - -FROM adoptopenjdk:8-jdk-hotspot-windowsservercore-$WINDOWS_DOCKER_TAG -MAINTAINER Alex Earl +FROM adoptopenjdk:8-jdk-hotspot-windowsservercore-1809 SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] diff --git a/make.ps1 b/make.ps1 index fe6f41f75..197fc2a6f 100644 --- a/make.ps1 +++ b/make.ps1 @@ -6,7 +6,7 @@ Param( [String] $Build = '', [String] $RemotingVersion = '4.3', [String] $BuildNumber = "1", - [int] $WindowsTag = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId + [switch] $PushVersions = $false ) $Repository = 'agent' @@ -23,50 +23,54 @@ if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_ORGANISATION)) { $builds = @{ 'jdk8' = @{ 'Folder' = '8\windows\windowsservercore-1809'; - 'Tags' = @( "latest", "windowsservercore-$WindowsTag", "jdk8", "windowsservercore-$WindowsTag-jdk8" ) + 'Tags' = @( "latest", "windowsservercore-1809", "jdk8", "jdk8-windowsservercore-1809" ) }; 'jdk11' = @{ 'Folder' = '11\windows\windowsservercore-1809'; - 'Tags' = @( "windowsservercore-$WindowsTag-jdk11", "jdk11" ) + 'Tags' = @( "jdk11-windowsservercore-1809", "jdk11" ) }; 'nanoserver' = @{ 'Folder' = '8\windows\nanoserver-1809'; - 'Tags' = @( "nanoserver-$WindowsTag", "nanoserver-$WindowsTag-jdk8" ) + 'Tags' = @( "nanoserver-1809", "jdk8-nanoserver-1809" ) }; 'nanoserver-jdk11' = @{ 'Folder' = '11\windows\nanoserver-1809'; - 'Tags' = @( "nanoserver-$WindowsTag-jdk11" ) + 'Tags' = @( "jdk11-nanoserver-1809" ) }; } if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) { foreach($tag in $builds[$Build]['Tags']) { Write-Host "Building $Build => tag=$tag" - $cmd = "docker build --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$Build]['Folder'] + $cmd = "docker build --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$Build]['Folder'] Invoke-Expression $cmd - $buildTag = "$RemotingVersion-$BuildNumber-$tag" - if($tag -eq 'latest') { - $buildTag = "$RemotingVersion-$BuildNumber" + if($PushVersions) { + $buildTag = "$RemotingVersion-$BuildNumber-$tag" + if($tag -eq 'latest') { + $buildTag = "$RemotingVersion-$BuildNumber" + } + Write-Host "Building $Build => tag=$buildTag" + $cmd = "docker build --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$Build]['Folder'] + Invoke-Expression $cmd } - Write-Host "Building $Build => tag=$buildTag" - $cmd = "docker build --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$Build]['Folder'] - Invoke-Expression $cmd } } else { foreach($b in $builds.Keys) { foreach($tag in $builds[$b]['Tags']) { Write-Host "Building $b => tag=$tag" - $cmd = "docker build --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$b]['Folder'] + $cmd = "docker build --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$b]['Folder'] Invoke-Expression $cmd - $buildTag = "$RemotingVersion-$BuildNumber-$tag" - if($tag -eq 'latest') { - $buildTag = "$RemotingVersion-$BuildNumber" + if($PushVersions) { + $buildTag = "$RemotingVersion-$BuildNumber-$tag" + if($tag -eq 'latest') { + $buildTag = "$RemotingVersion-$BuildNumber" + } + Write-Host "Building $Build => tag=$buildTag" + $cmd = "docker build --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$b]['Folder'] + Invoke-Expression $cmd } - Write-Host "Building $Build => tag=$buildTag" - $cmd = "docker build --build-arg WINDOWS_DOCKER_TAG=$WindowsTag --build-arg VERSION='$RemotingVersion' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$b]['Folder'] - Invoke-Expression $cmd } } } @@ -76,25 +80,29 @@ if($lastExitCode -ne 0) { } if($target -eq "test") { - $mod = Get-InstalledModule -Name Pester -RequiredVersion 4.9.0 -ErrorAction SilentlyContinue + $mod = Get-InstalledModule -Name Pester -MinimumVersion 4.9.0 -ErrorAction SilentlyContinue if($null -eq $mod) { $module = "c:\Program Files\WindowsPowerShell\Modules\Pester" takeown /F $module /A /R icacls $module /reset icacls $module /grant Administrators:'F' /inheritance:d /T Remove-Item -Path $module -Recurse -Force -Confirm:$false - Install-Module -Force -Name Pester -RequiredVersion 4.9.0 + Install-Module -Force -Name Pester -MinimumVersion 4.9.0 } if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) { - $env:FLAVOR = $Build + $env:FOLDER = $builds[$Build]['Folder'] + $env:VERSION = "$RemotingVersion-$BuildNumber" Invoke-Pester -Path tests -EnableExit - Remove-Item env:\FLAVOR + Remove-Item env:\FOLDER + Remove-Item env:\VERSION } else { foreach($b in $builds.Keys) { - $env:FLAVOR = $b + $env:FOLDER = $builds[$b]['Folder'] + $env:VERSION = "$RemotingVersion-$BuildNumber" Invoke-Pester -Path tests -EnableExit - Remove-Item env:\FLAVOR + Remove-Item env:\FOLDER + Remove-Item env:\VERSION } } } @@ -106,13 +114,15 @@ if($target -eq "publish") { $cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $tag Invoke-Expression $cmd - $buildTag = "$RemotingVersion-$BuildNumber-$tag" - if($tag -eq 'latest') { - $buildTag = "$RemotingVersion-$BuildNumber" + if($PushVersions) { + $buildTag = "$RemotingVersion-$BuildNumber-$tag" + if($tag -eq 'latest') { + $buildTag = "$RemotingVersion-$BuildNumber" + } + Write-Host "Publishing $Build => tag=$buildTag" + $cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag + Invoke-Expression $cmd } - Write-Host "Publishing $Build => tag=$buildTag" - $cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag - Invoke-Expression $cmd } } else { foreach($b in $builds.Keys) { @@ -121,13 +131,15 @@ if($target -eq "publish") { $cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $tag Invoke-Expression $cmd - $buildTag = "$RemotingVersion-$BuildNumber-$tag" - if($tag -eq 'latest') { - $buildTag = "$RemotingVersion-$BuildNumber" + if($PushVersions) { + $buildTag = "$RemotingVersion-$BuildNumber-$tag" + if($tag -eq 'latest') { + $buildTag = "$RemotingVersion-$BuildNumber" + } + Write-Host "Publishing $Build => tag=$buildTag" + $cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag + Invoke-Expression $cmd } - Write-Host "Publishing $Build => tag=$buildTag" - $cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag - Invoke-Expression $cmd } } } diff --git a/tests/agent.Tests.ps1 b/tests/agent.Tests.ps1 index 19dd72cbd..bf11beaf0 100644 --- a/tests/agent.Tests.ps1 +++ b/tests/agent.Tests.ps1 @@ -1,31 +1,33 @@ Import-Module -DisableNameChecking -Force $PSScriptRoot/test_helpers.psm1 -$FOLDER='8\windows\servercore-1809' -$JDK=8 -$AGENT_IMAGE='jenkins-agent' -$AGENT_CONTAINER='pester-jenkins-agent' +$AGENT_IMAGE='jenkins-jnlp-agent' +$AGENT_CONTAINER='pester-jenkins-jnlp-agent' $SHELL="powershell.exe" -$FLAVOR = Get-EnvOrDefault 'FLAVOR' '' +$FOLDER = Get-EnvOrDefault 'FOLDER' '' +$VERSION = Get-EnvOrDefault 'VERSION' '4.3-1' -if([System.String]::IsNullOrWhiteSpace($FLAVOR)) { - $FLAVOR = 'jdk8' -} elseif($FLAVOR -eq "jdk11") { - $FOLDER = '11\windows\servercore-1809' - $JDK=11 +$REAL_FOLDER=Resolve-Path -Path "$PSScriptRoot/../${FOLDER}" + +if(($FOLDER -match '^(?[0-9]+)[\\/](?.+)$') -and (Test-Path $REAL_FOLDER)) { + $JDK = $Matches['jdk'] + $FLAVOR = $Matches['flavor'] +} else { + Write-Error "Wrong folder format or folder does not exist: $FOLDER" + exit 1 +} + +if($FLAVOR -match "nanoserver") { + $AGENT_IMAGE += "-nanoserver" + $AGENT_CONTAINER += "-nanoserver-1809" + $SHELL = "pwsh.exe" +} + +if($JDK -eq "11") { $AGENT_IMAGE += ":jdk11" $AGENT_CONTAINER += "-jdk11" -} elseif($FLAVOR -eq "nanoserver") { - $FOLDER = '8\windows\nanoserver-1809' - $AGENT_IMAGE += ":nanoserver-1809" - $AGENT_CONTAINER += "-nanoserver" - $SHELL="pwsh.exe" -} elseif($FLAVOR -eq "nanoserver-jdk11") { - $FOLDER = '11\windows\nanoserver-1809' - $JDK=11 - $AGENT_IMAGE += ":nanoserver-1809-jdk11" - $AGENT_CONTAINER += "-nanoserver-jdk11" - $SHELL="pwsh.exe" +} else { + $AGENT_IMAGE += ":latest" } Cleanup($AGENT_CONTAINER) @@ -48,6 +50,7 @@ Describe "[$JDK $FLAVOR] build image" { Describe "[$JDK $FLAVOR] correct image metadata" { It 'has correct volumes' { $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "inspect -f '{{.Config.Volumes}}' $AGENT_IMAGE" + $stdout = $stdout.Trim() $stdout | Should -Match 'C:/Users/jenkins/.jenkins' $stdout | Should -Match 'C:/Users/jenkins/Work' } @@ -80,7 +83,7 @@ Describe "[$JDK $FLAVOR] image has correct applications in the PATH" { It 'has AGENT_WORKDIR in the envrionment' { $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "exec $AGENT_CONTAINER $SHELL -C `"Get-ChildItem env:`"" $exitCode | Should -Be 0 - $stdout | Should -Match "AGENT_WORKDIR.*C:/Users/jenkins/Work" + $stdout.Trim() | Should -Match "AGENT_WORKDIR.*C:/Users/jenkins/Work" } AfterAll { @@ -114,7 +117,7 @@ Describe "[$JDK $FLAVOR] check user access to directories" { } } -$TEST_VERSION="3.36" +$TEST_VERSION="4.0" $TEST_USER="test-user" $TEST_AGENT_WORKDIR="C:/test-user/something" @@ -132,13 +135,13 @@ Describe "[$JDK $FLAVOR] use build args correctly" { It 'has the correct version of remoting' { $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "exec $AGENT_CONTAINER $SHELL -C `"`$version = java -cp C:/ProgramData/Jenkins/agent.jar hudson.remoting.jnlp.Main -version ; Write-Host `$version`"" $exitCode | Should -Be 0 - $stdout | Should -Match $TEST_VERSION + $stdout.Trim() | Should -Match $TEST_VERSION } It 'has correct user' { $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "exec $AGENT_CONTAINER $SHELL -C `"(Get-ChildItem env:\ | Where-Object { `$_.Name -eq 'USERNAME' }).Value`"" $exitCode | Should -Be 0 - $stdout | Should -Match $TEST_USER + $stdout.Trim() | Should -Match $TEST_USER } It 'has correct AGENT_WORKDIR' {