-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstackbox.sh
executable file
·184 lines (157 loc) · 4.32 KB
/
stackbox.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
echo " _ _ _"
echo " ___| |_ __ _ ___| | _| |__ _____ __"
echo "/ __| __/ _ |/ __| |/ / '_ \ / _ \ \/ /"
echo "\__ \ || (_| | (__| <| |_) | (_) > <"
echo '|___/\__\__,_|\___|_|\_\_.__/ \___/_/\_\'
echo "\n"
echo "######## SELECT YOUR STACK #############\n"
stack=()
PS3='Select your frontend: '
echo "FRONTEND OPTIONS:"
frontend_options=("Vue" "Angular" "React")
select opt in "${frontend_options[@]}"
do
case $opt in
"Vue")
echo "You've chosen Vue"
stack+=("vue")
break;
;;
"Angular")
echo "You've chosen Angular"
stack+=("angular")
break;
;;
"React")
echo "You've chosen React"
stack+=("react")
break;
;;
*) echo "Invalid option $REPLY";;
esac
done
PS3='Select your backend: '
echo "BACKEND OPTIONS:"
backend_options=("Flask" "Rails" "Golang")
select opt in "${backend_options[@]}"
do
case $opt in
"Flask")
echo "You've chosen Flask"
stack+=("flask")
break;
;;
"Rails")
echo "You've chosen Rails"
stack+=("rubyonrails")
break;
;;
"Golang")
echo "You've chosen Golang"
stack+=("golang")
break;
;;
*) echo "Invalid option $REPLY";;
esac
done
printf "\n"
PS3='Add your services. Choose 5 to finish adding: '
echo "SERVICE OPTIONS:"
service_options=("MySQL" "Kafka" "Elasticsearch" "Nginx" "Done")
select opt in "${service_options[@]}"
do
case $opt in
"MySQL")
echo "You've chosen MySQL"
stack+=("mysql")
continue;
;;
"MongoDB")
echo "You've chosen MongoDB"
stack+=("mongodb")
continue;
;;
"Kafka")
echo "You've chosen Kafka. Zookeper will also be set up."
stack+=("kafka")
stack+=("zookeeper")
continue;
;;
"Elasticsearch")
echo "You've chosen Elasticsearch"
stack+=("elasticsearch")
# shellcheck disable=SC2162
read -p "Do you want Kibana as well? (y/n)" yn
case $yn in
[Yy]* )
echo "You've chosen Kibana + Elasticsearch"
stack+=("kibana")
continue;;
[Nn]* )
echo "You've chosen Elasticsearch without Kibana"
continue;;
* ) echo "Please answer yes or no.";;
esac
;;
"Nginx")
echo "You've chosen Nginx"
stack+=("nginx")
continue;
;;
"Done")
break
;;
*) echo "Invalid option $REPLY";;
esac
done
printf "\n"
printf "The services you've chosen are: "
echo "${stack[*]}"
printf "\n"
echo "######## BUILDING YOUR STACK ###############\n"
beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
python_version=$(python --version)
python3_version=$(python3 --version)
if beginswith "Python 3" "$python_version" ;
then
var="$(pip --disable-pip-version-check install -r requirements.txt) > /dev/null "
python stack.py ${stack[*]}
elif beginswith "Python 3" "$python3_version";
then
var="$(pip3 --disable-pip-version-check install -r requirements.txt) > /dev/null"
python3 stack.py ${stack[*]}
else
echo "Unable to find a python 3 installation"
fi
docker-compose down 2> /dev/null > logs/docker-compose-down-log.txt
docker-compose build > logs/docker-compose-build-log.txt
echo "\n######## DEPLOYING YOUR STACK ##############\n"
docker-compose up -d --remove-orphans
sleep 5
echo "\n######## YOUR STACK ########################\n"
containers=$(docker ps --format '{{.Names}}')
ports="$(docker ps --format '{{.Ports}}')"
service_ports=()
for port in $ports;
do
if beginswith "0.0.0.0" "$port";
then
port1=$(echo "$port" | awk -F[:-] '{print $2}')
service_ports+=("$port1")
fi
done
i=-1
for container in $containers;
do
i=$i+1
if [ "$container" != "registry" ];
then
if beginswith "stackbox" "$container";
then
tmp=${container%"_1"}
echo ${tmp#"stackbox_"} is up at http://localhost:${service_ports[i]}
fi
fi
done
echo "\n"