From 8e8263802e678abb4e663f4707f21fc6599bf013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= <91831478+lemeurherve@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:58:26 +0200 Subject: [PATCH] fix: implement `docker` calls as `make` targets (#421) * fix: replace `docker` calls by `make` ones * bake target as first arg everywhere for consistency * prefer US spelling Co-authored-by: Damien Duportal * rename `ci-init` make target to `docker-init` * rename `buildall` make target to `every-build` --------- Co-authored-by: Damien Duportal --- Jenkinsfile | 17 +++++++---------- Makefile | 20 ++++++++++++++++---- README.md | 27 ++++++++++++++++++++------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 26392919..118113f6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,10 +44,7 @@ pipeline { 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 docker-init' } } stage('Build and Test') { @@ -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 every-build' } else { powershell '& ./build.ps1 test' } @@ -83,13 +80,13 @@ pipeline { // This function is defined in the jenkins-infra/pipeline-library infra.withDockerCredentials { if (isUnix()) { - sh """ + sh ''' export ON_TAG=true - export VERSION=$TAG_NAME - docker buildx bake --push --file docker-bake.hcl linux - """ + export VERSION="${TAG_NAME}" + make publish + ''' } else { - powershell "& ./build.ps1 -VersionTag ${env.TAG_NAME} publish" + powershell '& ./build.ps1 -VersionTag $env:TAG_NAME publish' } } } diff --git a/Makefile b/Makefile index a32b3445..520a9903 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -37,15 +38,23 @@ check-reqs: @$(call check_cli,curl) @$(call check_cli,jq) +## This function is specific to Jenkins infrastructure and isn't required in other contexts +docker-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)' + +every-build: 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' @@ -57,6 +66,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) diff --git a/README.md b/README.md index 5fb456f6..0eae5cb8 100644 --- a/README.md +++ b/README.md @@ -120,14 +120,15 @@ If you want to build a specific image, you can issue the following command: make build-_ ``` -That would give for JDK 11 on Alpine Linux: +That would give for JDK 17 on Alpine Linux: ```bash -make build-alpine_jdk11 +make build-alpine_jdk17 ``` -#### Building all images -Then, you can build all the images by running: +#### Building images supported by your current architecture + +Then, you can build the images supported by your current architecture by running: ```bash make build @@ -135,7 +136,7 @@ make build #### Testing all images -If you want to test the images, you can run: +If you want to test these images, you can run: ```bash make test @@ -148,10 +149,18 @@ If you want to test a specific image, you can run: make test-_ ``` -That would give for JDK 11 on Alpine Linux: +That would give for JDK 17 on Alpine Linux: + +```bash +make test-alpine_jdk17 +``` + +#### Building all images + +You can build all images (even those unsupported by your current architecture) by running: ```bash -make test-alpine_jdk11 +make every-build ``` #### Other `make` targets @@ -196,6 +205,10 @@ make bats make: 'bats' is up to date. ``` +`publish` allows the publication of all images targeted by 'linux' to a registry. + +`docker-init` is dedicated to Jenkins infrastructure for initializing docker and isn't required in other contexts. + ### Building and testing on Windows From a Powershell console, set first the `IMAGE_TYPE` environment variable defining the Windows flavor ("nanoserver"/"windowsservercore") and version you want to build.