Skip to content

Commit

Permalink
fix: implement docker calls as make targets (#421)
Browse files Browse the repository at this point in the history
* fix: replace `docker` calls by `make` ones

* bake target as first arg everywhere for consistency

* prefer US spelling

Co-authored-by: Damien Duportal <[email protected]>

* rename `ci-init` make target to `docker-init`

* rename `buildall` make target to `every-build`

---------

Co-authored-by: Damien Duportal <[email protected]>
  • Loading branch information
lemeurherve and dduportal authored Jun 18, 2024
1 parent cc64011 commit 8e82638
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
17 changes: 7 additions & 10 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
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 every-build'
} else {
powershell '& ./build.ps1 test'
}
Expand All @@ -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'
}
}
}
Expand Down
20 changes: 16 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,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'
Expand All @@ -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)
Expand Down
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,23 @@ If you want to build a specific image, you can issue the following command:
make build-<OS>_<JDK_VERSION>
```

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
```

#### 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
Expand All @@ -148,10 +149,18 @@ If you want to test a specific image, you can run:
make test-<OS>_<JDK_VERSION>
```

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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8e82638

Please sign in to comment.