UNPKG

1.09 kBPlain TextView Raw
1#!/usr/bin/env bash
2#
3## Deprecate old images except the latest one
4
5set -e
6set -x
7
8opskit_path="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
9source ${opskit_path}/lib/common.sh
10
11if [[ -z $1 ]]; then
12 echo "Missing image family name"
13 exit 1;
14fi
15
16family=$1
17## Get the latest image from family
18latest_image=$(gcloud compute images describe-from-family "${family}" \
19 --format='value(name)')
20if [[ -z "${latest_image}" ]]; then
21 echo "No ${family} image exists."
22 exit 1;
23fi
24
25## Deprecate old images and skip latest one
26echo "Attempting to deprecate all ${family} images except the latest one...."
27images="$(gcloud compute images list --regexp=^${family}.* \
28 --format='value(name)')"
29if [ -z "${images}" ]; then
30 echo "No ${family} image available"
31 exit 1;
32fi
33
34echo Available images: ${images}
35for image in ${images}; do
36 if [[ "${image}" -ne "${latest_image}" ]]; then
37 gcloud compute images deprecate "${image}" \
38 --state=DEPRECATED --replacement="${latest_image}"
39 fi
40done
41