-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
258 lines (213 loc) · 6.24 KB
/
run.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/bash
SCRIPT_CURRENT_DIRECTORY="`dirname \"$0\"`"
FLAG=1
echo_prinT() {
local name=$1
(echo
echo -n "#"
for ((i=0;i<$((${#name}+8));i++))
do
echo -n "-"
done
echo "#"
echo -n "#----"
if [ "$2" = "error" ]
then
echo -ne "\e[1m\e[31m$name\e[0m"
elif [ "$2" = "head" ]
then
echo -ne "\e[1m\e[92m$name\e[0m"
elif [ "$2" = "subhead" ]
then
echo -ne "\e[1m\e[96m$name\e[0m"
else
echo -ne "$name"
fi
echo "----#"
echo -n "#"
for ((j=0;j<$((${#name}+8));j++))
do
echo -n "-"
done
echo "#") | tee -a $SCRIPT_CURRENT_DIRECTORY/log_error.out
return 0
}
header(){
clear
echo -e "\n**************************************************"
echo -e "**\t\t\t\t\t\t**"
echo -e "**\t \e[40;38;5;82m Docker \e[30;48;5;82m Project \e[0m \t\t\t**"
echo -e "**\t\t\t\t\t\t**"
echo -e "**\t \e[40;38;5;82m Name: \e[30;48;5;82m Mohamed Ayman \e[0m \t\t**"
echo -e "**\t\t\t\t\t\t**"
# echo -e "**\t \e[40;38;5;82m >>$ Press \e[30;48;5;82m Enter \e[40;38;5;82m To \e[30;48;5;82m Start \e[0m \t\t**"
# echo -e "**\t\t\t\t\t\t**"
echo -e "**************************************************"
}
build() {
####################
# Building Images #
####################
# Building MYSQL
echo_prinT "+%$>>>> Building Images <<<<$%+" "head"
echo_prinT "Installing MYSQL" "subhead"
echo "Chaning Directory To : $SCRIPT_CURRENT_DIRECTORY/"mysql""
cd $SCRIPT_CURRENT_DIRECTORY/"mysql"
echo "Bulding Image"
sudo docker build -t mohayman/mysql .
if [ $? -ne 0 ]
then
echo "[xXx] Failed : See Error Logs.
REMARK: [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out] command will execute AUTOMATICALLY."
FLAG=0
else
echo "[xXx] Succeeded."
fi
cd -
###########################################
# Building WordPress
echo_prinT "Installing WordPress" "subhead"
cd "$SCRIPT_CURRENT_DIRECTORY"/"wordpress"
sudo docker build -t mohayman/wpdownloader .
if [ $? -ne 0 ]
then
echo "[xXx] Failed : See Error Logs.
REMARK: [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out] command will execute AUTOMATICALLY."
FLAG=0
else
echo "[xXx] Succeeded."
fi
cd -
###########################################
# Building PHP-FPM
echo_prinT "Installing PHP-FPM" "subhead"
cd "$SCRIPT_CURRENT_DIRECTORY"/"php-fpm"
sudo docker build -t mohayman/phpfpm .
if [ $? -ne 0 ]
then
echo "[xXx] Failed : See Error Logs.
REMARK: [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out] command will execute AUTOMATICALLY."
FLAG=0
else
echo "[xXx] Succeeded."
fi
cd -
###########################################
# Building NGINX
echo_prinT "Installing NGINX" "subhead"
cd "$SCRIPT_CURRENT_DIRECTORY"/"nginx"
sudo docker build -t mohayman/nginx .
if [ $? -ne 0 ]
then
echo "[xXx] Failed : See Error Logs.
REMARK: [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out] command will execute AUTOMATICALLY."
FLAG=0
else
echo "[xXx] Succeeded."
fi
cd -
##########################################
} 2>>$SCRIPT_CURRENT_DIRECTORY/log_error.out
run(){
######################
# Running Containers #
######################
echo_prinT "+%$>>>> Running containers <<<<$%+" "head"
# Runing MYSQL Container
echo_prinT "Mysql Contianer" "subhead"
sudo docker run -d --name mysql mohayman/mysql
if [ $? -ne 0 ]
then
echo "[xXx] Failed : See Error Logs.
REMARK: [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out] command will execute AUTOMATICALLY."
FLAG=0
else
echo "[xXx] Succeeded."
fi
##################################################
# Runing WordPress Container
echo_prinT "WordPress Container" "subhead"
sudo docker run -i -t --name downloader mohayman/wpdownloader
if [ $? -ne 0 ]
then
echo "[xXx] Failed : See Error Logs.
REMARK: [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out] command will execute AUTOMATICALLY."
FLAG=0
else
echo "[xXx] Succeeded."
fi
##################################################
# Runing APPLICATION SERVER Container
echo_prinT "Application Server Container" "subhead"
sudo docker run -d --name app1 --volumes-from downloader --link mysql:db mohayman/phpfpm
if [ $? -ne 0 ]
then
echo "[xXx] Failed : See Error Logs.
REMARK: [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out] command will execute AUTOMATICALLY."
FLAG=0
else
echo "[xXx] Succeeded."
fi
##################################################
# Runing NGINX Container
echo_prinT "Nginx Container" "subhead"
sudo docker run -d -p 8023:80 --name nginx --volumes-from downloader --link app1:app1 mohayman/nginx
if [ $? -ne 0 ]
then
echo "[xXx] Failed : See Error Logs.
REMARK: [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out] command will execute AUTOMATICALLY."
FLAG=0
else
echo "[xXx] Succeeded."
fi
##################################################
} 2>>$SCRIPT_CURRENT_DIRECTORY/log_error.out
echo `echo_prinT "Error LOG"` > $SCRIPT_CURRENT_DIRECTORY/log_error.out
header
sleep 1.234567890
if [ "$1" = "--build" ] || [ "$1" = "-b" ] || [ "$1" = "--run" ] || [ "$1" = "-r" ] || [ "$1" = "--build--run" ] || [ "$1" = "-b-r" ]
then
if [ "$1" = "--build" ] || [ "$1" = "-b" ]
then
build
if [ "$FLAG" -eq 0 ]
then
echo
echo -ne "\e[1m\e[31mPress Enter To Execute [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out]\e[0m"
read EnterKey
echo_prinT "#######***^!^***###### Error-Log-Records #######***^!^***######" "error"
cat $SCRIPT_CURRENT_DIRECTORY/log_error.out
fi
elif [ "$1" = "--run" ] || [ "$1" = "-r" ]
then
run
if [ "$FLAG" -eq 0 ]
then
echo
echo -ne "\e[1m\e[31mPress Enter To Execute [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out]\e[0m"
read EnterKey
echo_prinT "#######***^!^***###### Error-Log-Records #######***^!^***######" "error"
cat $SCRIPT_CURRENT_DIRECTORY/log_error.out
fi
elif [ "$1" = "--build--run" ] || [ "$1" = "-b-r" ]
then
build
run
if [ "$FLAG" -eq 0 ]
then
echo
echo -ne "\e[1m\e[31mPress Enter To Execute [cat $SCRIPT_CURRENT_DIRECTORY/log_error.out]\e[0m"
read EnterKey
echo_prinT "#######***^!^***###### Error-Log-Records #######***^!^***######" "error"
cat $SCRIPT_CURRENT_DIRECTORY/log_error.out
fi
fi
else
echo_prinT "Error .. Please, Stick To This Instructions."
echo "Usage: ./.../run.sh [OPTION]... "
echo "Options:
RMARK: Options Order Is Mandatory
-b, --build TO BUILD IMAGES.
-r, --run TO RUN STACK'S CONTAINERS.
-b-r, --build--run TO BUILD THE IMAGES AND THEN RUN THE CONTAINERS."
fi