Use docker buildx and remove qemu-static binary (#4922)

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-01-13 20:34:24 -03:00 committed by GitHub
parent a9dc66f40c
commit c86e4e0d9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 40 deletions

View file

@ -1,6 +1,6 @@
FROM quay.io/kubernetes-ingress-controller/debian-base-amd64:0.1
ENV TERRAFORM_VERSION 0.12.16
ENV TERRAFORM_VERSION 0.12.19
RUN clean-install \
bash \

View file

@ -64,18 +64,26 @@ apt -q=3 update
apt -q=3 install docker-ce --yes
export DOCKER_CLI_EXPERIMENTAL=enabled
mkdir -p ~/.docker
echo '{ "experimental": "enabled", "aliases": { "builder": "buildx" } }' > ~/.docker/config.json
echo ${docker_password} | docker login -u ${docker_username} --password-stdin quay.io
curl -sL -o /usr/local/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme
chmod +x /usr/local/bin/gimme
eval "$(gimme 1.13)"
eval "$(gimme 1.13.6)"
git clone https://github.com/kubernetes/ingress-nginx
cd ingress-nginx/images/nginx
make register-qemu
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
docker buildx create --name ingress-nginx
docker buildx use ingress-nginx
export TAG=$(git rev-parse HEAD)

View file

@ -19,28 +19,11 @@ ARCH ?= $(shell go env GOARCH)
DOCKER ?= docker
ALL_ARCH = amd64 arm arm64
SED_I?=sed -i
GOHOSTOS ?= $(shell go env GOHOSTOS)
ifeq ($(GOHOSTOS),darwin)
SED_I=sed -i ''
endif
QEMUVERSION=v4.1.1-1
IMGNAME = nginx
IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
ifeq ($(ARCH),arm)
QEMUARCH=arm
endif
ifeq ($(ARCH),arm64)
QEMUARCH=aarch64
endif
TEMP_DIR := $(shell mktemp -d)
all: all-container
image-info:
@ -58,30 +41,17 @@ all-push: $(addprefix sub-push-,$(ALL_ARCH))
container: .container-$(ARCH)
.container-$(ARCH):
cp -r ./rootfs/* $(TEMP_DIR)
cd $(TEMP_DIR) && $(SED_I) "s|ARCH|$(QEMUARCH)|g" Dockerfile
ifeq ($(ARCH),amd64)
# When building "normally" for amd64, remove the whole line, it has no part in the amd64 image
cd $(TEMP_DIR) && $(SED_I) "/CROSS_BUILD_/d" Dockerfile
else
# When cross-building, only the placeholder "CROSS_BUILD_" should be removed
curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR)
cd $(TEMP_DIR) && $(SED_I) "s/CROSS_BUILD_//g" Dockerfile
endif
$(DOCKER) build --no-cache -t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR)
$(DOCKER) buildx build \
--no-cache \
--progress plain \
--platform linux/$(ARCH) \
-t $(MULTI_ARCH_IMG):$(TAG) rootfs
ifeq ($(ARCH), amd64)
# This is for to maintain the backward compatibility
$(DOCKER) tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG)
endif
.PHONY: register-qemu
register-qemu:
# Register /usr/bin/qemu-ARCH-static as the handler for binaries in multiple platforms
$(DOCKER) run --rm --privileged multiarch/qemu-user-static:register --reset
push: .push-$(ARCH)
.push-$(ARCH): .container-$(ARCH)
$(DOCKER) push $(MULTI_ARCH_IMG):$(TAG)

View file

@ -15,8 +15,6 @@
FROM alpine:3.11 as builder
CROSS_BUILD_COPY qemu-ARCH-static /usr/bin/
COPY . /
RUN apk add -U bash \