summaryrefslogtreecommitdiff
path: root/contrib/imgts/entrypoint.sh
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-04 19:18:10 +0100
committerGitHub <noreply@github.com>2019-02-04 19:18:10 +0100
commit465e19b555abb03d465dc448b169ea1661eb8cce (patch)
tree987f80b6c5e8a51f167b624d739b31be1ef9c869 /contrib/imgts/entrypoint.sh
parentd5593b8e718a1ca86380faa072c654f791b18bbc (diff)
parent01e609d460ac9c49246dcb10b1433e2b00b20981 (diff)
downloadpodman-465e19b555abb03d465dc448b169ea1661eb8cce.tar.gz
podman-465e19b555abb03d465dc448b169ea1661eb8cce.tar.bz2
podman-465e19b555abb03d465dc448b169ea1661eb8cce.zip
Merge pull request #2213 from cevich/cirrus_imgts_container
[skip ci] Cirrus: Container for tracking image use
Diffstat (limited to 'contrib/imgts/entrypoint.sh')
-rwxr-xr-xcontrib/imgts/entrypoint.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/contrib/imgts/entrypoint.sh b/contrib/imgts/entrypoint.sh
new file mode 100755
index 000000000..65a76d8e4
--- /dev/null
+++ b/contrib/imgts/entrypoint.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+set -e
+
+RED="\e[1;36;41m"
+YEL="\e[1;33;44m"
+NOR="\e[0m"
+
+die() {
+ echo -e "$2" >&2
+ exit "$1"
+}
+
+SENTINEL="__unknown__" # default set in dockerfile
+
+[[ "$GCPJSON" != "$SENTINEL" ]] || \
+ die 1 "Must specify service account JSON in \$GCPJSON"
+[[ "$GCPNAME" != "$SENTINEL" ]] || \
+ die 2 "Must specify service account name in \$GCPNAME"
+[[ "$GCPPROJECT" != "$SENTINEL" ]] || \
+ die 4 "Must specify GCP Project ID in \$GCPPROJECT"
+[[ -n "$GCPPROJECT" ]] || \
+ die 5 "Must specify non-empty GCP Project ID in \$GCPPROJECT"
+[[ "$IMGNAMES" != "$SENTINEL" ]] || \
+ die 6 "Must specify space separated list of GCE image names in \$IMGNAMES"
+[[ "$BUILDID" != "$SENTINEL" ]] || \
+ die 7 "Must specify the number of current build in \$BUILDID"
+[[ "$REPOREF" != "$SENTINEL" ]] || \
+ die 8 "Must specify a PR number or Branch name in \$REPOREF"
+
+ARGS="--update-labels=last-used=$(date +%s)"
+# optional
+[[ -z "$BUILDID" ]] || ARGS="$ARGS --update-labels=build-id=$BUILDID"
+[[ -z "$REPOREF" ]] || ARGS="$ARGS --update-labels=repo-ref=$REPOREF"
+
+gcloud config set account "$GCPNAME"
+gcloud config set project "$GCPPROJECT"
+echo "$GCPJSON" > /tmp/gcp.json
+gcloud auth activate-service-account --key-file=/tmp/gcp.json || rm /tmp/gcp.json
+for image in $IMGNAMES
+do
+ gcloud compute images update "$image" $ARGS &
+done
+set +e # Actual update failures are only warnings
+wait || die 0 "${RED}WARNING:$NOR ${YEL}Failed to update labels on one or more images:$NOR '$IMGNAMES'"