Skip to content

Commit

Permalink
Use docker buildx and remove qemu-static binary (#4922)
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored Jan 13, 2020
1 parent a9dc66f commit c86e4e0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build/images/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
12 changes: 10 additions & 2 deletions build/images/nginx/build-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
40 changes: 5 additions & 35 deletions images/nginx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions images/nginx/rootfs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

FROM alpine:3.11 as builder

CROSS_BUILD_COPY qemu-ARCH-static /usr/bin/

COPY . /

RUN apk add -U bash \
Expand Down

0 comments on commit c86e4e0

Please sign in to comment.