Repository navigation
Expand file tree
/
Copy pathgcp_teardown.sh
More file actions
executable file
·69 lines (59 loc) · 2.18 KB
/
Copy pathgcp_teardown.sh
File metadata and controls
executable file
·69 lines (59 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
#
# Remove everything gcp_run.sh created. Safe to run more than once.
#
# ./gcp_teardown.sh # keep the bucket (results live there)
# ./gcp_teardown.sh --all # delete the bucket too
#
set -uo pipefail
# Same reason as gcp_run.sh: a gcloud prompt behind a redirect looks like a hang.
export CLOUDSDK_CORE_DISABLE_PROMPTS=1
PROJECT="${PROJECT:-$(gcloud config get-value project 2>/dev/null || true)}"
REGION="${REGION:-us-central1}"
TEMPLATE_NAME="${TEMPLATE_NAME:-ct-pulse-l4}"
[[ -n "$PROJECT" && "$PROJECT" != "(unset)" ]] || {
echo "No project set. Run: gcloud config set project YOUR_PROJECT"; exit 1; }
BUCKET="ct-property-pulse-${PROJECT}"
say() { printf '\n\033[1m==> %s\033[0m\n' "$*"; }
ok() { printf ' \033[32m+ %s\033[0m\n' "$*"; }
warn() { printf ' \033[33m! %s\033[0m\n' "$*"; }
say "Runtimes still alive in $REGION (executions should leave none)"
RUNTIMES="$(gcloud colab runtimes list --region="$REGION" --project="$PROJECT" \
--format='value(name)' </dev/null 2>/dev/null || true)"
if [[ -z "$RUNTIMES" ]]; then
ok "none"
else
while IFS= read -r r; do
[[ -n "$r" ]] || continue
warn "still running: ${r##*/}"
echo " gcloud colab runtimes delete ${r##*/} --region=$REGION"
done <<<"$RUNTIMES"
fi
say "Deleting runtime template '$TEMPLATE_NAME'"
if gcloud colab runtime-templates delete "$TEMPLATE_NAME" \
--region="$REGION" --project="$PROJECT" --quiet </dev/null 2>/dev/null; then
ok "deleted"
else
warn "not found (or already gone)"
fi
say "Deleting Secret Manager secret 'hf-token'"
if gcloud secrets delete hf-token --project="$PROJECT" --quiet </dev/null 2>/dev/null; then
ok "deleted"
else
warn "not found (or already gone)"
fi
if [[ "${1:-}" == "--all" ]]; then
say "Deleting bucket gs://$BUCKET AND EVERY RESULT IN IT"
printf ' Type the bucket name to confirm: '
read -r confirm </dev/tty
if [[ "$confirm" == "$BUCKET" ]]; then
gcloud storage rm -r "gs://$BUCKET" && ok "deleted"
else
warn "name did not match - keeping the bucket"
fi
else
say "Keeping gs://$BUCKET"
echo " Your run outputs are in it. To remove: ./gcp_teardown.sh --all"
fi
echo
echo "Teardown complete."