-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy
executable file
·69 lines (56 loc) · 1.62 KB
/
deploy
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
#!/bin/bash
set -euo pipefail
set -x
cd "$(dirname "$0")"
TF_VAR_hetzner_token="$(gopass show spaceapi/hetzner_cloud_token)"
export TF_VAR_hetzner_token
TF_VAR_njalla_token="$(gopass show spaceapi/njalla_token)"
export TF_VAR_njalla_token
function autoDeploy {
createPersistent
read -p "Test changes in dev? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
createAndProvisionDev
read -p "Dev deployed, press enter to destroy. Ctrl + C to cancel."
destroyDev
fi
read -p "Press enter to deploy to prod. Ctrl + C to cancel."
createAndProvisionProd
}
function createAndProvisionEnv {
local env=$1
local domain=$2
local community_domain=$3
cd nodes
terraform init -upgrade
terraform workspace select ${env}
terraform apply -var-file=${env}.tfvars
cd ../deployment
env=${env} /usr/bin/env ansible-playbook -i inventory.sh playbooks/provisioning.yml --vault-password-file vaultpass --extra-vars "domain=$domain" --extra-vars "community_domain=$community_domain"
cd ..
}
function createPersistent {
cd persistent
terraform init -upgrade
terraform apply
cd ..
}
function createAndProvisionProd {
createAndProvisionEnv prod spaceapi.io spaceapi.community
}
function createAndProvisionDev {
createAndProvisionEnv dev spaceapi.rocks community.spaceapi.rocks
}
function destroyDev {
# cleanup dev
cd nodes
terraform workspace select dev
terraform destroy -auto-approve -var-file=dev.tfvars
cd ..
}
case ${1-} in
destroydev) destroyDev; exit ;;
deploydev) createAndProvisionDev; exit ;;
*) autoDeploy; exit ;;
esac