Add verification of docker buildx support (#4966)

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-01-26 10:07:55 -03:00 committed by GitHub
parent 7ff49b25d6
commit 5eddf1095d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 24 deletions

View file

@ -24,11 +24,10 @@ ifndef VERBOSE
endif
# set default shell
SHELL = /bin/bash
SHELL=/bin/bash -o pipefail
# Use the 0.0 tag for testing, it shouldn't clobber any release builds
TAG ?= master
DOCKER ?= docker
# Use docker to run makefile tasks
USE_DOCKER ?= true
@ -60,6 +59,8 @@ BUSTED_ARGS =-v --pattern=_test
ARCH ?= $(shell go env GOARCH)
BASEIMAGE_TAG = 26f574dc279aa853736d7f7249965e90e47171d6
REGISTRY ?= quay.io/kubernetes-ingress-controller
MULTI_ARCH_IMAGE = $(REGISTRY)/nginx-ingress-controller-${ARCH}
@ -77,9 +78,6 @@ endif
# use vendor directory instead of go modules https://github.com/golang/go/wiki/Modules
GO111MODULE=off
# Set default base image dynamically for each arch
BASEIMAGE?=quay.io/kubernetes-ingress-controller/nginx-$(ARCH):26f574dc279aa853736d7f7249965e90e47171d6
TEMP_DIR := $(shell mktemp -d)
DOCKERFILE := $(TEMP_DIR)/rootfs/Dockerfile
@ -107,27 +105,32 @@ container: clean-container .container-$(ARCH) ## Build image for a particular ar
# internal task to build image for a particular arch.
.PHONY: .container-$(ARCH)
.container-$(ARCH):
.container-$(ARCH): init-docker-buildx
mkdir -p $(TEMP_DIR)/rootfs
cp bin/$(ARCH)/nginx-ingress-controller $(TEMP_DIR)/rootfs/nginx-ingress-controller
cp bin/$(ARCH)/dbg $(TEMP_DIR)/rootfs/dbg
cp bin/$(ARCH)/wait-shutdown $(TEMP_DIR)/rootfs/wait-shutdown
# Set default base image dynamically for each arch
cp -RP ./* $(TEMP_DIR)
$(SED_I) "s|BASEIMAGE|$(BASEIMAGE)|g" $(DOCKERFILE)
$(SED_I) "s|BASEIMAGE|quay.io/kubernetes-ingress-controller/nginx-$(ARCH):$(BASEIMAGE_TAG)|g" $(DOCKERFILE)
$(SED_I) "s|VERSION|$(TAG)|g" $(DOCKERFILE)
echo "Building docker image..."
$(DOCKER) buildx build \
--no-cache \
echo "Building docker image ($(ARCH))..."
# buildx assumes images are multi-arch
docker buildx build \
--pull \
--load \
--no-cache \
--progress plain \
--platform linux/$(ARCH) \
-t $(MULTI_ARCH_IMAGE):$(TAG) $(TEMP_DIR)/rootfs
.PHONY: clean-container
clean-container: ## Removes local image
@$(DOCKER) rmi -f $(MULTI_ARCH_IMAGE):$(TAG) || true
echo "removing old image $(MULTI_ARCH_IMAGE):$(TAG)"
@docker rmi -f $(MULTI_ARCH_IMAGE):$(TAG) || true
.PHONY: push
push: .push-$(ARCH) ## Publish image for a particular arch.
@ -135,7 +138,7 @@ push: .push-$(ARCH) ## Publish image for a particular arch.
# internal task
.PHONY: .push-$(ARCH)
.push-$(ARCH):
$(DOCKER) push $(MULTI_ARCH_IMAGE):$(TAG)
docker push $(MULTI_ARCH_IMAGE):$(TAG)
.PHONY: build
build: check-go-version ## Build ingress controller, debug tool and pre-stop hook.
@ -282,3 +285,14 @@ run-ingress-controller: ## Run the ingress controller locally using a kubectl pr
.PHONY: check-go-version
check-go-version:
@hack/check-go-version.sh
.PHONY: init-docker-buildx
init-docker-buildx:
ifeq ($(DIND_TASKS),)
ifneq ($(shell docker buildx 2>&1 >/dev/null; echo $?),)
$(error "buildx not vailable. Docker 19.03 or higher is required")
endif
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
docker buildx create --name ingress-nginx --use || true
docker buildx inspect --bootstrap
endif

View file

@ -1,6 +1,6 @@
FROM quay.io/kubernetes-ingress-controller/debian-base-amd64:0.1
FROM 8s.gcr.io/debian-base:v2.0.0
ENV TERRAFORM_VERSION 0.12.9
ENV TERRAFORM_VERSION 0.12.19
RUN clean-install \
bash \

View file

@ -83,7 +83,8 @@ cd ingress-nginx
# disable docker in docker tasks
export DIND_TASKS=0
make register-qemu
make init-docker-buildx
docker buildx use ingress-nginx --default --global
echo "Building NGINX image..."
make all-container

View file

@ -1,4 +1,4 @@
FROM quay.io/kubernetes-ingress-controller/debian-base-amd64:0.1
FROM k8s.gcr.io/debian-base:v2.0.0
ENV TERRAFORM_VERSION 0.12.19

View file

@ -76,13 +76,10 @@ git clone https://github.com/kubernetes/ingress-nginx
cd ingress-nginx/images/nginx
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
docker buildx install
docker buildx create --use --name ingress-nginx
export TAG=$(git rev-parse HEAD)
make init-docker-buildx
docker buildx use ingress-nginx --default --global
echo "Building NGINX images..."
make release

View file

@ -25,8 +25,10 @@ EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
COMMA := ,
.PHONY: all
all: container
.PHONY: container
container:
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build \
--no-cache \
@ -47,6 +49,7 @@ ifeq ($(ARCH), amd64)
docker tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG)
endif
.PHONY: push
push: container
$(foreach PLATFORM,$(PLATFORMS), \
docker push $(IMAGE)-$(PLATFORM):$(TAG);)
@ -55,5 +58,13 @@ ifeq ($(ARCH), amd64)
docker push $(IMAGE):$(TAG)
endif
.PHONY: release
release: push
echo "done"
.PHONY: init-docker-buildx
init-docker-buildx:
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
docker buildx create --name ingress-nginx --use || true
docker buildx inspect --bootstrap
endif

View file

@ -67,7 +67,7 @@ make -C ${DIR}/../../ build container
make -C ${DIR}/../../ e2e-test-image
make -C ${DIR}/../../images/fastcgi-helloserver/ build container
make -C ${DIR}/../../images/httpbin/ container
" | parallel --progress --joblog /tmp/log {} || cat /tmp/log
" | parallel --joblog /tmp/log {} || cat /tmp/log
# Remove after https://github.com/kubernetes/ingress-nginx/pull/4271 is merged
docker tag ${REGISTRY}/nginx-ingress-controller-${ARCH}:${TAG} ${REGISTRY}/nginx-ingress-controller:${TAG}
@ -82,7 +82,7 @@ kind load docker-image --name="${KIND_CLUSTER_NAME}" ${REGISTRY}/nginx-ingress-c
kind load docker-image --name="${KIND_CLUSTER_NAME}" ${REGISTRY}/fastcgi-helloserver:${TAG}
kind load docker-image --name="${KIND_CLUSTER_NAME}" openresty/openresty:1.15.8.2-alpine
kind load docker-image --name="${KIND_CLUSTER_NAME}" ${REGISTRY}/httpbin:${TAG}
" | parallel --progress --joblog /tmp/log {} || cat /tmp/log
" | parallel --joblog /tmp/log {} || cat /tmp/log
echo "[dev-env] running e2e tests..."
make -C ${DIR}/../../ e2e-test