From 23458708d376e6e3c54a2ff375517f2144484c6c Mon Sep 17 00:00:00 2001 From: Yuwen Ma Date: Thu, 2 May 2019 17:11:12 -0700 Subject: [PATCH] Some fix to Makefile "push". --- Makefile | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 2389c7347..c01fcb89e 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,10 @@ # Common User-Settable Flags # ========================== -PREFIX?=gcr.io/google_containers +# Push to staging registry. +PREFIX?=staging-k8s.gcr.io FLAGS= ARCH?=amd64 GOLANG_VERSION?=1.10 -# You can set this variable for testing and the built image will also be tagged with this name -IMAGE_NAME?=$(PREFIX)/metrics-server-$(ARCH):$(VERSION) # by default, build the current arch's binary # (this needs to be pre-include, for some reason) @@ -14,7 +13,6 @@ all: _output/$(ARCH)/metrics-server # Constants # ========= ALL_ARCHITECTURES=amd64 arm arm64 ppc64le s390x -ML_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x # Calculated Variables # ==================== @@ -26,7 +24,7 @@ BASEIMAGE?=gcr.io/distroless/static:latest # Rules # ===== -.PHONY: all test-unit container container-* clean container-only container-only-* tmp-dir push do-push-* sub-push-* +.PHONY: all test-unit container container-* clean container-only container-only-* tmpdir push do-push-* sub-push-* # Build Rules # ----------- @@ -46,17 +44,18 @@ _output/%/metrics-server: $(src_deps) pkg/generated/openapi/zz_generated.openapi # build a container using containerized build (the current arch by default) container: container-$(ARCH) -container-%: pkg/generated/openapi/zz_generated.openapi.go tmpdir +container-%: pkg/generated/openapi/zz_generated.openapi.go tmpdir-% # Run the build in a container in order to have reproducible builds docker run --rm -v $(TEMP_DIR):/build -v $(REPO_DIR):/go/src/github.com/kubernetes-incubator/metrics-server -w /go/src/github.com/kubernetes-incubator/metrics-server golang:$(GOLANG_VERSION) /bin/bash -c "\ - GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags \"$(LDFLAGS)\" -o /build/metrics-server github.com/kubernetes-incubator/metrics-server/cmd/metrics-server" + GOARCH=$* CGO_ENABLED=0 go build -ldflags \"$(LDFLAGS)\" -o /build/metrics-server github.com/kubernetes-incubator/metrics-server/cmd/metrics-server" + # copy the base Dockerfile into the temp dir, and set the base image cp deploy/docker/Dockerfile $(TEMP_DIR) sed -i -e "s|BASEIMAGE|$(BASEIMAGE)|g" $(TEMP_DIR)/Dockerfile # run the actual build - docker build --pull -t $(IMAGE_NAME) $(TEMP_DIR) + docker build --pull -t $(PREFIX)/metrics-server-$*:$(VERSION) $(TEMP_DIR) # remove our TEMP_DIR, as needed rm -rf $(TEMP_DIR) @@ -64,14 +63,14 @@ container-%: pkg/generated/openapi/zz_generated.openapi.go tmpdir # build a container using a locally-built binary (the current arch by default) container-only: container-only-$(ARCH) -container-only-%: _output/$(ARCH)/metrics-server tmpdir +container-only-%: _output/$(ARCH)/metrics-server tmpdir-% # copy the base Dockerfile and binary into the temp dir, and set the base image cp deploy/docker/Dockerfile $(TEMP_DIR) - cp _output/$(ARCH)/metrics-server $(TEMP_DIR) + cp _output/$*/metrics-server $(TEMP_DIR) sed -i -e "s|BASEIMAGE|$(BASEIMAGE)|g" $(TEMP_DIR)/Dockerfile # run the actual build - docker build --pull -t $(IMAGE_NAME) $(TEMP_DIR) + docker build --pull -t $(PREFIX)/metrics-server-$*:$(VERSION) $(TEMP_DIR) # remove our TEMP_DIR, as needed rm -rf $(TEMP_DIR) @@ -85,7 +84,7 @@ do-push-%: docker push $(PREFIX)/metrics-server-$*:$(VERSION) # push alternate tags -ifeq ($(ARCH),amd64) +ifeq ($*,amd64) # TODO: Remove this and push the manifest list as soon as it's working docker tag $(PREFIX)/metrics-server-$*:$(VERSION) $(PREFIX)/metrics-server:$(VERSION) docker push $(PREFIX)/metrics-server:$(VERSION) @@ -126,5 +125,5 @@ endif # set up a temporary director when we need it # it's the caller's responsibility to clean it up -tmpdir: +tmpdir-%: $(eval TEMP_DIR:=$(shell mktemp -d /tmp/metrics-server.XXXXXX))