forked from dora-team/fourkeys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.sh
More file actions
executable file
·60 lines (47 loc) · 1.9 KB
/
Copy pathcleanup.sh
File metadata and controls
executable file
·60 lines (47 loc) · 1.9 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
#!/bin/bash
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Bulk delete: if flag `-b` is specified, delete all projects with IDs that
# match patterns: fourkeys_* or helloworld_*
bulk_delete=0
while getopts ":b" opt; do
case ${opt} in
b ) bulk_delete=1 ;;
\? ) echo "Usage: ./cleanup.sh [-b]" ;;
esac
done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [[ ${bulk_delete} -gt 0 ]]
then
# disregard env variables and delete all projects matching "fourkeys-XXXXXX" or "helloworld-XXXXXX"
projects=$(gcloud projects list --filter="projectId~^fourkeys-\d{6}$ OR projectId~^helloworld-\d{6}$" --format="value(projectId)")
else
[[ -f "$DIR/env.sh" ]] && echo "Importing environment from $DIR/env.sh..." && . $DIR/env.sh
projects="${FOURKEYS_PROJECT}"
if [[ ! -z "${HELLOWORLD_PROJECT}" && ! -z "$(gcloud projects list --filter="projectId=${HELLOWORLD_PROJECT}" --format="value(projectId)")" ]]
then
projects="${FOURKEYS_PROJECT} ${HELLOWORLD_PROJECT}"
fi
fi
if [ ! -z "${projects}" ]; then echo "Deleting projects..."; else echo "no projects to delete."; fi
for project in $projects; do
echo "delete project ${project}..."
gcloud projects delete "${project}"
done
if [ ! -z "${PARENT_PROJECT}" ]
then
gcloud config set project ${PARENT_PROJECT}
fi
# purge env.sh file, if it exists
[[ -f "$DIR/env.sh" ]] && rm env.sh