Skip to content

Commit

Permalink
Add verification of docker buildx support
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Jan 26, 2020
1 parent 7ff49b2 commit 22378ec
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 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 @@ -107,7 +106,7 @@ 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
Expand All @@ -118,24 +117,27 @@ container: clean-container .container-$(ARCH) ## Build image for a particular ar
$(SED_I) "s|VERSION|$(TAG)|g" $(DOCKERFILE)

echo "Building docker image..."
$(DOCKER) buildx build \
# buildx assumes images are multi-arch
docker buildx build \
--no-cache \
--pull \
--load \
--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 +284,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

0 comments on commit 22378ec

Please sign in to comment.