Skip to content

Commit

Permalink
chore(windows) factorize JDK specification to powershell build script
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Duportal <[email protected]>
  • Loading branch information
dduportal committed May 21, 2023
1 parent 597b29c commit a255365
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 144 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ updates:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: docker
directory: "/11/windows/nanoserver-ltsc2019"
directory: "/windows/nanoserver-ltsc2019"
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: docker
directory: "/11/windows/windowsservercore-ltsc2019"
directory: "/windows/windowsservercore-ltsc2019"
schedule:
interval: weekly
open-pull-requests-limit: 10
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ The image has several supported configurations, which can be accessed via the fo

* `latest`, `latest-jdk11`, `jdk11`, `latest-bullseye-jdk11`, `bullseye-jdk11`, `latest-debian-jdk11`, `debian-jdk11`, `${IMAGE_VERSION}`, `${IMAGE_VERSION}-jdk11`, ([Dockerfile](debian/Dockerfile))
* `latest-jdk17`, `jdk17`, `latest-bullseye-jdk17`, `bullseye-jdk17`,`latest-debian-jdk17`, `debian-jdk17`, `${IMAGE_VERSION}-jdk17`, ([Dockerfile](debian/Dockerfile))
* `nanoserver-1809`, `nanoserver-ltsc2019`, `nanoserver-1809-jdk11`, `nanoserver-ltsc2019-jdk11`, `${IMAGE_VERSION}-nanoserver-1809`, `${IMAGE_VERSION}-nanoserver-ltsc2019`, `${IMAGE_VERSION}-nanoserver-1809-jdk11`, `${IMAGE_VERSION}-nanoserver-ltsc2019-jdk11` ([Dockerfile](11/windows/nanoserver-ltsc2019/Dockerfile))
* `windowsservercore-1809`, `windowsservercore-ltsc2019`, `windowsservercore-1809-jdk11`, `windowsservercore-ltsc2019-jdk11`, `${IMAGE_VERSION}-windowsservercore-1809`, `${IMAGE_VERSION}-windowsservercore-ltsc2019`, `${IMAGE_VERSION}-windowsservercore-1809-jdk11`, `${IMAGE_VERSION}-windowsservercore-ltsc2019-jdk11` ([Dockerfile](11/windows/windowsservercore-ltsc2019/Dockerfile))
* `nanoserver-1809`, `nanoserver-ltsc2019`, `nanoserver-1809-jdk11`, `nanoserver-ltsc2019-jdk11`, `${IMAGE_VERSION}-nanoserver-1809`, `${IMAGE_VERSION}-nanoserver-ltsc2019`, `${IMAGE_VERSION}-nanoserver-1809-jdk11`, `${IMAGE_VERSION}-nanoserver-ltsc2019-jdk11` ([Dockerfile](windows/nanoserver-ltsc2019/Dockerfile))
* `windowsservercore-1809`, `windowsservercore-ltsc2019`, `windowsservercore-1809-jdk11`, `windowsservercore-ltsc2019-jdk11`, `${IMAGE_VERSION}-windowsservercore-1809`, `${IMAGE_VERSION}-windowsservercore-ltsc2019`, `${IMAGE_VERSION}-windowsservercore-1809-jdk11`, `${IMAGE_VERSION}-windowsservercore-ltsc2019-jdk11` ([Dockerfile](windows/windowsservercore-ltsc2019/Dockerfile))

## Building instructions

Expand Down
2 changes: 1 addition & 1 deletion debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ARG gid=1000
ARG JENKINS_AGENT_HOME=/home/${user}

ENV JENKINS_AGENT_HOME=${JENKINS_AGENT_HOME}
ARG AGENT_WORKDIR="${JENKINS_AGENT_HOME}"/agent
ARG AGENT_WORKDIR="${JENKINS_AGENT_HOME}/agent"
# Persist agent workdir path through an environment variable for people extending the image
ENV AGENT_WORKDIR=${AGENT_WORKDIR}

