diff --git a/.gitignore b/.gitignore index c5ac70a0f7..8aa392342f 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ help.txt # jsonnet dependency management /scripts/vendor + +# Image build tool +manifest-tool diff --git a/Makefile b/Makefile index 108f4b8957..5233e2a10e 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,6 @@ GOLANGCI_VERSION := v1.25.0 HAS_GOLANGCI := $(shell which golangci-lint) IMAGE = $(REGISTRY)/kube-state-metrics -MULTI_ARCH_IMG = $(IMAGE)-$(ARCH) validate-modules: @echo "- Verifying that the dependencies have expected content..." @@ -59,13 +58,10 @@ doccheck: generate @cd docs; for doc in *.md; do if [ "$$doc" != "README.md" ] && ! grep -q "$$doc" *.md; then echo "ERROR: No link to documentation file $${doc} detected"; exit 1; fi; done @echo OK -build-local: clean - GOOS=$(shell uname -s | tr A-Z a-z) GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "-s -w -X ${PKG}/version.Release=${TAG} -X ${PKG}/version.Commit=${Commit} -X ${PKG}/version.BuildDate=${BuildDate}" -o kube-state-metrics - build: clean kube-state-metrics kube-state-metrics: - ${DOCKER_CLI} run --rm -v "${PWD}:/go/src/k8s.io/kube-state-metrics" -w /go/src/k8s.io/kube-state-metrics golang:${GO_VERSION} make build-local + GOOS=$(shell uname -s | tr A-Z a-z) GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "-s -w -X ${PKG}/version.Release=${TAG} -X ${PKG}/version.Commit=${Commit} -X ${PKG}/version.BuildDate=${BuildDate}" -o kube-state-metrics test-unit: clean build GOOS=$(shell uname -s | tr A-Z a-z) GOARCH=$(ARCH) $(TESTENVVAR) go test --race $(FLAGS) $(PKGS) @@ -84,41 +80,57 @@ TEMP_DIR := $(shell mktemp -d) all: all-container sub-container-%: - $(MAKE) --no-print-directory ARCH=$* container + # 'clean' is necessary since build process needs to overwrite kube-state-metrics binary. Otherwise all images end up with binary made for one architecture + $(MAKE) --no-print-directory ARCH=$* clean .container-$* sub-push-%: - $(MAKE) --no-print-directory ARCH=$* push + # 'clean' is necessary since build process needs to overwrite kube-state-metrics binary. Otherwise all images end up with binary made for one architecture + $(MAKE) --no-print-directory ARCH=$* clean .quay-push-$* all-container: $(addprefix sub-container-,$(ALL_ARCH)) all-push: $(addprefix sub-push-,$(ALL_ARCH)) -container: .container-$(ARCH) -.container-$(ARCH): kube-state-metrics - cp -r * "${TEMP_DIR}" - ${DOCKER_CLI} build -t $(MULTI_ARCH_IMG):$(TAG) "${TEMP_DIR}" - ${DOCKER_CLI} tag $(MULTI_ARCH_IMG):$(TAG) $(MULTI_ARCH_IMG):latest - rm -rf "${TEMP_DIR}" +manifest-tool: + curl -fsSL https://github.com/estesp/manifest-tool/releases/download/v1.0.2/manifest-tool-linux-amd64 > ./manifest-tool + chmod +x ./manifest-tool + +comma:= , +empty:= +space:= $(empty) $(empty) +manifest-push: manifest-tool + ./manifest-tool push from-args --platforms $(subst $(space),$(comma),$(addprefix linux/,$(ALL_ARCH))) --template $(IMAGE):$(TAG)-ARCH --target $(IMAGE):$(TAG) + ./manifest-tool push from-args --platforms $(subst $(space),$(comma),$(addprefix linux/,$(ALL_ARCH))) --template $(IMAGE):latest-ARCH --target $(IMAGE):latest +release-images: all-push manifest-push + +container: .container-$(ARCH) ifeq ($(ARCH), amd64) # Adding check for amd64 - ${DOCKER_CLI} tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG) - ${DOCKER_CLI} tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):latest + ${DOCKER_CLI} tag $(IMAGE):$(TAG)-$(ARCH) $(IMAGE):$(TAG) + ${DOCKER_CLI} tag $(IMAGE):$(TAG)-$(ARCH) $(IMAGE):latest endif +.container-%: kube-state-metrics + cp -r * "${TEMP_DIR}" + ${DOCKER_CLI} build -t $(IMAGE):$(TAG)-$* "${TEMP_DIR}" + ${DOCKER_CLI} tag $(IMAGE):$(TAG)-$* $(IMAGE):latest-$* + rm -rf "${TEMP_DIR}" + quay-push: .quay-push-$(ARCH) -.quay-push-$(ARCH): .container-$(ARCH) - ${DOCKER_CLI} push $(MULTI_ARCH_IMG):$(TAG) - ${DOCKER_CLI} push $(MULTI_ARCH_IMG):latest ifeq ($(ARCH), amd64) ${DOCKER_CLI} push $(IMAGE):$(TAG) ${DOCKER_CLI} push $(IMAGE):latest endif -push: .push-$(ARCH) -.push-$(ARCH): .container-$(ARCH) - gcloud docker -- push $(MULTI_ARCH_IMG):$(TAG) - gcloud docker -- push $(MULTI_ARCH_IMG):latest +.quay-push-%: .container-% + ${DOCKER_CLI} push $(IMAGE):$(TAG)-$* + ${DOCKER_CLI} push $(IMAGE):latest-$* + +push: .push-% +.push-%: .container-% + gcloud docker -- push $(IMAGE):$(TAG)-$* + gcloud docker -- push $(IMAGE):latest-$* ifeq ($(ARCH), amd64) gcloud docker -- push $(IMAGE):$(TAG) gcloud docker -- push $(IMAGE):latest @@ -131,7 +143,7 @@ clean: e2e: ./tests/e2e.sh -generate: build-local +generate: build @echo ">> generating docs" @./scripts/generate-help-text.sh @$(GOPATH)/bin/embedmd -w `find . -path ./vendor -prune -o -name "*.md" -print` @@ -164,4 +176,4 @@ install-tools: @echo Installing tools from tools.go @cat tools/tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install % -.PHONY: all build build-local all-push all-container test-unit test-benchmark-compare container push quay-push clean e2e validate-modules shellcheck licensecheck lint generate embedmd +.PHONY: all build all-push all-container all-manifest test-unit test-benchmark-compare container push quay-push manifest-push clean e2e validate-modules shellcheck licensecheck lint generate embedmd diff --git a/RELEASE.md b/RELEASE.md index af3bb00dcc..a5a4fd2159 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -33,7 +33,7 @@ Maintaining the release branches for older minor releases happens on a best effo * Cut the new release branch, i.e., `release-1.2`, or merge/cherry-pick changes onto the minor release branch you intend to tag the release on * Cut the new release tag, i.e., `v1.2.0-rc.0` * Create issue requesting for image release to `k8s.gcr.io` (or to `staging-k8s.gcr.io` in case of release candidates) and assign it to one of Googlers (@serathius, @loburm) -* Build and push newest image to `quay.io`(@brancz) +* Build and push newest image to `quay.io` - `make release-images` (@brancz) ## Stable release diff --git a/tests/e2e.sh b/tests/e2e.sh index acad3c2d4a..6abc942711 100755 --- a/tests/e2e.sh +++ b/tests/e2e.sh @@ -113,7 +113,7 @@ make build # query kube-state-metrics image tag make container docker images -a -KUBE_STATE_METRICS_IMAGE_TAG=$(docker images -a|grep 'quay.io/coreos/kube-state-metrics'|grep -v 'latest'|awk '{print $2}'|sort -u) +KUBE_STATE_METRICS_IMAGE_TAG=$(docker images -a|grep 'quay.io/coreos/kube-state-metrics'|grep -v 'latest'|awk '{print $2}'|sort -u| head -n1) echo "local kube-state-metrics image tag: $KUBE_STATE_METRICS_IMAGE_TAG" # update kube-state-metrics image tag in deployment.yaml