-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindra
executable file
·459 lines (396 loc) · 15.4 KB
/
indra
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#!/usr/bin/env bash
UNAMEOUT="$(uname -s)"
# Regular Colors
BLACK='\033[0;30m' # Black
RED='\033[0;31m' # Red
GREEN='\033[0;32m' # Green
YELLOW='\033[0;33m' # Yellow
BLUE='\033[0;34m' # Blue
PURPLE='\033[0;35m' # Purple
CYAN='\033[0;36m' # Cyan
WHITE='\033[0;37m' # White
NC='\033[0m'
# Verify operating system is supported...
case "${UNAMEOUT}" in
Linux*) MACHINE=linux ;;
Darwin*) MACHINE=mac ;;
*) MACHINE="UNKNOWN" ;;
esac
if [ "$MACHINE" == "UNKNOWN" ]; then
echo -e "${YELLOW}Unsupported operating system [$(uname -s)]. Laravel Indra supports macOS, Linux, and Windows (WSL2)." >&2
exit 1
fi
# Define environment variables...
export APP_PORT="${APP_PORT:-80}"
export APP_SERVICE="${APP_SERVICE:-"web"}"
export COMPOSER_SERVICE="${APP_SERVICE:-"composer"}"
export DB_PORT="${DB_PORT:-3306}"
export WWWUSER="${WWWUSER:-$(id -u)}"
export WWWGROUP="${WWWGROUP:-$(id -g)}"
export INDRA_SHARE_DASHBOARD="${INDRA_SHARE_DASHBOARD:-4040}"
export INDRA_SHARE_SERVER_HOST="${INDRA_SHARE_SERVER_HOST:-"laravel-indra.site"}"
export INDRA_SHARE_SERVER_PORT="${INDRA_SHARE_SERVER_PORT:-8080}"
CURRENT_DIR=$(pwd)
INDRA=/usr/bin/indra
ARTISAN=/usr/bin/artisan
VENDOR_ROOT="${CURRENT_DIR}"/vendor/
NODE_ROOT="${CURRENT_DIR}"/node_modules/
BOOTSTRAP="${CURRENT_DIR}"/bootstrap/
STORAGE="${CURRENT_DIR}"/storage/
docker info >/dev/null 2>&1
if ! docker info >/dev/null 2>&1; then
echo -e "${WHITE}Docker is not running.${NC}" >&2
exit 1
fi
COMPOSE="docker-compose"
# Determine if Indra is currently up...
PSRESULT="$(docker-compose ps -q)"
if docker-compose ps | grep "$APP_SERVICE" | grep 'Exit'; then
echo -e "${WHITE}Shutting down old Indra processes...${NC}" >&2
docker-compose down >/dev/null 2>&1
EXEC="no"
elif [ -n "$PSRESULT" ]; then
EXEC="yes"
else
EXEC="no"
fi
# Function that outputs Indra is not running...
function indra_is_not_running() {
echo -e "${WHITE}Indra is not running.${NC}" >&2
echo "" >&2
echo -e "${WHITE}You may Indra using the following commands:${NC} './indra up|indra up' or './indra up -d|indra up -d'" >&2
exit 1
}
if [ $# -gt 0 ]; then
# Source the ".env" file so Laravel's environment variables are available...
if [ -f ./.env ]; then
source ./.env
fi
if [ "$1" == "initialize" ] || [ "$1" == "-init" ]; then
shift 1
echo -e "${RED} start delete old indra,artisan files from /usr/local/bin directory ${NC}\r\n"
sudo rm -rf ${INDRA} && sudo rm -rf ${ARTISAN} || exit
sudo ln -s "${CURRENT_DIR}/indra" /usr/local/bin/indra
echo -e "${GREEN} indra add to /usr/bin directory successfully ${NC}"
sudo ln -s "${CURRENT_DIR}/artisan" /usr/local/bin/artisan
echo -e "${GREEN} artisan add to /usr/bin directory successfully ${NC}\r\n"
sudo chmod +x artisan
echo -e "${BLUE} start to set vendor directory permission${NC}"
sudo chown -R "${WWWUSER}":"${WWWGROUP}" "${VENDOR_ROOT}" && sudo chmod -R 777 "${VENDOR_ROOT}"
echo -e "${BLUE} permission set for composer directory ${NC}\r\n"
echo -e "${CYAN} start to set node_modules directory permission${NC}"
sudo chown -R "${WWWUSER}":"${WWWGROUP}" "${NODE_ROOT}" && sudo chmod -R 777 "${NODE_ROOT}"
echo -e "${GREEN} permission set for node_modules directory ${NC}\r\n"
echo -e "${BLUE} start to set bootstrap directory permission${NC}"
sudo chmod -R 777 "${BOOTSTRAP}"
echo -e "${BLUE} permission set for bootstrap directory ${NC}\r\n"
echo -e "${CYAN} start to set storage directory permission${NC}"
sudo chmod -R 777 "${STORAGE}"
echo -e "${GREEN} permission set for node_modules directory ${NC}\r\n"
elif [ "$1" == "help" ] || [ "$1" == "-h" ]; then
shift 1
echo -e "${GREEN} You can use this command to stop other project docker and make indra ready to go:\r\n"
echo -e "${RED} docker-restart | -dr:"
echo -e "${CYAN} other project that run with docker and bind required port for indra should stop\r\n"
echo -e "${PURPLE} sample : indra docker-restart | indra -dr \r\n"
echo -e "${GREEN} You have these commands for running:\r\n"
echo -e "${RED} up:"
echo -e "${CYAN} indra up use for running docker-compose up command\r\n"
echo -e "${PURPLE} sample : indra up \r\n"
echo -e "${RED} down:"
echo -e "${CYAN} indra down use for running docker-compose down command\r\n"
echo -e "${PURPLE} sample : indra down \r\n"
echo -e "${RED} php:"
echo -e "${CYAN}indra php use for proxy php commands to your web container service \r\n"
echo -e "${PURPLE}sample : indra php -v \r\n"
echo -e "${RED} bin:"
echo -e "${CYAN}indra bin use for proxy vendor binary commands on the web container \r\n"
echo -e "${PURPLE}sample : indra bin carbon \r\n"
echo -e "${RED}composer"
echo -e "${CYAN}indra composer use for proxy composer commands to your web container service \r\n"
echo -e "${PURPLE}sample : indra composer -v \r\n"
echo -e "${RED}artisan:"
echo -e "${CYAN}indra artisan use for proxy artisan commands to your web container service \r\n"
echo -e "${PURPLE}sample : indra artisan cache:clear \r\n"
echo -e "${RED}test"
echo -e "${CYAN}indra test use for proxy artisan test to your web container service \r\n"
echo -e "${PURPLE}indra test --testsuite=Feature --stop-on-failure\r\n"
echo -e "${RED}dusk:"
echo -e "${CYAN}indra dusk use for proxy artisan dusk commands to your web container service \r\n"
echo -e "${PURPLE}sample : indra artisan dusk dusk:chrome-driver \r\n"
echo -e "${RED}dusk:fails :"
echo -e "${CYAN}indra dusk:fails use for proxy artisan dusk:fails commands to your web container service \r\n"
echo -e "${PURPLE}sample : indra artisan dusk:fails \r\n"
echo -e "${RED}tinker:"
echo -e "${CYAN}indra tinker use for proxy artisan tinker commands to your web container service \r\n"
echo -e "${PURPLE}sample : indra artisan tinker \r\n"
echo -e "${RED} app-console|a-console:"
echo -e "${CYAN} indra app-console|a-console use for proxy php Interactive mode enabled to your web container service \r\n"
echo -e "${PURPLE} sample : indra app-console \r\n"
echo -e "${RED}node:"
echo -e "${CYAN}indra node use for proxy node command to your node container service \r\n"
echo -e "${PURPLE}indra node install \r\n"
echo -e "${RED}npm:"
echo -e "${CYAN}indra npm use for proxy npm command to your node container service \r\n"
echo -e "${PURPLE}indra npm install \r\n"
echo -e "${RED}npx:"
echo -e "${CYAN}indra npx use for Proxy NPX commands to the 'npx' binary on the web container \r\n"
echo -e "${PURPLE}indra npx \r\n"
echo -e "${RED}yarn:"
echo -e "${CYAN}indra yarn use for proxy node yarn command to your node container service \r\n"
echo -e "${PURPLE}indra yarn test \r\n"
echo -e "${RED}mysql:"
echo -e "${CYAN}indra mysql use for initiate a mysql CLI terminal session within the 'mysql' container \r\n"
echo -e "${PURPLE}indra mysql \r\n"
echo -e "${RED}mariadb:"
echo -e "${CYAN}indra mariadb use for initiate a MYSQL CLI terminal session within the 'mariadb' container \r\n"
echo -e "${PURPLE}indra mariadb \r\n"
echo -e "${RED}psql:"
echo -e "${CYAN}indra psql use for initiate a PostgreSQL CLI terminal session within the "pgsql" container \r\n"
echo -e "${PURPLE}indra psql \r\n"
echo -e "${RED}shell:"
echo -e "${CYAN}indra shell use for initiate a bash shell within the web container \r\n"
echo -e "${PURPLE}sample : indra shell \r\n"
echo -e "${RED}root-shell:"
echo -e "${CYAN}indra shell use for initiate a root user bash shell within the web container \r\n"
echo -e "${PURPLE}sample : indra shell \r\n"
echo -e "${RED}redis:"
echo -e "${CYAN}indra redis use for Initiate a Redis CLI terminal session within the 'redis' container \r\n"
echo -e "${PURPLE}sample : indra redis \r\n"
echo -e "${RED}share:"
echo -e "${CYAN}indra share use for Share the site \r\n"
echo -e "${PURPLE}sample : indra share \r\n"
echo -e "${RED} :"
echo -e "${CYAN} Pass unknown commands to the 'docker-compose' binary \r\n"
echo -e "${PURPLE}sample : indra events \r\n"
# stop old docker services
elif [ "$1" == "docker-restart" ] || [ "$1" == "-dr" ]; then
shift 1
echo -e "${YELLOW}Stopping Dockers...${NC}"
docker stop $(docker ps -a -q)
echo -e "Docker ${GREEN}Stopped${NC}"
echo -e "${YELLOW}Stopping Docker-compose...${NC}"
docker-compose stop
echo -e "Docker-compose ${GREEN}Stopped${NC}"
echo -e "${YELLOW}Old docker running project stoped ,now you can start indra...${NC}"
# Run Indra using docker compose up...
elif grep -s -q "up" "$1" ; then
shift 1
echo -e "${YELLOW}Stopping Dockers...${NC}"
docker stop $(docker ps -a -q)
echo -e "Docker ${GREEN}Stopped${NC}"
echo -e "${YELLOW}Stopping Docker-compose...${NC}"
docker-compose stop
echo -e "Docker-compose ${GREEN}Stopped${NC}"
echo -e "${YELLOW}Old docker running project stoped ,now you can start indra...${NC}"
echo -e "${YELLOW}Starting Docker-compose...${NC}"
docker-compose "$@"
echo -e "Docker-compose ${GREEN}Started${NC}"
# Proxy PHP commands to the "php" binary on the application container...
elif [ "$1" == "php" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
# shellcheck disable=SC2124
EXEC_CMD="cd /var/www/html && php $@"
$COMPOSE exec -u indra "$APP_SERVICE" bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy vendor binary commands on the application container...
elif [ "$1" == "bin" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
# shellcheck disable=SC2124
EXEC_CMD="$@"
$COMPOSE exec -u indra "$APP_SERVICE" bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy Composer commands to the "composer" binary on the application container...
elif [ "$1" == "composer" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="composer $@"
$COMPOSE exec -u indra "$APP_SERVICE" bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy Artisan commands to the "artisan" binary on the application container...
elif [ "$1" == "artisan" ] || [ "$1" == "art" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="php artisan $@"
$COMPOSE exec -u indra "$APP_SERVICE" bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy the "test" command to the "php artisan test" Artisan command...
elif [ "$1" == "test" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="php artisan test "$@""
$COMPOSE exec "$APP_SERVICE" bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy the "dusk" command to the "php artisan dusk" Artisan command...
elif [ "$1" == "dusk" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="php artisan dusk $@"
$COMPOSE exec \
-u indra \
-e "APP_URL=http://web" \
-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub" \
"$APP_SERVICE" bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy the "dusk:fails" command to the "php artisan dusk:fails" Artisan command...
elif [ "$1" == "dusk:fails" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="php artisan dusk:fails $@"
$COMPOSE exec \
-u indra \
-e "APP_URL=http://web" \
-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub" \
"$APP_SERVICE" \
bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Initiate a Laravel Tinker session within the application container...
elif [ "$1" == "tinker" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="php artisan tinker $@"
$COMPOSE exec -u indra "$APP_SERVICE" bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
elif [ "$1" == "app-console" ] || [ "$1" == "a-console" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="php -a $@"
$COMPOSE exec -u indra web bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy Node commands to the "node" binary on the application container...
elif [ "$1" == "node" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="node $@"
$COMPOSE exec -u indra "$APP_SERVICE" bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy NPM commands to the "npm" binary on the application container...
elif [ "$1" == "npm" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="npm $@"
$COMPOSE exec -u indra "$APP_SERVICE" bash -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy NPX commands to the "npx" binary on the application container...
elif [ "$1" == "npx" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="npx "$@""
$COMPOSE exec -u indra "$APP_SERVICE" bach -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Proxy YARN commands to the "yarn" binary on the application container...
elif [ "$1" == "yarn" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
EXEC_CMD="yarn $@"
$COMPOSE exec -u indra "$APP_SERVICE" bach -c "$EXEC_CMD"
else
indra_is_not_running
fi
# Initiate a MySQL CLI terminal session within the "mysql" container...
elif [ "$1" == "mysql" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
docker-compose exec \
mysql \
bash -c 'MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}'
else
indra_is_not_running
fi
# Initiate a MySQL CLI terminal session within the "mariadb" container...
elif [ "$1" == "mariadb" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
docker-compose exec \
mariadb \
bash -c 'MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}'
else
indra_is_not_running
fi
# Initiate a PostgreSQL CLI terminal session within the "pgsql" container...
elif [ "$1" == "psql" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
docker-compose exec \
pgsql \
bash -c 'PGPASSWORD=${PGPASSWORD} psql -U ${POSTGRES_USER} ${POSTGRES_DB}'
else
indra_is_not_running
fi
# Initiate a Bash shell within the application container...
elif [ "$1" == "shell" ] || [ "$1" == "bash" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
docker-compose exec \
-u indra \
"$APP_SERVICE" \
bash
else
indra_is_not_running
fi
# Initiate a root user Bash shell within the application container...
elif [ "$1" == "root-shell" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
docker-compose exec \
"$APP_SERVICE" \
bash
else
indra_is_not_running
fi
# Initiate a Redis CLI terminal session within the "redis" container...
elif [ "$1" == "redis" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
docker-compose exec \
redis \
redis-cli
else
indra_is_not_running
fi
# Share the site...
elif [ "$1" == "share" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
docker run --init --rm -p "$INDRA_SHARE_DASHBOARD":4040 -t beyondcodegmbh/expose-server:latest share http://host.docker.internal:"$APP_PORT" \
--server-host="$INDRA_SHARE_SERVER_HOST" \
--server-port="$INDRA_SHARE_SERVER_PORT" \
--auth="$INDRA_SHARE_TOKEN" \
--subdomain=""
"$@"
else
indra_is_not_running
fi
# Pass unknown commands to the "docker-compose" binary...
else
docker-compose "$@"
fi
else
docker-compose ps
fi