Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verification of docker buildx support #4966

Merged
merged 1 commit into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand All @@ -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

Expand Down Expand Up @@ -107,35 +105,40 @@ 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.

# 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.
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions build/images/ingress-controller/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
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 \
Expand Down
3 changes: 2 additions & 1 deletion build/images/ingress-controller/build-ingress-controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/images/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 3 additions & 6 deletions build/images/nginx/build-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions images/nginx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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);)
Expand All @@ -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
4 changes: 2 additions & 2 deletions test/e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down