-
Notifications
You must be signed in to change notification settings - Fork 0
/
task
executable file
·186 lines (173 loc) · 4.41 KB
/
task
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
#!/bin/bash
set -eu
if [ $# = 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
cat <<EOF
Usage: $0 <service> [command...]
Bash shell $0 <service>
Strapi console $0 backend console
PostgreSQL console $0 postgres console
Redis console $0 redis console
Mail console $0 mail console
Run all tests $0 test
Run <service> tests $0 <service> test
Watch <service> tests $0 <service> watch
Run npm install in node services $0 install
Check for outdated node modules $0 outdated
Apply auto-formatting (prettier) $0 pretty
Run linter (eslint) $0 lint
Add fake data $0 fake
(Re)build Strapi admin $0 build-admin
Reset database $0 reset-db
Clean containers, cache, etc... $0 clean
EOF
exit 1
fi
SERVICE="$1"
shift
case "$SERVICE" in
frontend|shared|worker)
if [ "$*" == "install" ]; then
set npm install
elif [ "$*" == "outdated" ]; then
set bash -c 'npm outdated || true'
elif [ "$*" == "test" ]; then
set npm run test
elif [ "$*" == "watch" ]; then
set npm run watch
fi
;;
backend|strapi)
SERVICE="backend"
if [ "$*" == "install" ]; then
set npm install
elif [ "$*" == "outdated" ]; then
set bash -c 'npm outdated || true'
elif [ "$*" == "test" ]; then
set npm run test
elif [ "$*" == "watch" ]; then
set npm run watch
elif [ "$*" == "build-admin" ]; then
set bash -c 'rm -rf build/* cache/* && npx strapi build'
elif [ "$*" == "console" ]; then
set npx -c 'PORT=1338 strapi console'
elif [ "$*" == "fake" ]; then
set bash -c 'node lib/fake'
fi
;;
mail)
SERVICE="mail"
if [ "$*" == "console" ]; then
set mail
fi
;;
db|postgres)
SERVICE="postgres"
if [ "$*" == "console" ]; then
set psql -U strapi
fi
;;
redis)
if [ "$*" == "console" ]; then
set redis-cli
fi
;;
test)
"$0" shared test
"$0" backend test
"$0" frontend test
"$0" worker test
exit 0
;;
install)
"$0" shared install
"$0" backend install
"$0" frontend install
"$0" worker install
exit 0
;;
outdated)
"$0" shared outdated
"$0" backend outdated
"$0" frontend outdated
"$0" worker outdated
exit 0
;;
pretty|prettier)
test -d node_modules || npm install --silent
npm run prettier
exit 0
;;
lint|eslint)
test -d node_modules || npm install --silent
npm run eslint
exit 0
;;
fake)
"$0" backend fake
exit 0
;;
build-admin)
"$0" backend build-admin
exit 0
;;
reset-db|reload-db)
cd "$(dirname "$0")"
docker-compose stop -t 1 backend postgres
docker-compose rm -f postgres
docker volume prune -f
rm -rf backend/public/uploads/*
docker-compose up -d backend postgres
exit 0
;;
clean)
cd "$(dirname "$0")"
docker-compose down
docker container prune -f
if docker image ls | grep -q pujaslive; then
docker image rm $(docker image ls | grep pujaslive | tr -s ' ' | cut -d ' ' -f 3)
fi
docker image prune -f
if docker volume ls -q | grep -q pujaslive; then
docker volume rm $(docker volume ls -q | grep pujaslive)
fi
docker volume prune -f
rm -rf backend/.cache backend/.tmp backend/build \
backend/exports backend/node_modules \
backend/public/uploads/* \
frontend/.next frontend/node_modules \
logs/backup logs/deploy logs/worker \
shared/node_modules \
worker/build worker/node_modules
exit 0
;;
*)
echo "No such service: $SERVICE"
exit 1
;;
esac
if [ $# = 0 ]; then
set bash
fi
if [ "$SERVICE" = "shared" ]; then
DOCKER_SERVICE=worker
else
DOCKER_SERVICE="$SERVICE"
fi
COMMAND=run
DOCKER_ID=$(docker-compose ps -q "$DOCKER_SERVICE")
if echo "$DOCKER_ID" | grep -q .; then
if docker ps -qa --filter status=running \
--filter "id=$DOCKER_ID" | grep -q .; then
COMMAND=exec
fi
fi
case "$SERVICE" in
backend|frontend|worker|shared)
set -- /app/docker/run "$SERVICE" "$@"
;;
esac
echo "> docker-compose $COMMAND $DOCKER_SERVICE $@"
docker-compose "$COMMAND" "$DOCKER_SERVICE" "$@"
if test "$COMMAND" = "run"; then
docker-compose rm -vf > /dev/null 2>&1
fi