-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.sh
More file actions
155 lines (121 loc) · 3.31 KB
/
app.sh
File metadata and controls
155 lines (121 loc) · 3.31 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
FUNCTION=
if [ ! -z $1 ]; then
FUNCTION="$1"
fi
platform='unknown'
unmaster=`uname`
project_name='bitrix24-bridge'
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 "Project: $project_name"
echo 'Stop all containert'
docker stop $(docker ps -a -q)
echo ''
echo 'Start containers'
docker-compose -p $project_name up -d
echo ''
}
start() {
rundocker
}
migrate() {
echo 'migrate - Not support'
# docker exec -it $(get_container_name 'app') python manage.py migrate
}
logs() {
docker logs $(get_container_name 'app')
}
rabbitmq_logs() {
docker logs $(get_container_name 'rabbitmq')
}
redis_logs() {
docker logs $(get_container_name 'redis')
}
setup_rabbitmq() {
docker exec -it $(get_container_name 'rabbitmq') bash rabbitmq-init.sh init
}
clear_rabbitmq() {
docker exec -it $(get_container_name 'rabbitmq') bash rabbitmq-init.sh init
}
rabbitmq_cmd() {
echo $1
docker exec -it $(get_container_name 'rabbitmq') bash rabbitmq-init.sh $1
}
createsuperuser() {
echo 'createsuperuser - Not support'
#docker exec -it $(get_container_name 'app') python manage.py createsuperuser
}
makemigrations() {
echo 'makemigrations - Not support'
#docker exec -it $(get_container_name 'app') python manage.py makemigrations
}
collectstatic() {
echo 'collectstatic - Not support'
# docker exec -it $(get_container_name 'app') bash -c "cd app && npm i && npm q build"
# docker exec -it $(get_container_name 'app') python manage.py collectstatic --noinput -v 0
}
compilemessages() {
echo 'compilemessages - Not support'
# docker exec -it $(get_container_name 'app') django-admin compilemessages -v 0
}
get_container_name() {
docker ps -a --filter="name=bitrix24-bridge_$1" --format '{{.Names}}'
}
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 $(get_container_name 'postgres') psql -U postgres -c "CREATE DATABASE $DB_NAME;"
docker exec -it $(get_container_name 'postgres') psql -U postgres -c "CREATE USER $DB_USER WITH ENCRYPTED PASSWORD '$DB_PASS';"
docker exec -it $(get_container_name 'postgres') psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;"
docker exec -it $(get_container_name 'postgres') psql -U postgres -d $DB_NAME -c 'create extension hstore;'
setup_rabbitmq
}
update() {
echo 'Build containers with cache'
docker-compose -p $project_name build app
}
build() {
echo 'Build containers'
docker-compose -p $project_name 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 $2 $3 $4 $5
else
show-help
fi
esac