Skip to content

Commit b70878e

Browse files
authored
Merge pull request #1965 from GoogleContainerTools/lifecycle-tag
Add cloud build config for lifecycle tagging
2 parents bebaab1 + bbf4a4a commit b70878e

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

.cloudbuild/lifecycle_tag.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset -o xtrace -o pipefail
3+
4+
BAZELISK_VERSION="1.27.0"
5+
BAZELISK_SHA256="e1508323f347ad1465a887bc5d2bfb91cffc232d11e8e997b623227c6b32fb76"
6+
7+
GGCR_VERSION="0.20.7"
8+
GGCR_SHA256="8ef3564d264e6b5ca93f7b7f5652704c4dd29d33935aff6947dd5adefd05953e"
9+
10+
# install gcrane
11+
curl -fsSL "https://github.com/google/go-containerregistry/releases/download/v${GGCR_VERSION}/go-containerregistry_Linux_x86_64.tar.gz" -o ggcr.tar.gz
12+
echo "${GGCR_SHA256} ggcr.tar.gz" | sha256sum --check
13+
tar -xzf ggcr.tar.gz gcrane
14+
chmod a+x gcrane
15+
mv gcrane /usr/bin/gcrane # needs to be on path
16+
17+
# we need jq too
18+
apt-get update
19+
apt-get -y install jq
20+
21+
# install bazelisk (TODO: there's probably a better way to do this)
22+
curl -fsSL "https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-amd64" -o bazelisk
23+
echo "${BAZELISK_SHA256} bazelisk" | sha256sum --check
24+
chmod a+x bazelisk
25+
26+
echo "common --google_default_credentials" >> ~/.bazelrc
27+
echo "common --announce_rc" >> ~/.bazelrc
28+
29+
./bazelisk run :attach_lifecycle_tags --config=release

.cloudbuild/lifecycle_tag.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
timeout: 1800s # 30 minutes
2+
3+
options:
4+
machineType: E2_MEDIUM
5+
logging: CLOUD_LOGGING_ONLY
6+
7+
steps:
8+
- name: gcr.io/cloud-builders/bazel@sha256:70e96d9faec4bab40a9d8d55d6b86ce2657927d8bca6bdc2dcb21a82b66dbdf7 # 5.4.0
9+
env:
10+
- PROJECT_ID=${PROJECT_ID}
11+
- REGISTRY=gcr.io
12+
entrypoint: bash
13+
args: [".cloudbuild/lifecycle_tag.sh"]

private/tools/lifecycle/tag.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function tag_update() {
4343
(($now | tonumber) - (.value.timeUploadedMs | tonumber) > 172800000)
4444
) | .key
4545
');
46+
background_pid=$!
47+
wait "$background_pid"
4648

4749
echo "tagging ${#targets[@]} images of $image"
4850

@@ -58,14 +60,17 @@ function tag_deprecate() {
5860
images_json=$(gcrane ls "$image" --json)
5961

6062
# get all hashes for all images don't have the deprecated tag
63+
# this is only for wholesale deprecation of an image
6164
readarray -t targets < <(echo "$images_json" | jq -er '
6265
.manifest | to_entries | sort_by(.value.timeUploadedMs|tonumber) | .[] | select(
6366
.value.tag // [] | all(test("deprecated-public-image-[a-f0-9]{64}$") | not)
6467
) | .key
6568
');
69+
background_pid=$!
70+
wait "$background_pid"
6671

6772
echo "tagging ${#targets[@]} images of $image"
68-
echo "disabled for now, edit out comment"
73+
echo "disabled for now, edit out comment, be careful about builds happening, this doesn't account for them"
6974
# exec_tag "$image" "$tag_prefix" targets
7075
}
7176

0 commit comments

Comments
 (0)