forked from devopsloft/devopsloft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspin.sh
executable file
·94 lines (80 loc) · 2.84 KB
/
spin.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
#!/usr/bin/env bash
set -e
if [[ "$(uname)" != "Darwin" ]]; then
echo "This script can run only on OS-X"
exit
fi
ACTION=${1:-'up'}
ENVIRONMENT=${2:-'dev'}
function self_signed_certificate() {
if [[ -f web_s2i/cert.pem && -f web_s2i/key.pem ]]; then
return
fi
openssl req -x509 -newkey rsa:4096 -nodes -out web_s2i/cert.pem \
-keyout web_s2i/key.pem -days 365 \
-subj "/C=IL/ST=Gush-Dan/L=Tel-Aviv/O=DevOps Loft/OU=''/CN=''"
}
self_signed_certificate
source .env
if [[ -f .env.local ]]; then
source .env.local
fi
if [[ ! -d ./vault ]]; then
echo "Directory /vault doesn't exists"
exit
fi
vagrant plugin update
if [[ "$ENVIRONMENT" == "dev" ]]; then
if [[ $(vboxmanage --version) != "6.0.8r130520" ]]; then
echo "Wrong virtualbox version"
fi
vagrant box update --provider virtualbox
vagrant box prune --provider virtualbox
export WEB_HOST_PORT=$DEV_WEB_HOST_PORT
export WEB_GUEST_PORT=$DEV_WEB_GUEST_PORT
export WEB_HOST_SECURE_PORT=$DEV_WEB_HOST_SECURE_PORT
export WEB_GUEST_SECURE_PORT=$DEV_WEB_GUEST_SECURE_PORT
elif [[ "$ENVIRONMENT" == "stage" ]]; then
export AWS_PROFILE=$STAGE_AWS_PROFILE
export WEB_HOST_PORT=$STAGE_WEB_HOST_PORT
export WEB_GUEST_PORT=$STAGE_WEB_GUEST_PORT
export WEB_HOST_SECURE_PORT=$STAGE_WEB_HOST_SECURE_PORT
export WEB_GUEST_SECURE_PORT=$STAGE_WEB_GUEST_SECURE_PORT
if [[ -f record-set-create.json ]]; then
source venv/bin/activate
pip install --upgrade awscli
sed 's/CREATE/DELETE/g' record-set-create.json >record-set-delete.json
aws route53 change-resource-record-sets \
--hosted-zone-id $STAGE_HOSTED_ZONE_ID \
--change-batch file://record-set-delete.json
rm -rf record-set-create.json record-set-delete.json
fi
elif [[ "$ENVIRONMENT" == "prod" ]]; then
export AWS_PROFILE=$PROD_AWS_PROFILE
export WEB_HOST_PORT=$PROD_WEB_HOST_PORT
export WEB_GUEST_PORT=$PROD_WEB_GUEST_PORT
export WEB_HOST_SECURE_PORT=$PROD_WEB_HOST_SECURE_PORT
export WEB_GUEST_SECURE_PORT=$PROD_WEB_GUEST_SECURE_PORT
fi
vagrant destroy -f $ENVIRONMENT
if [[ "$ACTION" == "destroy" ]]; then
exit
fi
vagrant up $ENVIRONMENT
guest_ip=$(vagrant ssh-config $ENVIRONMENT | grep HostName | awk \{'print $2'\})
if [[ "$ENVIRONMENT" == "dev" ]]; then
sleep 5
elif [[ "$ENVIRONMENT" == "stage" ]]; then
source venv/bin/activate
pip install --upgrade awscli j2cli
export domain_name=www.dpline.io
export guest_ip
j2 record-set.json.j2 -o record-set-create.json
aws route53 change-resource-record-sets \
--hosted-zone-id $STAGE_HOSTED_ZONE_ID \
--change-batch file://record-set-create.json
fi
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
--disable-application-cache "https://${guest_ip}:${WEB_HOST_SECURE_PORT}"
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
--disable-application-cache "http://${guest_ip}:$WEB_HOST_PORT"