From e51a9d4e1edd909f3ae040b8adcb50ecf46d7c32 Mon Sep 17 00:00:00 2001 From: Xun Jiang/Bruce Jiang <59276555+blackpiglet@users.noreply.github.com> Date: Tue, 18 Jul 2023 08:05:57 +0800 Subject: [PATCH] Integrate pushing to docker hub and gcr.io in one docker build and push command. (#6199) Signed-off-by: Xun Jiang Signed-off-by: Xun Jiang/Bruce Jiang <59276555+blackpiglet@users.noreply.github.com> Co-authored-by: Xun Jiang --- .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 e04c325494..b1af90a379 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 82b5241065..0bdf6e8d78 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) @@ -183,6 +187,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) \