diff --git a/Makefile b/Makefile index 0e73415b75..baa0ef17b8 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/build/images/ingress-controller/Dockerfile b/build/images/ingress-controller/Dockerfile index 1cb670e78b..b8607e679e 100644 --- a/build/images/ingress-controller/Dockerfile +++ b/build/images/ingress-controller/Dockerfile @@ -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 \ diff --git a/build/images/ingress-controller/build-ingress-controller.sh b/build/images/ingress-controller/build-ingress-controller.sh index eaa44ad958..d156b8c445 100644 --- a/build/images/ingress-controller/build-ingress-controller.sh +++ b/build/images/ingress-controller/build-ingress-controller.sh @@ -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 diff --git a/build/images/nginx/Dockerfile b/build/images/nginx/Dockerfile index 90fe42ea29..d1d3b15a0a 100644 --- a/build/images/nginx/Dockerfile +++ b/build/images/nginx/Dockerfile @@ -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 diff --git a/build/images/nginx/build-nginx.sh b/build/images/nginx/build-nginx.sh index 9f0a07f13c..efb500c46b 100644 --- a/build/images/nginx/build-nginx.sh +++ b/build/images/nginx/build-nginx.sh @@ -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 diff --git a/images/nginx/Makefile b/images/nginx/Makefile index 5129d2b009..da8482bba7 100644 --- a/images/nginx/Makefile +++ b/images/nginx/Makefile @@ -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 diff --git a/test/e2e/run.sh b/test/e2e/run.sh index 4f25fc4b74..281d896f51 100755 --- a/test/e2e/run.sh +++ b/test/e2e/run.sh @@ -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