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

Commit

Permalink
adapt Jenkinsfile, windows stage, compared to docker-agent before rec…
Browse files Browse the repository at this point in the history
…ent refactoring
  • Loading branch information
lemeurherve committed Jul 8, 2023
1 parent c3a1ef6 commit a1a509e
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 341 deletions.
200 changes: 125 additions & 75 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,144 @@ 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"
}
}
}
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
}
}
steps {
// script {
// def parallelBuilds = [:]
// def images = ['jdk11-windowsservercore-ltsc2019', 'jdk11-nanoserver-1809', 'jdk17-windowsservercore-ltsc2019', 'jdk17-nanoserver-1809']
// for (unboundImage in images) {
// def image = unboundImage // Bind variable before the closure
// // Prepare a map of the steps to run in parallel
// parallelBuilds[image] = {
// // Allocate a node for each image to avoid filling disk
// node('docker-windows') {
// checkout scm
// powershell '& ./make.ps1 -Build ' + image + ' test'
// junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
// }
// }
// }
// // Peform the parallel execution
// parallel parallelBuilds
// }
powershell '& ./build.ps1 test'
}
stage('Deploy to DockerHub') {
// This stage is the "CD" and should only be run when a tag triggered the build
when {
buildingTag()
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.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 {
// powershell '& ./make.ps1 -PushVersions -VersionTag $env:TAG_NAME publish'
// }

// // Directly from docker-agent
// def tagItems = env.TAG_NAME.split('-')
// if(tagItems.length == 2) {
// def dockerAgentVersion = tagItems[0]
// def buildNumber = tagItems[1]
// // This function is defined in the jenkins-infra/pipeline-library
// infra.withDockerCredentials {
// powershell "& ./build.ps1 -PushVersions -DockerAgentVersion $dockerAgentVersion -BuildNumber $buildNumber -DisableEnvProps publish"
// }
// }
// debug
echo "=== env.TAG_NAME: ${env:TAG_NAME}"
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('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')
// }
// }
// }
// 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
4 changes: 2 additions & 2 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
# THE SOFTWARE.

#TODO(oleg_nenashev): Does it also need an update?
ARG version=3131.vf2b_b_798b_ce99-2
ARG VERSION=3131.vf2b_b_798b_ce99-2
ARG JAVA_MAJOR_VERSION=17
FROM jenkins/agent:"${version}"-alpine-jdk"${JAVA_MAJOR_VERSION}"

ARG version=3131.vf2b_b_798b_ce99-2
ARG VERSION=3131.vf2b_b_798b_ce99-2
LABEL Description="This is a base image, which allows connecting Jenkins agents via JNLP protocols" Vendor="Jenkins project" Version="$version"

ARG user=jenkins
Expand Down
8 changes: 4 additions & 4 deletions build-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ services:
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/
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/
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/
args:
JAVA_HOME: "C:/openjdk-17"
JAVA_VERSION: "17.0.7_7"
VERSION: ${REMOTING_VERSION}
VERSION: ${DOCKER_AGENT_VERSION}
61 changes: 34 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,7 +120,7 @@ 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"
$env:VERSION = "$DockerAgentVersion-$BuildNumber"


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

# TODO: dry mode?
function Publish-Image {
param (
[String] $Build,
Expand Down Expand Up @@ -207,9 +214,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 +233,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 a1a509e

Please sign in to comment.