From ee5595f5be68ae05d1bfa3c6f784905cbfbbce44 Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Fri, 31 Jan 2020 22:56:55 -0300 Subject: [PATCH] Cleanup main makefile and remove the need of sed (#4995) --- Makefile | 46 ++++++++++++---------------------------------- build/build.sh | 1 + rootfs/Dockerfile | 15 +++++++++------ 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 599634c5f..d897d94e8 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ endif # Allow limiting the scope of the e2e tests. By default run everything FOCUS ?= .* # number of parallel test -E2E_NODES ?= 10 +E2E_NODES ?= 12 # slow test only if takes > 50s SLOW_E2E_THRESHOLD ?= 50 # run e2e test suite with tests that check for memory leaks? (default is false) @@ -53,28 +53,18 @@ GIT_COMMIT ?= git-$(shell git rev-parse --short HEAD) PKG = k8s.io/ingress-nginx -ALL_ARCH = amd64 arm arm64 - 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} -GOHOSTOS ?= $(shell go env GOHOSTOS) -GOARCH = ${ARCH} -GOOS = linux +BASE_IMAGE ?= quay.io/kubernetes-ingress-controller/nginx +BASE_TAG ?= 26f574dc279aa853736d7f7249965e90e47171d6 + +GOARCH=$(ARCH) GOBUILD_FLAGS := -v -# fix sed for osx -SED_I ?= sed -i -ifeq ($(GOHOSTOS),darwin) - SED_I=sed -i '' -endif - # use vendor directory instead of go modules https://github.com/golang/go/wiki/Modules GO111MODULE=off @@ -94,12 +84,6 @@ sub-container-%: sub-push-%: ## Publish image for a particular arch. $(MAKE) ARCH=$* push -.PHONY: all-container -all-container: $(addprefix sub-container-,$(ALL_ARCH)) ## Build image for amd64, arm and arm64. - -.PHONY: all-push -all-push: $(addprefix sub-push-,$(ALL_ARCH)) ## Publish images for amd64, arm and arm64. - .PHONY: container container: clean-container .container-$(ARCH) ## Build image for a particular arch. @@ -111,11 +95,7 @@ container: clean-container .container-$(ARCH) ## Build image for a particular ar 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|quay.io/kubernetes-ingress-controller/nginx-$(ARCH):$(BASEIMAGE_TAG)|g" $(DOCKERFILE) - $(SED_I) "s|VERSION|$(TAG)|g" $(DOCKERFILE) + cp -RP rootfs/* $(TEMP_DIR)/rootfs echo "Building docker image ($(ARCH))..." # buildx assumes images are multi-arch @@ -125,12 +105,14 @@ container: clean-container .container-$(ARCH) ## Build image for a particular ar --no-cache \ --progress plain \ --platform linux/$(ARCH) \ - -t $(MULTI_ARCH_IMAGE):$(TAG) $(TEMP_DIR)/rootfs + --build-arg BASE_IMAGE="$(BASE_IMAGE)-$(ARCH):$(BASE_TAG)" \ + --build-arg VERSION="$(TAG)" \ + -t $(REGISTRY)/nginx-ingress-controller-${ARCH}:$(TAG) $(TEMP_DIR)/rootfs .PHONY: clean-container clean-container: ## Removes local image - echo "removing old image $(MULTI_ARCH_IMAGE):$(TAG)" - @docker rmi -f $(MULTI_ARCH_IMAGE):$(TAG) || true + echo "removing old image $(BASE_IMAGE)-$(ARCH):$(TAG)" + @docker rmi -f $(BASE_IMAGE)-$(ARCH):$(TAG) || true .PHONY: push push: .push-$(ARCH) ## Publish image for a particular arch. @@ -138,7 +120,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 $(BASE_IMAGE)-$(ARCH):$(TAG) .PHONY: build build: check-go-version ## Build ingress controller, debug tool and pre-stop hook. @@ -235,10 +217,6 @@ cover: check-go-version ## Run go coverage unit tests. vet: @go vet $(shell go list ${PKG}/internal/... | grep -v vendor) -.PHONY: release -release: all-container all-push ## Build and publish images of the ingress controller. - echo "done" - .PHONY: check_dead_links check_dead_links: ## Check if the documentation contains dead links. @docker run -t \ diff --git a/build/build.sh b/build/build.sh index 45cae4e88..e8138c6a6 100755 --- a/build/build.sh +++ b/build/build.sh @@ -44,6 +44,7 @@ if [ "$missing" = true ]; then fi export CGO_ENABLED=0 +export GOARCH=${ARCH} go build \ "${GOBUILD_FLAGS}" \ diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile index 64b471f42..fb0613f2c 100644 --- a/rootfs/Dockerfile +++ b/rootfs/Dockerfile @@ -12,14 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM --platform=$BUILDPLATFORM BASEIMAGE +ARG BASE_IMAGE +ARG VERSION -LABEL org.opencontainers.image.title='NGINX Ingress Controller for Kubernetes' -LABEL org.opencontainers.image.documentation='https://kubernetes.github.io/ingress-nginx/' +FROM --platform=$BUILDPLATFORM ${BASE_IMAGE} + +LABEL org.opencontainers.image.title="NGINX Ingress Controller for Kubernetes" +LABEL org.opencontainers.image.documentation="https://kubernetes.github.io/ingress-nginx/" LABEL org.opencontainers.image.source="https://github.com/kubernetes/ingress-nginx" -LABEL org.opencontainers.image.vendor='The Kubernetes Authors' -LABEL org.opencontainers.image.licenses='Apache-2.0' -LABEL org.opencontainers.image.version='VERSION' +LABEL org.opencontainers.image.vendor="The Kubernetes Authors" +LABEL org.opencontainers.image.licenses="Apache-2.0" +LABEL org.opencontainers.image.version="${VERSION}" WORKDIR /etc/nginx