-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
executable file
·140 lines (121 loc) · 3.38 KB
/
start
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
#!/bin/bash
PRESS_ENTER="\e[1;38m"
BG_RED="\e[41m"
RED="\e[31m"
BLUE="\e[34m"
GREEN="\e[32m"
ENDCOLOR="\e[0m"
CYAN="\e[36m"
MAGENTA="\e[95m"
if [[ $OSTYPE == darwin* ]]
then
PRESS_ENTER=
BG_RED=
RED=
BLUE=
GREEN=
ENDCOLOR=
CYAN=
MAGENTA=
fi
main() {
if [[ $1 == 'dev' ]]
then
mkdir debug
fi
user_gid=$(id -g)
gid_to_replace=$(grep USER_GID= .env | cut -d '=' -f2)
cp .env .env.old
cat .env.old | sed "s/$(grep STAGE= .env)/STAGE=$1/" > .env
if [[ $1 == 'dev' ]]
then
cp .env .env.old
cat .env.old | sed "s/$(grep HTTP_METHOD= .env)/HTTP_METHOD=http/" > .env
cp .env .env.old
cat .env.old | sed "s/$(grep REACT_PORT= .env)/REACT_PORT=80/" > .env
else
cp .env .env.old
cat .env.old | sed "s/$(grep HTTP_METHOD= .env)/HTTP_METHOD=https/" > .env
cp .env .env.old
cat .env.old | sed "s/$(grep REACT_PORT= .env)/REACT_PORT=443/" > .env
fi
if [[ $1 == 'dev' ]]
then
cp .env .env.old
cat .env.old | sed "s/$(grep DJANGO_DEBUG= .env)/DJANGO_DEBUG=True/" > .env
else
cp .env .env.old
cat .env.old | sed "s/$(grep DJANGO_DEBUG= .env)/DJANGO_DEBUG=False/" > .env
fi
if [[ $OSTYPE == darwin* ]]
then
ip=$(ifconfig | grep en0 -A 2 | grep "inet " | awk '{ print $2 }')
host_name=$(hostname | tr '[:upper:]' '[:lower:]')
else
ip=$(ip add | grep "BROADCAST,MULTICAST,UP,LOWER_UP" -A 2 | grep inet -m1 | awk '{print $2}' | cut -d '/' -f1)
host_name=$(hostnamectl hostname | tr '[:upper:]' '[:lower:]')
fi
ip_to_replace=$(grep HOST_IP= .env | cut -d '=' -f2)
hostname_to_replace=$(grep HOST_NAME= .env | awk '{ print $1 }' | cut -d '=' -f2)
cp .env .env.old
cat .env.old | sed "s/$gid_to_replace/$user_gid/" > .env
cp .env .env.old
cat .env.old | sed "s/$ip_to_replace/$ip/" > .env
cp .env .env.old
cat .env.old | sed "s/$hostname_to_replace/$host_name/" > .env
rm .env.old
exec docker-compose up --build
}
cleanup_database() {
docker rm postgresql
}
cleanup_network() {
docker network prune
}
cleanup_debug() {
rm -rf debug/
}
cleanup() {
docker kill $(docker ps --format '{{.ID}}') 2> /dev/null
docker rm $(docker ps -a --format '{{.ID}}') 2> /dev/null
docker rmi $(docker images --format '{{.ID}}') 2> /dev/null
docker system prune -af --volumes 2> /dev/null
rm -rf debug/
}
press_enter() {
echo ""
echo -en $PRESS_ENTER" Press Enter to continue "$ENDCOLOR
read
clear
}
exit_case() {
exit
}
incorrect_selection() {
echo -e $BG_RED"Wrong choice! Try again."$ENDCOLOR
}
until [ "$selection" = "q" ]; do
clear
echo ""
echo -e $GREEN" 1 - Start server in production mode"$ENDCOLOR
echo -e $CYAN" 2 - Start server in development mode"$ENDCOLOR
echo -e $BLUE" 3 - Clean up docker files and debug folder"$ENDCOLOR
echo -e $BLUE" 4 - Clean up debug folder"$ENDCOLOR
echo -e $BLUE" 5 - Clean up database"$ENDCOLOR
echo -e $BLUE" 6 - Clean up docker networks"$ENDCOLOR
echo -e $RED" 0 - Exit" $ENDCOLOR
echo ""
echo -en $MAGENTA" Enter selection: "$ENDCOLOR
read selection
echo ""
case $selection in
1 ) clear ; main "prod" ; press_enter ;;
2 ) clear ; main "dev" ; press_enter ;;
3 ) clear ; cleanup ; press_enter ;;
4 ) clear ; cleanup_debug ; press_enter ;;
5 ) clear ; cleanup_database ; press_enter ;;
6 ) clear ; cleanup_network ; press_enter ;;
0 ) clear ; exit ;;
* ) clear ; incorrect_selection ; press_enter ;;
esac
done