Skip to content

Commit 84facf8

Browse files
committed
Add docker-buildx target to Makefile
Various configuration flags allow for fine(r)-grain control over the build process: - `BASE_IMG`: FQDN of the base image that should be used, without a tag. - `BASE_TAG: tag of the base image that should be used. Allows checksum sum to be included. - `BUILDX_PLATFORMS`: platforms to target for the final container image. - `BUILDX_ARGS`: additional `docker buildx build` arguments, e.g. `--push` to push the result to a (local) image registry. Signed-off-by: Hidde Beydals <hello@hidde.co>
1 parent 9f1b8cb commit 84facf8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ CRD_OPTIONS ?= crd:crdVersions=v1
1010
BASE_IMG ?= ghcr.io/hiddeco/golang-with-libgit2
1111
BASE_TAG ?= dev
1212

13+
# Allows for defining additional Docker buildx arguments,
14+
# e.g. '--push'.
15+
BUILDX_ARGS ?=
16+
# Architectures to build images for
17+
BUILDX_PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v7
18+
1319
# Directory with versioned, downloaded things
1420
CACHE := cache
1521

@@ -132,6 +138,14 @@ docker-build: ## Build the Docker image
132138
--build-arg BASE_TAG=$(BASE_TAG) \
133139
-t $(IMG):$(TAG) .
134140

141+
docker-buildx: ## Build the cross-platform Docker image
142+
docker buildx build \
143+
--build-arg BASE_IMG=$(BASE_IMG) \
144+
--build-arg BASE_TAG=$(BASE_TAG) \
145+
--platform=$(BUILDX_PLATFORMS) \
146+
-t $(IMG):$(TAG) \
147+
$(BUILDX_ARGS) .
148+
135149
docker-push: ## Push the Docker image
136150
docker push $(IMG):$(TAG)
137151

0 commit comments

Comments
 (0)