-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstackbox-brew.sh
182 lines (152 loc) · 4.36 KB
/
stackbox-brew.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
#!/bin/bash
echo " _ _ _"
echo " ___| |_ __ _ ___| | _| |__ _____ __"
echo "/ __| __/ _ |/ __| |/ / '_ \ / _ \ \/ /"
echo "\__ \ || (_| | (__| <| |_) | (_) > <"
echo '|___/\__\__,_|\___|_|\_\_.__/ \___/_/\_\'
printf "\n"
echo "######## SELECT YOUR STACK #############"
printf "\n"
stack=()
installationPath=$(brew --cellar stackbox)/$(brew info --json stackbox | jq -r '.[0].installed[0].version')
PS3='Select your frontend: '
echo "FRONTEND OPTIONS:"
frontend_options=("Vue")
select opt in "${frontend_options[@]}"
do
case $opt in
"Vue")
echo "You've chosen Vue"
stack+=("vue")
break;
;;
*) echo "Invalid option $REPLY";;
esac
done
printf "\n"
PS3='Select your backend: '
echo "BACKEND OPTIONS:"
backend_options=("Flask" "Rails")
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;
;;
*) 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;
;;
"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 "######## SETTING YOUR CODE DIRECTORY #############"
printf "\n"
srcPath=$(pwd)"/stackbox/"
mkdir $srcPath
cp -r $installationPath/. $srcPath
echo "Your code is in "$srcPath
printf "\n"
echo "######## BUILDING YOUR STACK ###############"
printf "\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 $srcPath/requirements.txt) > /dev/null "
python $srcPath/brew/stack-brew.py $srcPath ${stack[*]}
elif beginswith "Python 3" "$python3_version";
then
var="$(pip3 --disable-pip-version-check install -r $srcPath/requirements.txt) > /dev/null"
python3 $srcPath/brew/stack-brew.py $srcPath ${stack[*]}
else
echo "Unable to find a python 3 installation"
fi
docker-compose -f $srcPath/docker-compose.yml down 2> /dev/null > $srcPath/logs/docker-compose-down-log.txt
docker-compose -f $srcPath/docker-compose.yml build > $srcPath/logs/docker-compose-build-log.txt
printf "\n"
echo "######## DEPLOYING YOUR STACK ##############"
printf "\n"
docker-compose -f $srcPath/docker-compose.yml up -d --remove-orphans
sleep 5
printf "\n"
echo "######## YOUR STACK ########################"
printf "\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
printf "\n"