-
Notifications
You must be signed in to change notification settings - Fork 9
/
commands.sh
executable file
·103 lines (90 loc) · 2.44 KB
/
commands.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
source .env
init(){
cd cloudflare && terraform init \
&& cd records && terraform init \
&& cd ../workers/blue && terraform init \
&& cd ../green && terraform init \
&& cd ../proxy && terraform init
}
setup_cloudflare(){
cd cloudflare && \
TF_VAR_cloudflare_email=${ACCOUNT_EMAIL} \
TF_VAR_cloudflare_token=${ACCOUNT_AUTH_KEY} \
TF_VAR_proxy_domain=${PROXY_DOMAIN} \
TF_VAR_blue_domain=${BLUE_DOMAIN} \
TF_VAR_green_domain=${GREEN_DOMAIN} \
TF_VAR_default_origin=${DEFAULT_ORIGIN} \
terraform apply
}
records(){
cd cloudflare/records && \
TF_VAR_cloudflare_email=${ACCOUNT_EMAIL} \
TF_VAR_cloudflare_token=${ACCOUNT_AUTH_KEY} \
terraform apply
}
deploy_worker(){
if [[ $1 == "blue" || $1 == "green" ]]; then
COLOR=$1 npm run build-worker \
&& cd cloudflare/workers/${1} \
&& TF_VAR_cloudflare_email=${ACCOUNT_EMAIL} \
TF_VAR_cloudflare_token=${ACCOUNT_AUTH_KEY} \
terraform apply
else
echo "You must call this function with a color (blue or green). Try again with ./commands.sh deploy_worker blue/green"
exit 1
fi
}
deploy_proxy(){
npm run build-proxy \
&& cd cloudflare/workers/proxy \
&& TF_VAR_cloudflare_email=${ACCOUNT_EMAIL} \
TF_VAR_cloudflare_token=${ACCOUNT_AUTH_KEY} \
terraform apply
}
destroy_cloudflare(){
cd cloudflare &&
TF_VAR_cloudflare_email=${ACCOUNT_EMAIL} \
TF_VAR_cloudflare_token=${ACCOUNT_AUTH_KEY} \
TF_VAR_proxy_domain=${PROXY_DOMAIN} \
TF_VAR_blue_domain=${BLUE_DOMAIN} \
TF_VAR_green_domain=${GREEN_DOMAIN} \
TF_VAR_default_origin=${DEFAULT_ORIGIN} \
terraform destroy
}
destroy_blue(){
cd cloudflare/workers/blue &&
TF_VAR_cloudflare_email=${ACCOUNT_EMAIL} \
TF_VAR_cloudflare_token=${ACCOUNT_AUTH_KEY} \
terraform destroy
}
destroy_green(){
cd cloudflare/workers/green &&
TF_VAR_cloudflare_email=${ACCOUNT_EMAIL} \
TF_VAR_cloudflare_token=${ACCOUNT_AUTH_KEY} \
terraform destroy
}
destroy_proxy(){
cd cloudflare/workers/proxy &&
TF_VAR_cloudflare_email=${ACCOUNT_EMAIL} \
TF_VAR_cloudflare_token=${ACCOUNT_AUTH_KEY} \
terraform destroy
}
destroy_records(){
cd cloudflare/records &&
TF_VAR_cloudflare_email=${ACCOUNT_EMAIL} \
TF_VAR_cloudflare_token=${ACCOUNT_AUTH_KEY} \
terraform destroy
}
destroy_all(){
destroy_blue \
&& destroy_green \
&& destroy_proxy \
&& destroy_records \
&& destroy_cloudflare
}
"$@"
# use
# chmod u+x commands.sh
# ./commands.sh test
# . commands.sh -> then can just call functions