-
Notifications
You must be signed in to change notification settings - Fork 14
/
start.sh
executable file
·118 lines (93 loc) · 2.58 KB
/
start.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
set -e
function usage(){
cat <<EOF
Usage: $(basename "$0") [options] <argument>
Description:
This script initiates boundary vault stack in your desired environment.
Options:
--help Display this help message and exit
-e Define which environment to run the stack in (development/staging/test/production).
Example:
- run in dev:
$(basename "$0") -e development
EOF
}
if [[ $1 == "--help" ]]; then
usage
exit 0
fi
function check_env(){
case "$1" in
development | staging | test | production)
return 0
;;
*)
echo "ERROR: Invalid value for -e : ${1} , For more info use --help or reach out to Documentation." >&2
return 4
;;
esac
}
if [ -z "$STACK_ENV" ]; then
while getopts "e:" opt; do
case $opt in
e)
check_env "$OPTARG"
export STACK_ENV="${OPTARG}"
echo "Running Boundary Vault Stack on ${STACK_ENV} Mode."
;;
\?)
echo "ERROR: Invalid option: -${OPTARG} For more info use --help or reach out to Documentation" >&2
return 4
;;
esac
done
elif ! check_env "$STACK_ENV"; then
exit 4
fi
if [ $# -ne 2 ]; then
usage
exit 4
fi
echo -e "***Running Boundary Vault Stack on ${STACK_ENV} Mode.****\n"
## create ignored dirs in git for confidential data
mkdir -p logs/ logs/docker logs/terraform secrets/
source ./scripts/linter.sh
if [[ ! -d "venv/" ]]; then
echo -e "\nInstalling Virtual Env and dependencies."
py_cmd=$(lint_py)
$py_cmd -m venv venv
source venv/bin/activate
pip install -U pip
pip install -r ./requirements.txt
else
source venv/bin/activate
pip install -r ./requirements.txt
fi
## install required collections
#!/bin/bash
# Check if Vagrant is installed
if command -v vagrant &> /dev/null
then
echo "Vagrant is installed"
vagrant --version
else
sh scripts/install_vagrant.sh
fi
#install virtualbox
sh scripts/install_virtual_box.sh
ansible-galaxy collection install -r requirements.yml
# provision the server
if [ -z "$STACK_SERVER"]; then
lint_vagrant
vagrant up
fi
ansible-playbook -i ansible/inventory/inventory.ini ansible/playbook.yml --ask-vault-pass
echo "****** Applying Vault changes ******"
sleep 10
ansible-playbook -i ansible/inventory/inventory.ini ansible/terraform.yml --ask-vault-pass
echo "********* Applying terraform provisioning ******* "
sleep 5
ansible-playbook -i ansible/inventory/inventory.ini ansible/boundary.yml --ask-vault-pass
echo "***** Performing Stack Cleanup *******"
ansible-playbook -i ansible/inventory/inventory.ini ansible/cleanup.yml --ask-vault-pass