Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 399 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
#!/usr/bin/env bash
2
 
3
UNAMEOUT="$(uname -s)"
4
 
5
# Verify operating system is supported...
6
case "${UNAMEOUT}" in
7
    Linux*)             MACHINE=linux;;
8
    Darwin*)            MACHINE=mac;;
9
    *)                  MACHINE="UNKNOWN"
10
esac
11
 
12
if [ "$MACHINE" == "UNKNOWN" ]; then
13
    echo "Unsupported operating system [$(uname -s)]. Laravel Sail supports macOS, Linux, and Windows (WSL2)." >&2
14
 
15
    exit 1
16
fi
17
 
18
# Determine if stdout is a terminal...
19
if test -t 1; then
20
    # Determine if colors are supported...
21
    ncolors=$(tput colors)
22
 
23
    if test -n "$ncolors" && test "$ncolors" -ge 8; then
24
        BOLD="$(tput bold)"
25
        YELLOW="$(tput setaf 3)"
26
        GREEN="$(tput setaf 2)"
27
        NC="$(tput sgr0)"
28
    fi
29
fi
30
 
31
# Function that prints the available commands...
32
function display_help {
33
    echo "Laravel Sail"
34
    echo
35
    echo "${YELLOW}Usage:${NC}" >&2
36
    echo "  sail COMMAND [options] [arguments]"
37
    echo
38
    echo "Unknown commands are passed to the docker-compose binary."
39
    echo
40
    echo "${YELLOW}docker-compose Commands:${NC}"
41
    echo "  ${GREEN}sail up${NC}        Start the application"
42
    echo "  ${GREEN}sail up -d${NC}     Start the application in the background"
43
    echo "  ${GREEN}sail stop${NC}      Stop the application"
44
    echo "  ${GREEN}sail restart${NC}   Restart the application"
45
    echo "  ${GREEN}sail ps${NC}        Display the status of all containers"
46
    echo
47
    echo "${YELLOW}Artisan Commands:${NC}"
48
    echo "  ${GREEN}sail artisan ...${NC}          Run an Artisan command"
49
    echo "  ${GREEN}sail artisan queue:work${NC}"
50
    echo
51
    echo "${YELLOW}PHP Commands:${NC}"
52
    echo "  ${GREEN}sail php ...${NC}   Run a snippet of PHP code"
53
    echo "  ${GREEN}sail php -v${NC}"
54
    echo
55
    echo "${YELLOW}Composer Commands:${NC}"
56
    echo "  ${GREEN}sail composer ...${NC}                       Run a Composer command"
57
    echo "  ${GREEN}sail composer require laravel/sanctum${NC}"
58
    echo
59
    echo "${YELLOW}Node Commands:${NC}"
60
    echo "  ${GREEN}sail node ...${NC}         Run a Node command"
61
    echo "  ${GREEN}sail node --version${NC}"
62
    echo
63
    echo "${YELLOW}NPM Commands:${NC}"
64
    echo "  ${GREEN}sail npm ...${NC}        Run a npm command"
65
    echo "  ${GREEN}sail npx${NC}            Run a npx command"
66
    echo "  ${GREEN}sail npm run prod${NC}"
67
    echo
68
    echo "${YELLOW}Yarn Commands:${NC}"
69
    echo "  ${GREEN}sail yarn ...${NC}        Run a Yarn command"
70
    echo "  ${GREEN}sail yarn run prod${NC}"
71
    echo
72
    echo "${YELLOW}Database Commands:${NC}"
73
    echo "  ${GREEN}sail mysql${NC}     Start a MySQL CLI session within the 'mysql' container"
74
    echo "  ${GREEN}sail mariadb${NC}   Start a MySQL CLI session within the 'mariadb' container"
75
    echo "  ${GREEN}sail psql${NC}      Start a PostgreSQL CLI session within the 'pgsql' container"
76
    echo "  ${GREEN}sail redis${NC}     Start a Redis CLI session within the 'redis' container"
77
    echo
78
    echo "${YELLOW}Debugging:${NC}"
79
    echo "  ${GREEN}sail debug ...${NC}          Run an Artisan command in debug mode"
80
    echo "  ${GREEN}sail debug queue:work${NC}"
81
    echo
82
    echo "${YELLOW}Running Tests:${NC}"
83
    echo "  ${GREEN}sail test${NC}          Run the PHPUnit tests via the Artisan test command"
84
    echo "  ${GREEN}sail phpunit ...${NC}   Run PHPUnit"
399 lars 85
    echo "  ${GREEN}sail pest ...${NC}      Run Pest"
148 lars 86
    echo "  ${GREEN}sail pint ...${NC}      Run Pint"
87
    echo "  ${GREEN}sail dusk${NC}          Run the Dusk tests (Requires the laravel/dusk package)"
88
    echo "  ${GREEN}sail dusk:fails${NC}    Re-run previously failed Dusk tests (Requires the laravel/dusk package)"
89
    echo
90
    echo "${YELLOW}Container CLI:${NC}"
91
    echo "  ${GREEN}sail shell${NC}        Start a shell session within the application container"
92
    echo "  ${GREEN}sail bash${NC}         Alias for 'sail shell'"
93
    echo "  ${GREEN}sail root-shell${NC}   Start a root shell session within the application container"
94
    echo "  ${GREEN}sail root-bash${NC}    Alias for 'sail root-shell'"
95
    echo "  ${GREEN}sail tinker${NC}       Start a new Laravel Tinker session"
96
    echo
97
    echo "${YELLOW}Sharing:${NC}"
98
    echo "  ${GREEN}sail share${NC}   Share the application publicly via a temporary URL"
621 lars 99
    echo "  ${GREEN}sail open${NC}    Open the site in your browser"
148 lars 100
    echo
101
    echo "${YELLOW}Binaries:${NC}"
102
    echo "  ${GREEN}sail bin ...${NC}   Run Composer binary scripts from the vendor/bin directory"
103
    echo
104
    echo "${YELLOW}Customization:${NC}"
105
    echo "  ${GREEN}sail artisan sail:publish${NC}   Publish the Sail configuration files"
106
    echo "  ${GREEN}sail build --no-cache${NC}       Rebuild all of the Sail containers"
107
 
108
    exit 1
109
}
110
 