Expand Down
113 changes: 68 additions & 45 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Param(
[Parameter(Position=1)]
[String] $Target = "build",
[String] $AdditionalArgs = '',
[String] $Build = '',
[String] $VersionTag = '1.0-1',
[switch] $PushVersions = $false
)

$Repository = 'ssh-agent'
$Organization = 'jenkins'
$Java11Version = '11.0.19_7'

if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_REPO)) {
$Repository = $env:DOCKERHUB_REPO
Expand All @@ -20,58 +20,85 @@ if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_ORGANISATION)) {
}

$builds = @{
'jdk11' = @{
'Folder' = '11\windows\windowsservercore-ltsc2019';
'jdk11-windowsservercore-ltsc2019' = @{
'Folder' = 'windows\windowsservercore-ltsc2019';
'Tags' = @( "windowsservercore-1809", "windowsservercore-1809-jdk11", "windowsservercore-ltsc2019", "windowsservercore-ltsc2019-jdk11" );
'JavaVersion' = $Java11Version;
'JavaHome' = 'C:\openjdk-11';
};
'nanoserver-jdk11' = @{
'Folder' = '11\windows\nanoserver-ltsc2019';
'jdk11-nanoserver-1809' = @{
'Folder' = 'windows\nanoserver-ltsc2019';
'Tags' = @( "nanoserver-1809", "nanoserver-ltsc2019", "nanoserver-1809-jdk11", "nanoserver-ltsc2019", "nanoserver-ltsc2019-jdk11" );
'JavaVersion' = $Java11Version;
'JavaHome' = 'C:\openjdk-11';
};
}

function Build-Image {
param (
[String] $Build,
[String] $ImageName,
[String] $JavaVersion,
[String] $JavaHome,
[String] $Folder
)

Write-Host "Building $Build with name $imageName"
docker build --build-arg "JAVA_VERSION=${JavaVersion}" --build-arg "JAVA_HOME=${JavaHome}" --tag="${ImageName}" --file="${Folder}/Dockerfile" ./
}

$exitCodes = 0
if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) {
foreach($tag in $builds[$Build]['Tags']) {
Copy-Item -Path 'setup-sshd.ps1' -Destination (Join-Path $builds[$Build]['Folder'] 'setup-sshd.ps1') -Force
Copy-Item -Path 'CreateProfile.psm1' -Destination (Join-Path $builds[$Build]['Folder'] 'CreateProfile.psm1') -Force
Write-Host "Building $Build => tag=$tag"
$cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$Build]['Folder']
Invoke-Expression $cmd
Build-Image -Build $Build -ImageName "${Organization}/${Repository}:${tag}" -JavaVersion $builds[$Build]['JavaVersion'] -JavaHome $builds[$Build]['JavaHome'] -Folder $builds[$Build]['Folder']
$exitCodes += $lastExitCode

if($PushVersions) {
$buildTag = "$VersionTag-$tag"
if($tag -eq 'latest') {
$buildTag = "$VersionTag"
}
Write-Host "Building $Build => tag=$buildTag"
$cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$Build]['Folder']
Invoke-Expression $cmd
Build-Image -Build $Build -ImageName "${Organization}/${Repository}:${buildTag}" -JavaVersion $builds[$Build]['JavaVersion'] -JavaHome $builds[$Build]['JavaHome'] -Folder $builds[$Build]['Folder']
$exitCodes += $lastExitCode
}
}
} else {
foreach($b in $builds.Keys) {
Copy-Item -Path 'setup-sshd.ps1' -Destination (Join-Path $builds[$b]['Folder'] 'setup-sshd.ps1') -Force
Copy-Item -Path 'CreateProfile.psm1' -Destination (Join-Path $builds[$b]['Folder'] 'CreateProfile.psm1') -Force
foreach($tag in $builds[$b]['Tags']) {
Write-Host "Building $b => tag=$tag"
$cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$b]['Folder']
Invoke-Expression $cmd
Build-Image -Build $Build -ImageName "${Organization}/${Repository}:${tag}" -JavaVersion $builds[$b]['JavaVersion'] -JavaHome $builds[$b]['JavaHome'] -Folder $builds[$b]['Folder']
$exitCodes += $lastExitCode

if($PushVersions) {
$buildTag = "$VersionTag-$tag"
if($tag -eq 'latest') {
$buildTag = "$VersionTag"
}
Write-Host "Building $Build => tag=$buildTag"
$cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$b]['Folder']
Invoke-Expression $cmd
Build-Image -Build $Build -ImageName "${Organization}/${Repository}:${buildTag}" -JavaVersion $builds[$b]['JavaVersion'] -JavaHome $builds[$b]['JavaHome'] -Folder $builds[$b]['Folder']
$exitCodes += $lastExitCode
}
}
}
}

