From c8b7b4909e0dc8a8aff07b2a69113d9fd14d91cc Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Thu, 27 Jul 2023 09:47:11 +0800 Subject: [PATCH] combine docker push and gcr push Signed-off-by: Lyndon-Li --- .github/workflows/push.yml | 23 +++++++---------------- Makefile | 5 +++++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index f4a66e7d4..bc41d0210 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -60,6 +60,13 @@ jobs: files: coverage.out verbose: true + # Use the JSON key in secret to login gcr.io + - uses: 'docker/login-action@v2' + with: + registry: 'gcr.io' # or REGION.docker.pkg.dev + username: '_json_key' + password: '${{ secrets.GCR_SA_KEY }}' + # Only try to publish the container image from the root repo; forks don't have permission to do so and will always get failures. - name: Publish container image if: github.repository == 'vmware-tanzu/velero' @@ -91,19 +98,3 @@ jobs: uploader ${VELERO_RESTORE_HELPER_IMAGE_FILE} ${GCS_BUCKET} uploader ${VELERO_IMAGE_BACKUP_FILE} ${GCS_BUCKET} uploader ${VELERO_RESTORE_HELPER_IMAGE_BACKUP_FILE} ${GCS_BUCKET} - - # Use the JSON key in secret to login gcr.io - - uses: 'docker/login-action@v1' - with: - registry: 'gcr.io' # or REGION.docker.pkg.dev - username: '_json_key' - password: '${{ secrets.GCR_SA_KEY }}' - - # Push image to GCR to facilitate some environments that have rate limitation to docker hub, e.g. vSphere. - - name: Publish container image to GCR - if: github.repository == 'vmware-tanzu/velero' - run: | - sudo swapoff -a - sudo rm -f /mnt/swapfile - docker image prune -a --force - REGISTRY=gcr.io/velero-gcp ./hack/docker-push.sh diff --git a/Makefile b/Makefile index c27112a2c..250b21b2f 100644 --- a/Makefile +++ b/Makefile @@ -22,9 +22,11 @@ PKG := github.com/vmware-tanzu/velero # Where to push the docker image. REGISTRY ?= velero +GCR_REGISTRY ?= gcr.io/velero-gcp # Image name IMAGE ?= $(REGISTRY)/$(BIN) +GCR_IMAGE ?= $(GCR_REGISTRY)/$(BIN) # We allow the Dockerfile to be configurable to enable the use of custom Dockerfiles # that pull base images from different registries. @@ -66,8 +68,10 @@ TAG_LATEST ?= false ifeq ($(TAG_LATEST), true) IMAGE_TAGS ?= $(IMAGE):$(VERSION) $(IMAGE):latest + GCR_IMAGE_TAGS ?= $(GCR_IMAGE):$(VERSION) $(GCR_IMAGE):latest else IMAGE_TAGS ?= $(IMAGE):$(VERSION) + GCR_IMAGE_TAGS ?= $(GCR_IMAGE):$(VERSION) endif ifeq ($(shell docker buildx inspect 2>/dev/null | awk '/Status/ { print $$2 }'), running) @@ -186,6 +190,7 @@ endif --output=type=$(BUILDX_OUTPUT_TYPE) \ --platform $(BUILDX_PLATFORMS) \ $(addprefix -t , $(IMAGE_TAGS)) \ + $(addprefix -t , $(GCR_IMAGE_TAGS)) \ --build-arg=GOPROXY=$(GOPROXY) \ --build-arg=PKG=$(PKG) \ --build-arg=BIN=$(BIN) \