-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·69 lines (58 loc) · 1.73 KB
/
entrypoint.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
#!/usr/bin/env bash
ACTION=""
while [[ ! "$ACTION" =~ [cdkq] ]]; do
cat <<EOF
What can I do for you today?
c) Create a new environment
d) Deploy an existing environment
k) Destroy an existing environment
q) Quit
Enter your choice:
EOF
read -r ACTION
done
case $ACTION in
c)
# Select the environment to clone
envTemplate=$(ls terraform | percol --prompt-bottom --prompt "Select the environment to trigger:")
# Select a name for the new environment
printf "Insert a unique name for the environment:\n"
read -r environmentName
if [ -d "${environmentName}" ]; then
echo "Environment named ${ENVIRONMENT_NAME} already exists. Please select a unique name"
exit 1
fi
# Clone environment
cp -a "terraform/${envTemplate}" "environments/${environmentName}"
printf "New environment created: %s\n" "./environments/${environmentName}"
;;
q)
echo "Have a nice day!"
exit 0
;;
esac
#Select the environment
if [ -z "${environmentName}" ]; then
environmentName=$(ls "environments" | percol --prompt-bottom --prompt "Select environment:")
fi
if [ ! -f "environments/${environmentName}/caos.auto.tfvars" ]; then
echo "Rename environments/${environmentName}/caos.auto.tfvars.dist to environments/${environmentName}/caos.auto.tfvars, fill the variables and re-run command"
echo "cp environments/${environmentName}/caos.auto.tfvars.dist environments/${environmentName}/caos.auto.tfvars"
exit 1
fi
make init-${environmentName}
case $ACTION in
d | c)
echo "Installing dependencies..."
make deps
make apply-${environmentName}
;;
k)
make destroy-${environmentName}
echo "Do you want to delete all the files?y/[n]"
read -r PRUNE
if [ "${PRUNE}" == "y" ]; then
rm -rf "environments/${environmentName}"
fi
;;
esac