Skip to content

Commit

Permalink
Merge pull request #117 from mainred/docker-buildx-for-multi-arch-image
Browse files Browse the repository at this point in the history
use docker buildx for multi-arch image
  • Loading branch information
k8s-ci-robot authored Jul 27, 2022
2 parents 3a0f0f6 + 279fe49 commit d186f0a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ SRC_DIRS := cmd pkg # directories which hold app source (not vendored)

ALL_ARCH := amd64 arm arm64 ppc64le

# The output type could either be docker (local), or registry.
OUTPUT_TYPE ?= docker

IMAGE := $(REGISTRY)/$(BIN)-$(ARCH)

BUILD_IMAGE ?= golang:1.18.4-alpine
Expand Down Expand Up @@ -84,13 +87,16 @@ bin/$(ARCH)/$(BIN): build-dirs

DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(VERSION)

buildx-setup:
docker buildx inspect img-builder > /dev/null || docker buildx create --name img-builder --use

container: .container-$(DOTFILE_IMAGE) container-name
.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in
.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in buildx-setup
@sed \
-e 's|ARG_BIN|$(BIN)|g' \
-e 's|ARG_ARCH|$(ARCH)|g' \
Dockerfile.in > .dockerfile-$(ARCH)
@docker build --pull -t $(IMAGE):$(VERSION) -f .dockerfile-$(ARCH) .
@docker buildx build --pull --platform linux/$(ARCH) --output=type=$(OUTPUT_TYPE) -t $(IMAGE):$(VERSION) -f .dockerfile-$(ARCH) .
@docker images -q $(IMAGE):$(VERSION) > $@

container-name:
Expand Down

0 comments on commit d186f0a

Please sign in to comment.