|
| 1 | +# |
| 2 | +# Use GitHub releases to promote container-debug-support images |
| 3 | + |
| 4 | +# We use GitHub release triggers to promote the images corresponding to |
| 5 | +# the release commit from staging ($_STAGING) to the production location ($_PROD). |
| 6 | +# Images are tagged with the $SHORT_SHA and $TAG_NAME where appropriate. |
| 7 | +# |
| 8 | +# Release tags ($TAG_NAME) are expected to follow a `vN.N` pattern and are |
| 9 | +# expected to be distinct. The `vN` indicates a major version (e.g., v1.35 -> v1). |
| 10 | +# These release tags are generally expected to be distinct, such that they |
| 11 | +# shouldn't be overwritten by accident. |
| 12 | +# |
| 13 | +# This promotion script copies the long- and short-form images to: |
| 14 | +# |
| 15 | +# 1. $_PROD/$TAG_NAME tagged with `latest` and `$SHORT_SHA` |
| 16 | +# Users can then use a specific release with: |
| 17 | +# ``` |
| 18 | +# skaffold config set --global debug-helpers-registry $_PROD/$TAG_NAME |
| 19 | +# ``` |
| 20 | +# 2. $_PROD/$MAJORVER tagged with `latest`, `$TAG_NAME`, and `$SHORT_SHA`, |
| 21 | +# when $_IS_LATEST is true and $TAG_NAME has a valid major version |
| 22 | +# 3. $_PROD for backward compatibility, tagged with `latest`, `$TAG_NAME`, and `$SHORT_NAME`, |
| 23 | +# when $_IS_LATEST is true and the major version is `v1`. |
| 24 | +# |
| 25 | +# For example, tagging commit 70f0f74 as v1.1 should result in the images being |
| 26 | +# copied over as: |
| 27 | +# |
| 28 | +# 1. gcr.io/k8s-skaffold/skaffold-debug-support/v1.1/<image>:{latest,70f0f74} |
| 29 | +# 2. gcr.io/k8s-skaffold/skaffold-debug-support/v1/<image>:{latest,v1.1,70f0f74} |
| 30 | +# 3. gcr.io/k8s-skaffold/skaffold-debug-support/<image>:{latest,v1.1,70f0f74} |
| 31 | +# |
| 32 | +# The last location (3) occurs because the major version is v1. This copy is to maintain |
| 33 | +# backwards compatibility with the existing versions of Skaffold. When we bump the |
| 34 | +# major version to v2, we will no longer copy images into (3). |
| 35 | +# |
| 36 | +# To test: |
| 37 | +# $ export CLOUDSDK_CORE_PROJECT=bdealwis-playground |
| 38 | +# $ gcloud builds submit --config=hack/cloudbuild-promote.yaml \ |
| 39 | +# --substitutions=SHORT_SHA=999999,TAG_NAME=v1.23,_STAGING=us-central1-docker.pkg.dev/$CLOUDSDK_CORE_PROJECT/junk/skaffold-debug-support,_PROD=gcr.io/$CLOUDSDK_CORE_PROJECT/skaffold-debug-support |
| 40 | +# |
| 41 | +# To replace a previous release with rebuilt images: |
| 42 | +# $ gcloud builds submit --config=hack/cloudbuild-promote.yaml \ |
| 43 | +# --substitutions=SHORT_SHA=xxxx,TAG_NAME=v1.23,_STAGING=us-central1-docker.pkg.dev/$CLOUDSDK_CORE_PROJECT/junk/skaffold-debug-support,_PROD=gcr.io/$CLOUDSDK_CORE_PROJECT/skaffold-debug-support,_IS_LATEST=0 |
| 44 | +# |
| 45 | +options: |
| 46 | + #machineType: 'E2_HIGHCPU_8' |
| 47 | + |
| 48 | +substitutions: |
| 49 | + _STAGING: us-central1-docker.pkg.dev/$PROJECT_ID/skaffold-staging/skaffold-debug-support |
| 50 | + _PROD: gcr.io/$PROJECT_ID/skaffold-debug-support |
| 51 | + _RUNTIMES: go netcore nodejs python |
| 52 | + _IS_LATEST: "1" |
| 53 | + |
| 54 | +steps: |
| 55 | + ################################################################### |
| 56 | + # Validate that $TAG_NAME is an acceptable image component name and tag |
| 57 | + # Regexs from https://github.com/opencontainers/distribution-spec/blob/main/spec.md |
| 58 | + - id: validate-tag |
| 59 | + name: bash |
| 60 | + entrypoint: 'bash' |
| 61 | + args: |
| 62 | + - '-eEuo' |
| 63 | + - 'pipefail' |
| 64 | + - '-c' |
| 65 | + - |- |
| 66 | + if [[ "$TAG_NAME" =~ ^[a-z0-9]+([._-][a-z0-9]+)*$ ]] \ |
| 67 | + && [[ "$TAG_NAME" =~ ^[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}$ ]]; then |
| 68 | + echo "Accepted tag" |
| 69 | + else |
| 70 | + echo "Release tag [$TAG_NAME] is not a valid image name component or image tag" |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + |
| 74 | + ################################################################### |
| 75 | + # Copy the staged images to release loction in $_PROD/$TAG_NAME. |
| 76 | + # This allows users to use a specific release with: |
| 77 | + # skaffold config set --global debug-helpers-registry $_PROD/$TAG_NAME |
| 78 | + # |
| 79 | + # First copy staged images into $_PROD/$TAG_NAME tagged with $SHORT_SHA. |
| 80 | + # If this step fails, then nothing irrevocable has occurred. |
| 81 | + - id: install-release-images |
| 82 | + name: gcr.io/go-containerregistry/gcrane:debug |
| 83 | + entrypoint: /busybox/sh |
| 84 | + args: |
| 85 | + - "-euc" |
| 86 | + - |- |
| 87 | + for runtime in $_RUNTIMES; do |
| 88 | + gcrane copy $_STAGING/$SHORT_SHA/skaffold-debug-$$runtime:latest $_PROD/$TAG_NAME/skaffold-debug-$$runtime:$SHORT_SHA |
| 89 | + gcrane copy $_STAGING/$SHORT_SHA/$$runtime:latest $_PROD/$TAG_NAME/$$runtime:$SHORT_SHA |
| 90 | + done |
| 91 | + # Then install these images by tagging them with `latest`. |
| 92 | + - id: promote-release-images |
| 93 | + name: gcr.io/go-containerregistry/gcrane:debug |
| 94 | + entrypoint: /busybox/sh |
| 95 | + args: |
| 96 | + - "-euc" |
| 97 | + - |- |
| 98 | + for runtime in $_RUNTIMES; do |
| 99 | + gcrane tag $_PROD/$TAG_NAME/skaffold-debug-$$runtime:$SHORT_SHA latest |
| 100 | + gcrane tag $_PROD/$TAG_NAME/$$runtime:$SHORT_SHA latest |
| 101 | + done |
| 102 | + echo "Images promoted to $_PROD/$TAG_NAME" |
| 103 | + |
| 104 | + # Promote to major version (e.g., v1.35 -> v1). |
| 105 | + # If IS_LATEST=1 copy these tagged images into latest. |
| 106 | + - id: promote-to-major-version |
| 107 | + name: gcr.io/go-containerregistry/gcrane:debug |
| 108 | + entrypoint: /busybox/sh |
| 109 | + args: |
| 110 | + - "-euc" |
| 111 | + - |- |
| 112 | + MAJORVER=$$(echo $TAG_NAME | sed -n 's/\(v[0-9][0-9]\)*\.[0-9.]*/\1/p') |
| 113 | + if [ -z "$$MAJORVER" ]; then |
| 114 | + echo "Skipping rest of promotion: Release tag [${TAG_NAME}] does not have [vN.*] major version" |
| 115 | + exit 0 |
| 116 | + fi |
| 117 | +
|
| 118 | + for runtime in $_RUNTIMES; do |
| 119 | + gcrane copy $_STAGING/$SHORT_SHA/skaffold-debug-$$runtime:latest $_PROD/$$MAJORVER/skaffold-debug-$$runtime:$SHORT_SHA |
| 120 | + gcrane copy $_STAGING/$SHORT_SHA/$$runtime:latest $_PROD/$$MAJORVER/$$runtime:$SHORT_SHA |
| 121 | + if [ "$$MAJORVER" = v1 ]; then |
| 122 | + gcrane copy $_STAGING/$SHORT_SHA/skaffold-debug-$$runtime:latest $_PROD/skaffold-debug-$$runtime:$SHORT_SHA |
| 123 | + gcrane copy $_STAGING/$SHORT_SHA/$$runtime:latest $_PROD/$$runtime:$SHORT_SHA |
| 124 | + fi |
| 125 | + done |
| 126 | + for runtime in $_RUNTIMES; do |
| 127 | + gcrane tag $_PROD/$$MAJORVER/skaffold-debug-$$runtime:$SHORT_SHA $TAG_NAME |
| 128 | + gcrane tag $_PROD/$$MAJORVER/$$runtime:$SHORT_SHA $TAG_NAME |
| 129 | + if [ "$$MAJORVER" = v1 ]; then |
| 130 | + gcrane tag $_PROD/skaffold-debug-$$runtime:$SHORT_SHA $TAG_NAME |
| 131 | + gcrane tag $_PROD/$$runtime:$SHORT_SHA $TAG_NAME |
| 132 | + fi |
| 133 | + done |
| 134 | + case "$_IS_LATEST" in |
| 135 | + 0|no|NO|false|FALSE) echo "skipping promotion to latest as _IS_LATEST=${_IS_LATEST}"; exit 0;; |
| 136 | + esac |
| 137 | + |
| 138 | + for runtime in $_RUNTIMES; do |
| 139 | + gcrane tag $_PROD/$$MAJORVER/skaffold-debug-$$runtime:$SHORT_SHA latest |
| 140 | + gcrane tag $_PROD/$$MAJORVER/$$runtime:$SHORT_SHA latest |
| 141 | + done |
| 142 | + echo "Images promoted to $_PROD/$$MAJORVER as latest" |
| 143 | +
|
| 144 | + if [ "$$MAJORVER" = v1 ]; then |
| 145 | + for runtime in $_RUNTIMES; do |
| 146 | + gcrane tag $_PROD/skaffold-debug-$$runtime:$SHORT_SHA latest |
| 147 | + gcrane tag $_PROD/$$runtime:$SHORT_SHA latest |
| 148 | + done |
| 149 | + echo "Images promoted to $_PROD as latest" |
| 150 | + fi |
| 151 | +
|
| 152 | +timeout: 200s |
0 commit comments