Skip to content

Commit

Permalink
use docker buildx to buld multi-arch image (#4407)
Browse files Browse the repository at this point in the history
  • Loading branch information
mainred authored Nov 18, 2021
1 parent 00d828e commit f2a5f9d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions addon-resizer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ IMGNAME = addon-resizer
IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
TAG = 2.3
# The output type could either be docker (local), or registry.
OUTPUT_TYPE ?= docker

BASEIMAGE?=gcr.io/distroless/static:latest

Expand All @@ -43,8 +45,12 @@ sub-push-%:
all-container: test $(addprefix sub-container-,$(ALL_ARCH))

all-push: $(addprefix sub-push-,$(ALL_ARCH))

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

container: .container-$(ARCH)
.container-$(ARCH):
.container-$(ARCH): buildx-setup
cp -r * $(TEMP_DIR)
cd $(TEMP_DIR) && sed -i 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile

Expand All @@ -55,7 +61,11 @@ container: .container-$(ARCH)
cd /go/src/k8s.io/autoscaler/addon-resizer/ && \
CGO_ENABLED=0 GOARM=$(GOARM) GOARCH=$(ARCH) godep go build -a -installsuffix cgo --ldflags '-w -X k8s.io/autoscaler/addon-resizer/nanny.AddonResizerVersion=$(TAG)' -o $(TEMP_DIR)/pod_nanny main.go"

docker build -t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR)
docker buildx build \
--pull \
--platform linux/$(ARCH) \
--output=type=$(OUTPUT_TYPE) \
-t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR)

ifeq ($(ARCH), amd64)
# This is for to maintain the backward compatibility
Expand Down

0 comments on commit f2a5f9d

Please sign in to comment.