-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.sh
More file actions
executable file
·136 lines (101 loc) · 2.53 KB
/
app.sh
File metadata and controls
executable file
·136 lines (101 loc) · 2.53 KB
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
#!/usr/bin/env bash
FUNCTION=
if [ ! -z $1 ]; then
FUNCTION="$1"
fi
platform='unknown'
unmaster=`uname`
if [[ $unmaster == 'Linux' ]]; then
platform='linux'
elif [[ $unmaster == 'MINGW64_NT-10.0' ]]; then
platform='windows'
elif [[ $unmaster == 'Darwin' ]]; then
platform='mac'
fi
show-help() {
echo 'Functions:'
echo './app.sh [start] [stop] [restart] [build] [first_run]'
}
rundocker() {
echo 'Stop all containert'
docker stop $(docker ps -a -q)
echo ''
echo 'Start containers'
docker-compose -p forus-notification up -d
echo ''
}
start() {
rundocker
migrate
#create_static
}
migrate() {
docker exec -it forus-notification_web_1 python manage.py migrate
}
logs() {
docker logs forus-notification_web_1
}
celery_logs() {
docker logs forus-notification_worker_1
}
redis_logs() {
docker logs forus-notification_redis_1
}
createsuperuser() {
docker exec -it forus-notification_web_1 python manage.py createsuperuser
}
makemigrations() {
docker exec -it forus-notification_web_1 python manage.py makemigrations
}
collectstatic() {
# docker exec -it forus-notification_web_1 bash -c "cd app && npm i && npm run build"
docker exec -it forus-notification_web_1 python manage.py collectstatic
}
stop() {
echo 'Stop all containert'
docker stop $(docker ps -a -q)
}
restart() {
start
}
first_run() {
local DB_NAME=$(get_variable 'DB_NAME')
local DB_USER=$(get_variable 'DB_USER')
local DB_PASS=$(get_variable 'DB_PASS')
rundocker
docker exec -it forus-notification_postgres_1 psql -U postgres -c "CREATE DATABASE $DB_NAME;"
docker exec -it forus-notification_postgres_1 psql -U postgres -c "CREATE USER $DB_USER WITH ENCRYPTED PASSWORD '$DB_PASS';"
docker exec -it forus-notification_postgres_1 psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;"
start
}
update() {
echo 'Build containers with cache'
docker-compose -p forus-notification build worker
docker-compose -p forus-notification build web
}
build() {
echo 'Build containers'
docker-compose -p forus-notification build worker --no-cache
docker-compose -p forus-notification build --no-cache
}
get_variable(){
while read p; do
A="$(echo $p | cut -d'=' -f1)"
B="$(echo $p | cut -d'=' -f2)"
if [[ $A = $1 ]]
then
echo $B
fi
done <.env
}
case "$1" in
-h|--help)
show-help
;;
*)
if [ ! -z $(type -t $FUNCTION | grep function) ]; then
$1
else
show-help
fi
esac