if($lastExitCode -ne 0) {
exit $lastExitCode
if($exitCodes -ne 0) {
Write-Host "Image build stage failed!"
exit 1
} else {
Write-Host "Image build stage passed!"
}

function Test-Image {
param (
[String] $ImageName,
[String] $ImageFolder
)

Write-Host "Testing $ImageName..."
$env:AGENT_IMAGE = $ImageName
$env:IMAGE_FOLDER = $ImageFolder
Invoke-Pester -Path tests -EnableExit
Remove-Item env:\AGENT_IMAGE
Remove-Item env:\IMAGE_FOLDER
}

if($Target -eq "test") {
Expand All @@ -88,54 +115,50 @@ if($Target -eq "test") {
}

if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) {
$env:FOLDER = $builds[$Build]['Folder']
$env:VERSION = "$VersionTag"
Invoke-Pester -Path tests -EnableExit
Remove-Item env:\FOLDER
Remove-Item env:\VERSION
Test-Image $Build $builds[$Build]['Folder']
} else {
foreach($b in $builds.Keys) {
$env:FOLDER = $builds[$b]['Folder']
$env:VERSION = "$VersionTag"
Invoke-Pester -Path tests -EnableExit
Remove-Item env:\FOLDER
Remove-Item env:\VERSION
Test-Image $b $builds[$b]['Folder']
}
}
}

function Publish-Image {
param (
[String] $Build,
[String] $ImageName
)
Write-Host "= PUBLISH: Tagging $Build => full name = $ImageName"
docker tag "$Build" "$ImageName"

Write-Host "= PUBLISH: Publishing $ImageName..."
docker push "$ImageName"
}

if($Target -eq "publish") {
if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) {
foreach($tag in $Builds[$Build]['Tags']) {
Write-Host "Publishing $Build => tag=$tag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $tag
Invoke-Expression $cmd
Publish-Image "$Build" "${Organization}/${Repository}:${tag}"

if($PushVersions) {
$buildTag = "$VersionTag-$tag"
if($tag -eq 'latest') {
$buildTag = "$VersionTag"
}
Write-Host "Publishing $Build => tag=$buildTag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag
Invoke-Expression $cmd
Publish-Image "$Build" "${Organization}/${Repository}:${buildTag}"
}
}
} else {
foreach($b in $builds.Keys) {
foreach($tag in $Builds[$b]['Tags']) {
Write-Host "Publishing $b => tag=$tag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $tag
Invoke-Expression $cmd
Publish-Image "$b" "${Organization}/${Repository}:${tag}"

if($PushVersions) {
$buildTag = "$VersionTag-$tag"
if($tag -eq 'latest') {
$buildTag = "$VersionTag"
}
Write-Host "Publishing $Build => tag=$buildTag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag
Invoke-Expression $cmd
Publish-Image "$b" "${Organization}/${Repository}:${tag}"
}
}
}
Expand Down
Loading

0 comments on commit a255365

Please sign in to comment.