Skip to content

Commit

Permalink
Add docker-buildx target to Makefile
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
hiddeco committed Sep 30, 2021
1 parent 9f1b8cb commit 84facf8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ CRD_OPTIONS ?= crd:crdVersions=v1
BASE_IMG ?= ghcr.io/hiddeco/golang-with-libgit2
BASE_TAG ?= dev

# Allows for defining additional Docker buildx arguments,
# e.g. '--push'.
BUILDX_ARGS ?=
# Architectures to build images for
BUILDX_PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v7

# Directory with versioned, downloaded things
CACHE := cache

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

docker-buildx: ## Build the cross-platform Docker image
docker buildx build \
--build-arg BASE_IMG=$(BASE_IMG) \
--build-arg BASE_TAG=$(BASE_TAG) \
--platform=$(BUILDX_PLATFORMS) \
-t $(IMG):$(TAG) \
$(BUILDX_ARGS) .

docker-push: ## Push the Docker image
docker push $(IMG):$(TAG)

Expand Down

0 comments on commit 84facf8

Please sign in to comment.