-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply.sh
61 lines (56 loc) · 2.92 KB
/
apply.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
#!/bin/bash
echo "Begin to use $deploy_type to Deploy"
echo '{
"client_id": "'$client_id'",
"client_secret": "'$client_secret'",
"refresh_token": "'$refresh_token'",
"scopes": "'$scopes'",
"type": "authorized_user"
}' > client_secret.json
echo "---------------------------------------------"
echo "Begin to clone deploy from $url"
git clone $url $solution_id > /dev/null 2>&1
echo "Clone finished."
cd $solution_id
version=$(echo $parameters | jq .version)
if [[ $version != '""' ]];then
echo "Checkout to version: $version"
git checkout $version
echo "Checkout finish"
fi
cd $deploy_path
if [[ $deploy_type == "Terraform" ]]
then
echo $parameters | jq -r 'to_entries[] | .key + "=\"" + .value +"\""' > ./pangu.tfvars
mysql --host=$host --user=$user --password=$password --database="ads" -N --execute="select CONCAT(id,'=\"',default_value,'\"') from parameters where solution_id='$solution_id' and show_on_ui=0 ;" >> ./pangu.tfvars
echo "-------------- parameters env ---------------"
cat pangu.tfvars
echo "-------------- parameters env ---------------"
terraform init -backend-config="address=$consul_ip:8500" -backend-config="path=ads_dev/$DEPLOY_ID/terraform_state" -backend-config="scheme=http"
terraform apply -auto-approve -var-file="pangu.tfvars" -no-color
if [ $? -eq 0 ]; then
mysql --host=$host --user=$user --password=$password --database="ads" --execute="update deploy set status='deploy_success' where id='$DEPLOY_ID';"
else
mysql --host=$host --user=$user --password=$password --database="ads" --execute="update deploy set status='deploy_failed' where id='$DEPLOY_ID';"
fi
else
echo $parameters | jq -r 'to_entries[] | "export " + .key + "=\"" + .value +"\""' > ./pangu.env
mysql --host=$host --user=$user --password=$password --database="ads" -N --execute="select CONCAT('export ',id,'=\"',default_value,'\"') from parameters where solution_id='$solution_id' and show_on_ui=0 ;" >> ./pangu.env
source ./pangu.env
echo "---------------------------------------------"
# echo "Run the following command to deploy from your Cloud Shell:"
# cat pangu.env
# echo "git clone $url $solution_id"
# echo "cd $solution_id/$deploy_path"
# echo 'CLOUDSDK_AUTH_ACCESS_TOKEN=$(gcloud auth application-default print-access-token) bash deploy.sh'
# echo "---------------------------------------------"
bash deploy.sh
if [ $? -eq 0 ]; then
mysql --host=$host --user=$user --password=$password --database="ads" --execute="update deploy set status='deploy_success' where id='$DEPLOY_ID';"
else
mysql --host=$host --user=$user --password=$password --database="ads" --execute="update deploy set status='deploy_failed' where id='$DEPLOY_ID';"
fi
fi
cd /app
rm -rf ./*
unset CLOUDSDK_AUTH_ACCESS_TOKEN GOOGLE_APPLICATION_CREDENTIALS parameters user host password image db consul_ip client_id client_secret scopes refresh_token