Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
build Windows images with docker compose like docker-agent and regrou…
Browse files Browse the repository at this point in the history
…p dockerfiles
  • Loading branch information
lemeurherve committed Jul 9, 2023
1 parent 52cd94c commit ac54873
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 404 deletions.
159 changes: 87 additions & 72 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,103 @@ pipeline {

options {
buildDiscarder(logRotator(daysToKeepStr: '10'))
timestamps()
}

stages {
stage('docker-agent') {
failFast true
matrix {
axes {
axis {
name 'AGENT_TYPE'
values 'linux', 'windows-2019'
stage('Build') {
parallel {
stage('Windows') {
agent {
label "docker-windows"
}
}
stages {
stage('Main') {
agent {
label env.AGENT_TYPE
}
options {
timeout(time: 30, unit: 'MINUTES')
}
environment {
DOCKERHUB_ORGANISATION = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}"
}
stages {
stage('Prepare Docker') {
when {
environment name: 'AGENT_TYPE', value: 'linux'
}
steps {
sh '''
docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
'''
}
options {
timeout(time: 60, unit: 'MINUTES')
}
environment {
DOCKERHUB_ORGANISATION = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}"
}
stages {
stage('Build and Test') {
// This stage is the "CI" and should be run on all code changes triggered by a code change
when {
not { buildingTag() }
}
stage('Build and Test') {
// This stage is the "CI" and should be run on all code changes triggered by a code change
when {
not { buildingTag() }
}
steps {
script {
if(isUnix()) {
sh './build.sh'
sh './build.sh test'
// If the tests are passing for Linux AMD64, then we can build all the CPU architectures
sh 'docker buildx bake --file docker-bake.hcl linux'
} else {
powershell "& ./build.ps1 test"
}
}
steps {
powershell '& ./build.ps1 test'
}
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
}
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
}
}
stage('Deploy to DockerHub') {
// This stage is the "CD" and should only be run when a tag triggered the build
when {
buildingTag()
}
steps {
script {
infra.withDockerCredentials {
// TODO: check if this function has the same beahvior in build.ps1 vs make.ps1
powershell '& ./build.ps1 -PushVersions -VersionTag $env:TAG_NAME publish'
}
}
}
stage('Deploy to DockerHub') {
// This stage is the "CD" and should only be run when a tag triggered the build
when {
buildingTag()
}
}
}
stage('Linux') {
agent {
label "docker&&linux"
}
options {
timeout(time: 30, unit: 'MINUTES')
}
environment {
JENKINS_REPO = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}/inbound-agent"
}
stages {
stage('Prepare Docker') {
steps {
sh '''
docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
'''
}
}
stage('Build and Test') {
// This stage is the "CI" and should be run on all code changes triggered by a code change
when {
not { buildingTag() }
}
steps {
sh 'make build'
sh 'make test'
// If the tests are passing for Linux AMD64, then we can build all the CPU architectures
sh 'docker buildx bake --file docker-bake.hcl linux'
}
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/*.xml')
}
steps {
script {
def tagItems = env.TAG_NAME.split('-')
if(tagItems.length == 2) {
def remotingVersion = tagItems[0]
def buildNumber = tagItems[1]
// This function is defined in the jenkins-infra/pipeline-library
infra.withDockerCredentials {
if (isUnix()) {
sh """
docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
./build.sh -r ${remotingVersion} -b ${buildNumber} -d publish
"""
} else {
powershell "& ./build.ps1 -PushVersions -RemotingVersion $remotingVersion -BuildNumber $buildNumber -DisableEnvProps publish"
}
}
}
}
}
stage('Deploy to DockerHub') {
// This stage is the "CD" and should only be run when a tag triggered the build
when {
buildingTag()
}
steps {
script {
// This function is defined in the jenkins-infra/pipeline-library
infra.withDockerCredentials {
sh '''
export IMAGE_TAG="${TAG_NAME}"
export ON_TAG=true
docker buildx bake --push --file docker-bake.hcl linux
'''
}
}
}
Expand Down
28 changes: 12 additions & 16 deletions build-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,28 @@ services:
jdk11-nanoserver-1809:
image: jdk11-nanoserver-1809
build:
context: ./windows/nanoserver-1809/
context: ./windows/
dockerfile: Dockerfile.nanoserver
args:
JAVA_HOME: "C:/openjdk-11"
JAVA_VERSION: "11.0.19_7"
VERSION: ${REMOTING_VERSION}
VERSION: ${DOCKER_AGENT_VERSION}
jdk17-nanoserver-1809:
image: jdk17-nanoserver-1809
build:
context: ./windows/nanoserver-1809/
context: ./windows/
dockerfile: Dockerfile.nanoserver
args:
JAVA_HOME: "C:/openjdk-17"
JAVA_VERSION: "17.0.7_7"
VERSION: ${REMOTING_VERSION}
VERSION: ${DOCKER_AGENT_VERSION}
jdk11-windowsservercore-ltsc2019:
image: jdk11-windowsservercore-ltsc2019
build:
context: ./windows/windowsservercore-ltsc2019/
context: ./windows/
dockerfile: Dockerfile.windowsservercore
args:
JAVA_HOME: "C:/openjdk-11"
JAVA_VERSION: "11.0.19_7"
VERSION: ${REMOTING_VERSION}
VERSION: ${DOCKER_AGENT_VERSION}
jdk17-windowsservercore-ltsc2019:
image: jdk17-windowsservercore-ltsc2019
build:
context: ./windows/windowsservercore-ltsc2019/
context: ./windows/
dockerfile: Dockerfile.windowsservercore
args:
JAVA_HOME: "C:/openjdk-17"
JAVA_VERSION: "17.0.7_7"
VERSION: ${REMOTING_VERSION}
VERSION: ${DOCKER_AGENT_VERSION}
64 changes: 37 additions & 27 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ Param(
[Parameter(Position=1)]
[String] $Target = "build",
[String] $Build = '',
[String] $RemotingVersion = '3131.vf2b_b_798b_ce99',
[String] $DockerAgentVersion = '3131.vf2b_b_798b_ce99-2',
[String] $BuildNumber = '1',
[switch] $PushVersions = $false,
[switch] $DisableEnvProps = $false
[switch] $PushVersions = $false
# [switch] $PushVersions = $false,
# [switch] $DisableEnvProps = $false
)

$ErrorActionPreference = "Stop"
$Repository = 'agent'
$Repository = 'inbound-agent'
$Organization = 'jenkins'

if(!$DisableEnvProps) {
Get-Content env.props | ForEach-Object {
$items = $_.Split("=")
if($items.Length -eq 2) {
$name = $items[0].Trim()
$value = $items[1].Trim()
Set-Item -Path "env:$($name)" -Value $value
}
}
}
# TODO: not needed? Commented for now, env.props contains DOCKER_AGENT_VERSION in docker-agent
# if(!$DisableEnvProps) {
# Get-Content env.props | ForEach-Object {
# $items = $_.Split("=")
# if($items.Length -eq 2) {
# $name = $items[0].Trim()
# $value = $items[1].Trim()
# Set-Item -Path "env:$($name)" -Value $value
# }
# }
# }

if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_REPO)) {
$Repository = $env:DOCKERHUB_REPO
Expand All @@ -32,8 +34,8 @@ if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_ORGANISATION)) {
$Organization = $env:DOCKERHUB_ORGANISATION
}

if(![String]::IsNullOrWhiteSpace($env:REMOTING_VERSION)) {
$RemotingVersion = $env:REMOTING_VERSION
if(![String]::IsNullOrWhiteSpace($env:DOCKER_AGENT_VERSION)) {
$DockerAgentVersion = $env:DOCKER_AGENT_VERSION
}

# Check for required commands
Expand Down Expand Up @@ -61,7 +63,7 @@ Function Test-CommandExists {
# this is the jdk version that will be used for the 'bare tag' images, e.g., jdk8-windowsservercore-1809 -> windowsserver-1809
$defaultJdk = '11'
$builds = @{}
$env:REMOTING_VERSION = "$RemotingVersion"
$env:DOCKER_AGENT_VERSION = "$DockerAgentVersion"
$ProgressPreference = 'SilentlyContinue' # Disable Progress bar for faster downloads

Test-CommandExists "docker"
Expand All @@ -74,16 +76,20 @@ $baseDockerBuildCmd = '{0} build --parallel --pull' -f $baseDockerCmd
Invoke-Expression "$baseDockerCmd config --services" 2>$null | ForEach-Object {
$image = $_
$items = $image.Split("-")
# Remove the 'jdk' prefix (3 first characters)
$jdkMajorVersion = $items[0].Remove(0,3)
$windowsType = $items[1]
$windowsVersion = $items[2]

$baseImage = "${windowsType}-${windowsVersion}"
$versionTag = "${RemotingVersion}-${BuildNumber}-${image}"
$versionTag = "${DockerAgentVersion}-${BuildNumber}-${image}"
$tags = @( $image, $versionTag )
if($jdkMajorVersion -eq "$defaultJdk") {
$tags += $baseImage
}
# TODO: keep it here too? (from docker-agent)
# if($jdkMajorVersion -eq "$defaultJdk") {
# $tags += $baseImage
# }

Write-Host "New Windows image to build ($image): ${Organization}/${Repository}:${baseImage} with JDK ${jdkMajorVersion}"

$builds[$image] = @{
'Tags' = $tags;
Expand Down Expand Up @@ -114,8 +120,11 @@ function Test-Image {

$env:AGENT_IMAGE = $ImageName
$env:IMAGE_FOLDER = Invoke-Expression "$baseDockerCmd config" 2>$null | yq -r ".services.${ImageName}.build.context"
$env:VERSION = "$RemotingVersion-$BuildNumber"
# TODO: review build number removal (?)
# $env:VERSION = "$DockerAgentVersion-$BuildNumber"
$env:VERSION = $DockerAgentVersion

Write-Host "= TEST: image folder ${env:IMAGE_FOLDER}, version ${env:VERSION}"

if(Test-Path ".\target\$ImageName") {
Remove-Item -Recurse -Force ".\target\$ImageName"
Expand Down Expand Up @@ -180,6 +189,7 @@ if($target -eq "test") {
}
}

# TODO: dry mode?
function Publish-Image {
param (
[String] $Build,
Expand Down Expand Up @@ -207,9 +217,9 @@ if($target -eq "publish") {
}

if($PushVersions) {
$buildTag = "$RemotingVersion-$BuildNumber-$tag"
$buildTag = "$DockerAgentVersion-$BuildNumber-$tag"
if($tag -eq 'latest') {
$buildTag = "$RemotingVersion-$BuildNumber"
$buildTag = "$DockerAgentVersion-$BuildNumber"
}
Publish-Image "$Build" "${Organization}/${Repository}:${buildTag}"
if($lastExitCode -ne 0) {
Expand All @@ -226,9 +236,9 @@ if($target -eq "publish") {
}

if($PushVersions) {
$buildTag = "$RemotingVersion-$BuildNumber-$tag"
$buildTag = "$DockerAgentVersion-$BuildNumber-$tag"
if($tag -eq 'latest') {
$buildTag = "$RemotingVersion-$BuildNumber"
$buildTag = "$DockerAgentVersion-$BuildNumber"
}
Publish-Image "$b" "${Organization}/${Repository}:${buildTag}"
if($lastExitCode -ne 0) {
Expand Down
Loading

0 comments on commit ac54873

Please sign in to comment.