forked from alexvanboxel/airflow-gcp-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcp_setup.sh
executable file
·39 lines (37 loc) · 977 Bytes
/
gcp_setup.sh
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
#!/bin/bash
#
# Prepare GCP project environment by creating the required bucket and dataset.
#############################################################################
# Run the first command, return if succeed. Otherwise run the second command.
# Arguments:
# $1: first command
# $2: second command
# Returns:
# None
#############################################################################
check_and_run() {
echo "Executing: "$1
unset IFS
$1
if [[ $? -ne 0 ]]; then
echo "Executing: "$2
$2
if [[ $? -ne 0 ]]; then
echo "Fail to set up the GCP environment."
exit 1
fi
fi
echo "Success."
}
echo "Preparing GCP environment..."
commands_to_run=(
"gsutil ls gs://airflow-gcp-smoke, gsutil mb gs://airflow-gcp-smoke"
"bq ls airflow, bq mk airflow"
"bq ls airflow_temp, bq mk airflow_temp" )
for command in "${commands_to_run[@]}"
do
IFS=","
set $command
check_and_run $1 $2
done
echo "GCP environment is ready."