rollout/cli_tools_cloudbuild_rollback.yaml (33 lines of code) (raw):

timeout: 1800s steps: # Rollback given tools to given locations. Expect 2 vars substitutions, examples: # 1. $_REGIONS="us;us-east1;us-east2" # 2. $_TOOLS="gve_vm_image_import;gce_vm_image_export" # The script will pull the built docker images with "prev-release" tag from gcr.io (container registry), # and then push to artifacts registry (e.g. us-east1-docker.pkg.dev/compute-image-tools/wrappers/gce_vm_image_import) # with 3 tags: the workflow execution ID, the commit SHA, and the "release". # 1. The workflow execution ID is used to track which workflow produced the image. # It's specifically useful when the original workflow was failed and we resumed it. # 2. The commit SHA is used to track which version of source code produced the image. # 3. The "release" tag marks it as the current effective image. - name: 'google/cloud-sdk:alpine' args: - 'bash' - '-c' - | REGIONS_ARR=$(echo "$_REGIONS" | tr ";" "\n") TOOLS_ARR=$(echo "$_TOOLS" | tr ";" "\n") exit_on_error() { ERR=$$1 if [[ $$ERR != 0 ]]; then echo "Rollback failed with exit code $$ERR. Please check the error message, debug and rerun." exit "$$ERR" fi } for _REGION in $$REGIONS_ARR do for _TOOL in $$TOOLS_ARR do echo "--> Rollback... $$_TOOL -> $$_REGION" gcloud container images add-tag $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/wrappers/$$_TOOL:prev-release $$_REGION-docker.pkg.dev/$_IMAGE_PROJECT/wrappers/$$_TOOL:release -q exit_on_error $$? done echo "----> Rollback all tools for $$_REGION done." done for _TOOL in $$TOOLS_ARR do echo "--> Rollback... $$_TOOL -> gcr.io" gcloud container images add-tag gcr.io/$_IMAGE_PROJECT/$$_TOOL:prev-release gcr.io/$_IMAGE_PROJECT/$$_TOOL:release -q exit_on_error $$? done echo "----> Rollback all tools for gcr.io done."