Skip to content

chore: extract of improvements from #415 #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
def agentSelector(String imageType) {
// Image type running on a Linux agent
// Linux agent
if (imageType == 'linux') {
return 'linux'
}
// Image types running on a Windows Server Core 2022 agent
// Windows Server Core 2022 agent
if (imageType.contains('2022')) {
return 'windows-2022'
}
// Remaining image types running on a Windows Server Core 2019 agent: (nanoserver|windowservercore)-(1809|2019)
// Windows Server Core 2019 agent (for nanoserver 1809 & ltsc2019 and for windowservercore ltsc2019)
return 'windows-2019'
}

Expand All @@ -20,6 +20,9 @@ pipeline {

stages {
stage('docker-ssh-agent') {
environment {
DOCKERHUB_ORGANISATION = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}"
}
matrix {
axes {
axis {
Expand All @@ -35,19 +38,13 @@ pipeline {
options {
timeout(time: 60, unit: 'MINUTES')
}
environment {
DOCKERHUB_ORGANISATION = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}"
}
stages {
stage('Prepare Docker') {
when {
environment name: 'IMAGE_TYPE', value: 'linux'
}
steps {
sh '''
docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
'''
sh 'make init'
}
}
stage('Build and Test') {
Expand All @@ -61,7 +58,7 @@ pipeline {
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'
sh 'make buildall'
} else {
powershell '& ./build.ps1 test'
}
Expand All @@ -78,18 +75,18 @@ pipeline {
when {
buildingTag()
}
environment {
ON_TAG = 'true'
VERSION = "${env.TAG_NAME}"
}
steps {
script {
// This function is defined in the jenkins-infra/pipeline-library
infra.withDockerCredentials {
if (isUnix()) {
sh """
export ON_TAG=true
export VERSION=$TAG_NAME
docker buildx bake --push --file docker-bake.hcl linux
"""
sh 'make publish'
} else {
powershell "& ./build.ps1 -VersionTag ${env.TAG_NAME} publish"
powershell '& ./build.ps1 publish'
}
}
}
Expand Down
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ check_cli = type "$(1)" >/dev/null 2>&1 || { echo "Error: command '$(1)' require
## Check if a given image exists in the current manifest docker-bake.hcl
check_image = make --silent list | grep -w '$(1)' >/dev/null 2>&1 || { echo "Error: the image '$(1)' does not exist in manifest for the platform 'linux/$(ARCH)'. Please check the output of 'make list'. Exiting." ; exit 1 ; }
## Base "docker buildx base" command to be reused everywhere
bake_base_cli := docker buildx bake -f docker-bake.hcl --load
bake_base_cli := docker buildx bake --file docker-bake.hcl
bake_cli := $(bake_base_cli) --load

.PHONY: build
.PHONY: test test-alpine test-archlinux test-debian test-jdk11 test-jdk11-alpine
Expand All @@ -37,15 +38,22 @@ check-reqs:
@$(call check_cli,curl)
@$(call check_cli,jq)

init: check-reqs
@set -x; docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

build: check-reqs
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' $(shell make --silent list)
@set -x; $(bake_cli) $(shell make --silent list) --set '*.platform=linux/$(ARCH)'

build-%:
@$(call check_image,$*)
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' '$*'
@set -x; $(bake_cli) '$*' --set '*.platform=linux/$(ARCH)'

buildall: check-reqs
@set -x; $(bake_base_cli) linux

show:
@$(bake_base_cli) linux --print
$(bake_cli) linux --print

list: check-reqs
@set -x; make --silent show | jq -r '.target | path(.. | select(.platforms[] | contains("linux/$(ARCH)"))?) | add'
Expand All @@ -57,6 +65,9 @@ prepare-test: bats check-reqs
git submodule update --init --recursive
mkdir -p target

publish:
@set -x; $(bake_base_cli) linux --push

## Define bats options based on environment
# common flags for all tests
bats_flags := $(TEST_SUITES)
Expand Down
33 changes: 17 additions & 16 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Param(
[String] $Target = 'build',
[String] $Build = '',
[String] $VersionTag = '1.0-1',
[String] $ImageType = 'nanoserver-ltsc2019',
[switch] $DryRun = $false,
# Output debug info for tests. Accepted values:
# - empty (no additional test output)
Expand All @@ -15,15 +16,14 @@ Param(
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue' # Disable Progress bar for faster downloads

$Repository = 'ssh-agent'
$Organisation = 'jenkins'
$ImageType = 'windows-ltsc2019'

$baseDockerCmd = 'docker-compose --file=build-windows.yaml'
$baseDockerBuildCmd = '{0} build --parallel --pull' -f $baseDockerCmd

$Repository = 'ssh-agent'
$Organisation = 'jenkins'

if(![String]::IsNullOrWhiteSpace($env:TESTS_DEBUG)) {
$ImageType = $env:IMAGE_TYPE
$TestsDebug = $env:TESTS_DEBUG
}
$env:TESTS_DEBUG = $TestsDebug

Expand All @@ -39,6 +39,10 @@ if(![String]::IsNullOrWhiteSpace($env:IMAGE_TYPE)) {
$ImageType = $env:IMAGE_TYPE
}

if(![String]::IsNullOrWhiteSpace($env:VERSION)) {
$VersionTag = $env:VERSION
}

# Ensure constant env vars used in the docker compose file are defined
$env:DOCKERHUB_ORGANISATION = "$Organisation"
$env:DOCKERHUB_REPO = "$Repository"
Expand Down Expand Up @@ -84,10 +88,10 @@ function Test-Image {
$ImageNameAndJavaVersion
)

$items = $ImageNameAndJavaVersion.Split("|")
$items = $ImageNameAndJavaVersion.Split('|')
$imageName = $items[0]
$javaVersion = $items[1]
$imageNameItems = $imageName.Split(":")
$imageNameItems = $imageName.Split(':')
$imageTag = $imageNameItems[1]

Write-Host "= TEST: Testing ${ImageName} image"
Expand Down Expand Up @@ -116,18 +120,15 @@ function Test-Image {
return $failed
}

$baseDockerCmd = 'docker-compose --file=build-windows.yaml'
$baseDockerBuildCmd = '{0} build --parallel --pull' -f $baseDockerCmd

Write-Host "= PREPARE: List of $Organisation/$env:DOCKERHUB_REPO images and tags to be processed:"
Write-Host '= PREPARE: List of images and tags to be processed:'
Invoke-Expression "$baseDockerCmd config"

Write-Host '= BUILD: Building all images...'
switch ($DryRun) {
$true { Write-Host "(dry-run) $baseDockerBuildCmd" }
$false { Invoke-Expression $baseDockerBuildCmd }
}
Write-Host '= BUILD: Finished building all images.'
switch ($DryRun) {
$true { Write-Host "(dry-run) $baseDockerBuildCmd" }
$false { Invoke-Expression $baseDockerBuildCmd }
}
Write-Host '= BUILD: Finished building all images.'

if($lastExitCode -ne 0) {
exit $lastExitCode
Expand Down
18 changes: 12 additions & 6 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ group "linux-ppc64le" {
]
}

variable "jdks_to_build" {
default = [11, 17, 21]
}

variable "default_jdk" {
default = 17
}

variable "REGISTRY" {
default = "docker.io"
}
Expand Down Expand Up @@ -76,10 +84,7 @@ variable "DEBIAN_RELEASE" {
default = "bookworm-20240513"
}

variable "default_jdk" {
default = 17
}

## Common functions
# Return "true" if the jdk passed as parameter is the same as the default jdk, "false" otherwise
function "is_default_jdk" {
params = [jdk]
Expand All @@ -96,6 +101,7 @@ function "javaversion" {
: "${JAVA21_VERSION}"))
}

# Specific functions
# Return an array of Alpine platforms to use depending on the jdk passed as parameter
function "alpine_platforms" {
params = [jdk]
Expand All @@ -114,7 +120,7 @@ function "debian_platforms" {

target "alpine" {
matrix = {
jdk = [11, 17, 21]
jdk = jdks_to_build
}
name = "alpine_${jdk}"
dockerfile = "alpine/Dockerfile"
Expand All @@ -141,7 +147,7 @@ target "alpine" {

target "debian" {
matrix = {
jdk = [11, 17, 21]
jdk = jdks_to_build
}
name = "debian_${jdk}"
dockerfile = "debian/Dockerfile"
Expand Down