Skip to content

Commit

Permalink
Merge pull request #118 from slide/windows_updates_and_cleanup
Browse files Browse the repository at this point in the history
Windows updates and cleanup
  • Loading branch information
slide authored Apr 10, 2020
2 parents 1e38db1 + e32bb3b commit d1bc33e
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 102 deletions.
1 change: 0 additions & 1 deletion 11/buster/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

FROM openjdk:11-jdk-buster
MAINTAINER Oleg Nenashev <o.v.nenashev@gmail.com>

ARG VERSION=4.3
ARG user=jenkins
Expand Down
1 change: 0 additions & 1 deletion 11/stretch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

FROM openjdk:11-jdk-stretch
MAINTAINER Oleg Nenashev <o.v.nenashev@gmail.com>

ARG VERSION=4.3
ARG user=jenkins
Expand Down
20 changes: 5 additions & 15 deletions 11/windows/nanoserver-1809/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <slide.o.mix@gmail.com>

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 ; `
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions 11/windows/windowsservercore-1809/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <slide.o.mix@gmail.com>
FROM adoptopenjdk:11-jdk-hotspot-windowsservercore-1809

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

Expand Down
1 change: 0 additions & 1 deletion 8/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

FROM openjdk:8-jdk-alpine3.9
MAINTAINER Oleg Nenashev <o.v.nenashev@gmail.com>

ARG VERSION=4.3
ARG user=jenkins
Expand Down
1 change: 0 additions & 1 deletion 8/stretch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

FROM openjdk:8-jdk-stretch
MAINTAINER Oleg Nenashev <o.v.nenashev@gmail.com>

ARG VERSION=4.3
ARG user=jenkins
Expand Down
18 changes: 5 additions & 13 deletions 8/windows/nanoserver-1809/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <slide.o.mix@gmail.com>

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';"]

Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions 8/windows/windowsservercore-1809/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <slide.o.mix@gmail.com>
FROM adoptopenjdk:8-jdk-hotspot-windowsservercore-1809

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

Expand Down
86 changes: 49 additions & 37 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand All @@ -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) {
Expand All @@ -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
}
}
}
Expand Down
53 changes: 28 additions & 25 deletions tests/agent.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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 '^(?<jdk>[0-9]+)[\\/](?<flavor>.+)$') -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)
Expand All @@ -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'
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"

Expand All @@ -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' {
Expand Down

0 comments on commit d1bc33e

Please sign in to comment.