111
# Proxy the "help" command...
112
if [ $# -gt 0 ]; then
113
    if [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == "--help" ]; then
114
        display_help
115
    fi
116
else
117
    display_help
118
fi
119
 
120
# Source the ".env" file so Laravel's environment variables are available...
121
if [ ! -z "$APP_ENV" ] && [ -f ./.env.$APP_ENV ]; then
122
  source ./.env.$APP_ENV;
123
elif [ -f ./.env ]; then
124
  source ./.env;
125
fi
126
 
127
# Define environment variables...
128
export APP_PORT=${APP_PORT:-80}
129
export APP_SERVICE=${APP_SERVICE:-"laravel.test"}
130
export DB_PORT=${DB_PORT:-3306}
131
export WWWUSER=${WWWUSER:-$UID}
132
export WWWGROUP=${WWWGROUP:-$(id -g)}
133
 
134
export SAIL_FILES=${SAIL_FILES:-""}
135
export SAIL_SHARE_DASHBOARD=${SAIL_SHARE_DASHBOARD:-4040}
136
export SAIL_SHARE_SERVER_HOST=${SAIL_SHARE_SERVER_HOST:-"laravel-sail.site"}
137
export SAIL_SHARE_SERVER_PORT=${SAIL_SHARE_SERVER_PORT:-8080}
138
export SAIL_SHARE_SUBDOMAIN=${SAIL_SHARE_SUBDOMAIN:-""}
621 lars 139
export SAIL_SHARE_DOMAIN=${SAIL_SHARE_DOMAIN:-"$SAIL_SHARE_SERVER_HOST"}
148 lars 140
 
141
# Function that outputs Sail is not running...
142
function sail_is_not_running {
143
    echo "${BOLD}Sail is not running.${NC}" >&2
144
    echo "" >&2
145
    echo "${BOLD}You may Sail using the following commands:${NC} './vendor/bin/sail up' or './vendor/bin/sail up -d'" >&2
146
 
147
    exit 1
148
}
149
 
150
# Define Docker Compose command prefix...
151
docker compose &> /dev/null
152
if [ $? == 0 ]; then
153
    DOCKER_COMPOSE=(docker compose)
154
else
155
    DOCKER_COMPOSE=(docker-compose)
156
fi
157
 
158
if [ -n "$SAIL_FILES" ]; then
159
    # Convert SAIL_FILES to an array...
160
    IFS=':' read -ra SAIL_FILES <<< "$SAIL_FILES"
161
 
162
    for FILE in "${SAIL_FILES[@]}"; do
163
        if [ -f "$FILE" ]; then
164
            DOCKER_COMPOSE+=(-f "$FILE")
165
        else
166
            echo "${BOLD}Unable to find Docker Compose file: '${FILE}'${NC}" >&2
167
 
168
            exit 1
169
        fi
170
    done
171
fi
172
 
173
EXEC="yes"
174
 
175
if [ -z "$SAIL_SKIP_CHECKS" ]; then
176
    # Ensure that Docker is running...
177
    if ! docker info > /dev/null 2>&1; then
178
        echo "${BOLD}Docker is not running.${NC}" >&2
179
 
180
        exit 1
181
    fi
182
 
183
    # Determine if Sail is currently up...
184
    if "${DOCKER_COMPOSE[@]}" ps "$APP_SERVICE" 2>&1 | grep 'Exit\|exited'; then
185
        echo "${BOLD}Shutting down old Sail processes...${NC}" >&2
186
 
187
        "${DOCKER_COMPOSE[@]}" down > /dev/null 2>&1
188
 
189
        EXEC="no"
190
    elif [ -z "$("${DOCKER_COMPOSE[@]}" ps -q)" ]; then
191
        EXEC="no"
192
    fi
193
fi
194
 
195
ARGS=()
196
 
197
# Proxy PHP commands to the "php" binary on the application container...
198
if [ "$1" == "php" ]; then
199
    shift 1
200
 
201
    if [ "$EXEC" == "yes" ]; then
202
        ARGS+=(exec -u sail)
203
        [ ! -t 0 ] && ARGS+=(-T)
204
        ARGS+=("$APP_SERVICE" "php" "$@")
205
    else
206
        sail_is_not_running
207
    fi
208
 
209
# Proxy vendor binary commands on the application container...
210
elif [ "$1" == "bin" ]; then
211
    shift 1
212
 
213
    if [ "$EXEC" == "yes" ]; then
214
        ARGS+=(exec -u sail)
215
        [ ! -t 0 ] && ARGS+=(-T)
216
        ARGS+=("$APP_SERVICE" ./vendor/bin/"$@")
217
    else
218
        sail_is_not_running
219
    fi
220
 
221
# Proxy docker-compose commands to the docker-compose binary on the application container...
222
elif [ "$1" == "docker-compose" ]; then
223
    shift 1
224
 
225
    if [ "$EXEC" == "yes" ]; then
226
        ARGS+=(exec -u sail)
227
        [ ! -t 0 ] && ARGS+=(-T)
228
        ARGS+=("$APP_SERVICE" "${DOCKER_COMPOSE[@]}")
229
    else
230
        sail_is_not_running
231
    fi
232
 
233
# Proxy Composer commands to the "composer" binary on the application container...
234
elif [ "$1" == "composer" ]; then
235
    shift 1
236
 
237
    if [ "$EXEC" == "yes" ]; then
238
        ARGS+=(exec -u sail)
239
        [ ! -t 0 ] && ARGS+=(-T)
240
        ARGS+=("$APP_SERVICE" "composer" "$@")
241
    else
242
        sail_is_not_running
243
    fi
244
 
245
# Proxy Artisan commands to the "artisan" binary on the application container...
246
elif [ "$1" == "artisan" ] || [ "$1" == "art" ]; then
247
    shift 1
248
 
249
    if [ "$EXEC" == "yes" ]; then
250
        ARGS+=(exec -u sail)
251
        [ ! -t 0 ] && ARGS+=(-T)
252
        ARGS+=("$APP_SERVICE" php artisan "$@")
253
    else
254
        sail_is_not_running
255
    fi
256
 
257
# Proxy the "debug" command to the "php artisan" binary on the application container with xdebug enabled...
258
elif [ "$1" == "debug" ]; then
259
    shift 1
260
 
261
    if [ "$EXEC" == "yes" ]; then
262
        ARGS+=(exec -u sail -e XDEBUG_SESSION=1)
263
        [ ! -t 0 ] && ARGS+=(-T)
264
        ARGS+=("$APP_SERVICE" php artisan "$@")
265
    else
266
        sail_is_not_running
267
    fi
268
 
269
# Proxy the "test" command to the "php artisan test" Artisan command...
270
elif [ "$1" == "test" ]; then
271
    shift 1
272
 
273
    if [ "$EXEC" == "yes" ]; then
274
        ARGS+=(exec -u sail)
275
        [ ! -t 0 ] && ARGS+=(-T)
276
        ARGS+=("$APP_SERVICE" php artisan test "$@")
277
    else
278
        sail_is_not_running
279
    fi
280
 
281
# Proxy the "phpunit" command to "php vendor/bin/phpunit"...
282
elif [ "$1" == "phpunit" ]; then
283
    shift 1
284
 
285
    if [ "$EXEC" == "yes" ]; then
286
        ARGS+=(exec -u sail)
287
        [ ! -t 0 ] && ARGS+=(-T)
288
        ARGS+=("$APP_SERVICE" php vendor/bin/phpunit "$@")
289
    else
290
        sail_is_not_running
291
    fi
292
 
399 lars 293
# Proxy the "pest" command to "php vendor/bin/pest"...
294
elif [ "$1" == "pest" ]; then
295
    shift 1
296
 
297
    if [ "$EXEC" == "yes" ]; then
298
        ARGS+=(exec -u sail)
299
        [ ! -t 0 ] && ARGS+=(-T)
300
        ARGS+=("$APP_SERVICE" php vendor/bin/pest "$@")
301
    else
302
        sail_is_not_running
303
    fi
304
 
148 lars 305
# Proxy the "pint" command to "php vendor/bin/pint"...
306
elif [ "$1" == "pint" ]; then
307
    shift 1
308
 
309
    if [ "$EXEC" == "yes" ]; then
310
        ARGS+=(exec -u sail)
311
        [ ! -t 0 ] && ARGS+=(-T)
312
        ARGS+=("$APP_SERVICE" php vendor/bin/pint "$@")
313
    else
314
        sail_is_not_running
315
    fi
316
 
317
# Proxy the "dusk" command to the "php artisan dusk" Artisan command...
318
elif [ "$1" == "dusk" ]; then
319
    shift 1
320
 
321
    if [ "$EXEC" == "yes" ]; then
322
        ARGS+=(exec -u sail)
323
        [ ! -t 0 ] && ARGS+=(-T)
324
        ARGS+=(-e "APP_URL=http://${APP_SERVICE}")
325
        ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub")
326
        ARGS+=("$APP_SERVICE" php artisan dusk "$@")
327
    else
328
        sail_is_not_running
329
    fi
330
 
331
# Proxy the "dusk:fails" command to the "php artisan dusk:fails" Artisan command...
332
elif [ "$1" == "dusk:fails" ]; then
333
    shift 1
334
 
335
    if [ "$EXEC" == "yes" ]; then
336
        ARGS+=(exec -u sail)
337
        [ ! -t 0 ] && ARGS+=(-T)
338
        ARGS+=(-e "APP_URL=http://${APP_SERVICE}")
339
        ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub")
340
        ARGS+=("$APP_SERVICE" php artisan dusk:fails "$@")
341
    else
342
        sail_is_not_running
343
    fi
344
 
345
# Initiate a Laravel Tinker session within the application container...
346
elif [ "$1" == "tinker" ] ; then
347
    shift 1
348
 
349
    if [ "$EXEC" == "yes" ]; then
350
        ARGS+=(exec -u sail)
351
        [ ! -t 0 ] && ARGS+=(-T)
352
        ARGS+=("$APP_SERVICE" php artisan tinker)
353
    else
354
        sail_is_not_running
355
    fi
356
 
357
# Proxy Node commands to the "node" binary on the application container...
358
elif [ "$1" == "node" ]; then
359
    shift 1
360
 
361
    if [ "$EXEC" == "yes" ]; then
362
        ARGS+=(exec -u sail)
363
        [ ! -t 0 ] && ARGS+=(-T)
364
        ARGS+=("$APP_SERVICE" node "$@")
365
    else
366
        sail_is_not_running
367
    fi
368
 
369
# Proxy NPM commands to the "npm" binary on the application container...
370
elif [ "$1" == "npm" ]; then
371
    shift 1
372
 
373
    if [ "$EXEC" == "yes" ]; then
374
        ARGS+=(exec -u sail)
375
        [ ! -t 0 ] && ARGS+=(-T)
376
        ARGS+=("$APP_SERVICE" npm "$@")
377
    else
378
        sail_is_not_running
379
    fi
380
 
381
# Proxy NPX commands to the "npx" binary on the application container...
382
elif [ "$1" == "npx" ]; then
383
    shift 1
384
 
385
    if [ "$EXEC" == "yes" ]; then
386
        ARGS+=(exec -u sail)
387
        [ ! -t 0 ] && ARGS+=(-T)
388
        ARGS+=("$APP_SERVICE" npx "$@")
389
    else
390
        sail_is_not_running
391
    fi
392
 
393
# Proxy YARN commands to the "yarn" binary on the application container...
394
elif [ "$1" == "yarn" ]; then
395
    shift 1
396
 
397
    if [ "$EXEC" == "yes" ]; then
398
        ARGS+=(exec -u sail)
399
        [ ! -t 0 ] && ARGS+=(-T)
400
        ARGS+=("$APP_SERVICE" yarn "$@")
401
    else
402
        sail_is_not_running
403
    fi
404
 
405
# Initiate a MySQL CLI terminal session within the "mysql" container...
406
elif [ "$1" == "mysql" ]; then
407
    shift 1
408
 
409
    if [ "$EXEC" == "yes" ]; then
410
        ARGS+=(exec)
411
        [ ! -t 0 ] && ARGS+=(-T)
412
        ARGS+=(mysql bash -c)
413
        ARGS+=("MYSQL_PWD=\${MYSQL_PASSWORD} mysql -u \${MYSQL_USER} \${MYSQL_DATABASE}")
414
    else
415
        sail_is_not_running
416
    fi
417
 
418
# Initiate a MySQL CLI terminal session within the "mariadb" container...
419
elif [ "$1" == "mariadb" ]; then
420
    shift 1
421
 
422
    if [ "$EXEC" == "yes" ]; then
423
        ARGS+=(exec)
424
        [ ! -t 0 ] && ARGS+=(-T)
425
        ARGS+=(mariadb bash -c)
426
        ARGS+=("MYSQL_PWD=\${MYSQL_PASSWORD} mysql -u \${MYSQL_USER} \${MYSQL_DATABASE}")
427
    else
428
        sail_is_not_running
429
    fi
430
 
431
# Initiate a PostgreSQL CLI terminal session within the "pgsql" container...
432
elif [ "$1" == "psql" ]; then
433
    shift 1
434
 
435
    if [ "$EXEC" == "yes" ]; then
436
        ARGS+=(exec)
437
        [ ! -t 0 ] && ARGS+=(-T)
438
        ARGS+=(pgsql bash -c)
439
        ARGS+=("PGPASSWORD=\${PGPASSWORD} psql -U \${POSTGRES_USER} \${POSTGRES_DB}")
440
    else
441
        sail_is_not_running
442
    fi
443
 
444
# Initiate a Bash shell within the application container...
445
elif [ "$1" == "shell" ] || [ "$1" == "bash" ]; then
446
    shift 1
447
 
448
    if [ "$EXEC" == "yes" ]; then
449
        ARGS+=(exec -u sail)
450
        [ ! -t 0 ] && ARGS+=(-T)
451
        ARGS+=("$APP_SERVICE" bash "$@")
452
    else
453
        sail_is_not_running
454
    fi
455
 
456
# Initiate a root user Bash shell within the application container...
457
elif [ "$1" == "root-shell" ] || [ "$1" == "root-bash" ]; then
458
    shift 1
459
 
460
    if [ "$EXEC" == "yes" ]; then
461
        ARGS+=(exec)
462
        [ ! -t 0 ] && ARGS+=(-T)
463
        ARGS+=("$APP_SERVICE" bash "$@")
464
    else
465
        sail_is_not_running
466
    fi
467
 
468
# Initiate a Redis CLI terminal session within the "redis" container...
469
elif [ "$1" == "redis" ] ; then
470
    shift 1
471
 
472
    if [ "$EXEC" == "yes" ]; then
473
        ARGS+=(exec)
474
        [ ! -t 0 ] && ARGS+=(-T)
475
        ARGS+=(redis redis-cli)
476
    else
477
        sail_is_not_running
478
    fi
479
 
480
# Share the site...
481
elif [ "$1" == "share" ]; then
482
    shift 1
483
 
484
    if [ "$EXEC" == "yes" ]; then
485
        docker run --init --rm -p "$SAIL_SHARE_DASHBOARD":4040 -t beyondcodegmbh/expose-server:latest share http://host.docker.internal:"$APP_PORT" \
486
            --server-host="$SAIL_SHARE_SERVER_HOST" \
487
            --server-port="$SAIL_SHARE_SERVER_PORT" \
488
            --auth="$SAIL_SHARE_TOKEN" \
489
            --subdomain="$SAIL_SHARE_SUBDOMAIN" \
399 lars 490
            --domain="$SAIL_SHARE_DOMAIN" \
148 lars 491
            "$@"
492
 
493
        exit
494
    else
495
        sail_is_not_running
496
    fi
497
 
621 lars 498
# Open the site...
499
elif [ "$1" == "open" ]; then
500
    shift 1
501
 
502
    if [ "$EXEC" == "yes" ]; then
503
        open $APP_URL
504
 
505
        exit
506
    else
507
        sail_is_not_running
508
    fi
509
 
148 lars 510
# Pass unknown commands to the "docker-compose" binary...
511
else
512
    ARGS+=("$@")
513
fi
514
 
515
# Run Docker Compose with the defined arguments...
516
"${DOCKER_COMPOSE[@]}" "${ARGS[@]}"