Revision 621 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed
#!/usr/bin/env bashUNAMEOUT="$(uname -s)"# Verify operating system is supported...case "${UNAMEOUT}" inLinux*) MACHINE=linux;;Darwin*) MACHINE=mac;;*) MACHINE="UNKNOWN"esacif [ "$MACHINE" == "UNKNOWN" ]; thenecho "Unsupported operating system [$(uname -s)]. Laravel Sail supports macOS, Linux, and Windows (WSL2)." >&2exit 1fi# Determine if stdout is a terminal...if test -t 1; then# Determine if colors are supported...ncolors=$(tput colors)if test -n "$ncolors" && test "$ncolors" -ge 8; thenBOLD="$(tput bold)"YELLOW="$(tput setaf 3)"GREEN="$(tput setaf 2)"NC="$(tput sgr0)"fifi# Function that prints the available commands...function display_help {echo "Laravel Sail"echoecho "${YELLOW}Usage:${NC}" >&2echo " sail COMMAND [options] [arguments]"echoecho "Unknown commands are passed to the docker-compose binary."echoecho "${YELLOW}docker-compose Commands:${NC}"echo " ${GREEN}sail up${NC} Start the application"echo " ${GREEN}sail up -d${NC} Start the application in the background"echo " ${GREEN}sail stop${NC} Stop the application"echo " ${GREEN}sail restart${NC} Restart the application"echo " ${GREEN}sail ps${NC} Display the status of all containers"echoecho "${YELLOW}Artisan Commands:${NC}"echo " ${GREEN}sail artisan ...${NC} Run an Artisan command"echo " ${GREEN}sail artisan queue:work${NC}"echoecho "${YELLOW}PHP Commands:${NC}"echo " ${GREEN}sail php ...${NC} Run a snippet of PHP code"echo " ${GREEN}sail php -v${NC}"echoecho "${YELLOW}Composer Commands:${NC}"echo " ${GREEN}sail composer ...${NC} Run a Composer command"echo " ${GREEN}sail composer require laravel/sanctum${NC}"echoecho "${YELLOW}Node Commands:${NC}"echo " ${GREEN}sail node ...${NC} Run a Node command"echo " ${GREEN}sail node --version${NC}"echoecho "${YELLOW}NPM Commands:${NC}"echo " ${GREEN}sail npm ...${NC} Run a npm command"echo " ${GREEN}sail npx${NC} Run a npx command"echo " ${GREEN}sail npm run prod${NC}"echoecho "${YELLOW}Yarn Commands:${NC}"echo " ${GREEN}sail yarn ...${NC} Run a Yarn command"echo " ${GREEN}sail yarn run prod${NC}"echoecho "${YELLOW}Database Commands:${NC}"echo " ${GREEN}sail mysql${NC} Start a MySQL CLI session within the 'mysql' container"echo " ${GREEN}sail mariadb${NC} Start a MySQL CLI session within the 'mariadb' container"echo " ${GREEN}sail psql${NC} Start a PostgreSQL CLI session within the 'pgsql' container"echo " ${GREEN}sail redis${NC} Start a Redis CLI session within the 'redis' container"echoecho "${YELLOW}Debugging:${NC}"echo " ${GREEN}sail debug ...${NC} Run an Artisan command in debug mode"echo " ${GREEN}sail debug queue:work${NC}"echoecho "${YELLOW}Running Tests:${NC}"echo " ${GREEN}sail test${NC} Run the PHPUnit tests via the Artisan test command"echo " ${GREEN}sail phpunit ...${NC} Run PHPUnit"echo " ${GREEN}sail pest ...${NC} Run Pest"echo " ${GREEN}sail pint ...${NC} Run Pint"echo " ${GREEN}sail dusk${NC} Run the Dusk tests (Requires the laravel/dusk package)"echo " ${GREEN}sail dusk:fails${NC} Re-run previously failed Dusk tests (Requires the laravel/dusk package)"echoecho "${YELLOW}Container CLI:${NC}"echo " ${GREEN}sail shell${NC} Start a shell session within the application container"echo " ${GREEN}sail bash${NC} Alias for 'sail shell'"echo " ${GREEN}sail root-shell${NC} Start a root shell session within the application container"echo " ${GREEN}sail root-bash${NC} Alias for 'sail root-shell'"echo " ${GREEN}sail tinker${NC} Start a new Laravel Tinker session"echoecho "${YELLOW}Sharing:${NC}"echo " ${GREEN}sail share${NC} Share the application publicly via a temporary URL"echo " ${GREEN}sail open${NC} Open the site in your browser"echoecho "${YELLOW}Binaries:${NC}"echo " ${GREEN}sail bin ...${NC} Run Composer binary scripts from the vendor/bin directory"echoecho "${YELLOW}Customization:${NC}"echo " ${GREEN}sail artisan sail:publish${NC} Publish the Sail configuration files"echo " ${GREEN}sail build --no-cache${NC} Rebuild all of the Sail containers"exit 1}# Proxy the "help" command...if [ $# -gt 0 ]; thenif [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == "--help" ]; thendisplay_helpfielsedisplay_helpfi# Source the ".env" file so Laravel's environment variables are available...if [ ! -z "$APP_ENV" ] && [ -f ./.env.$APP_ENV ]; thensource ./.env.$APP_ENV;elif [ -f ./.env ]; thensource ./.env;fi# Define environment variables...export APP_PORT=${APP_PORT:-80}export APP_SERVICE=${APP_SERVICE:-"laravel.test"}export DB_PORT=${DB_PORT:-3306}export WWWUSER=${WWWUSER:-$UID}export WWWGROUP=${WWWGROUP:-$(id -g)}export SAIL_FILES=${SAIL_FILES:-""}export SAIL_SHARE_DASHBOARD=${SAIL_SHARE_DASHBOARD:-4040}export SAIL_SHARE_SERVER_HOST=${SAIL_SHARE_SERVER_HOST:-"laravel-sail.site"}export SAIL_SHARE_SERVER_PORT=${SAIL_SHARE_SERVER_PORT:-8080}export SAIL_SHARE_SUBDOMAIN=${SAIL_SHARE_SUBDOMAIN:-""}export SAIL_SHARE_DOMAIN=${SAIL_SHARE_DOMAIN:-"$SAIL_SHARE_SERVER_HOST"}export SAIL_SHARE_SERVER=${SAIL_SHARE_SERVER:-""}# Function that outputs Sail is not running...function sail_is_not_running {echo "${BOLD}Sail is not running.${NC}" >&2echo "" >&2echo "${BOLD}You may Sail using the following commands:${NC} './vendor/bin/sail up' or './vendor/bin/sail up -d'" >&2exit 1}# Define Docker Compose command prefix...docker compose &> /dev/nullif [ $? == 0 ]; thenDOCKER_COMPOSE=(docker compose)elseDOCKER_COMPOSE=(docker-compose)fiif [ -n "$SAIL_FILES" ]; then# Convert SAIL_FILES to an array...IFS=':' read -ra SAIL_FILES <<< "$SAIL_FILES"for FILE in "${SAIL_FILES[@]}"; doif [ -f "$FILE" ]; thenDOCKER_COMPOSE+=(-f "$FILE")elseecho "${BOLD}Unable to find Docker Compose file: '${FILE}'${NC}" >&2exit 1fidonefiEXEC="yes"if [ -z "$SAIL_SKIP_CHECKS" ]; then# Ensure that Docker is running...if ! docker info > /dev/null 2>&1; thenecho "${BOLD}Docker is not running.${NC}" >&2exit 1fi# Determine if Sail is currently up...if "${DOCKER_COMPOSE[@]}" ps "$APP_SERVICE" 2>&1 | grep 'Exit\|exited'; thenecho "${BOLD}Shutting down old Sail processes...${NC}" >&2"${DOCKER_COMPOSE[@]}" down > /dev/null 2>&1EXEC="no"elif [ -z "$("${DOCKER_COMPOSE[@]}" ps -q)" ]; thenEXEC="no"fifiARGS=()# Proxy PHP commands to the "php" binary on the application container...if [ "$1" == "php" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" "php" "$@")elsesail_is_not_runningfi# Proxy vendor binary commands on the application container...elif [ "$1" == "bin" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" ./vendor/bin/"$@")elsesail_is_not_runningfi# Proxy docker-compose commands to the docker-compose binary on the application container...elif [ "$1" == "docker-compose" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" "${DOCKER_COMPOSE[@]}")elsesail_is_not_runningfi# Proxy Composer commands to the "composer" binary on the application container...elif [ "$1" == "composer" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" "composer" "$@")elsesail_is_not_runningfi# Proxy Artisan commands to the "artisan" binary on the application container...elif [ "$1" == "artisan" ] || [ "$1" == "art" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" php artisan "$@")elsesail_is_not_runningfi# Proxy the "debug" command to the "php artisan" binary on the application container with xdebug enabled...elif [ "$1" == "debug" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail -e XDEBUG_SESSION=1)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" php artisan "$@")elsesail_is_not_runningfi# Proxy the "test" command to the "php artisan test" Artisan command...elif [ "$1" == "test" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" php artisan test "$@")elsesail_is_not_runningfi# Proxy the "phpunit" command to "php vendor/bin/phpunit"...elif [ "$1" == "phpunit" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" php vendor/bin/phpunit "$@")elsesail_is_not_runningfi# Proxy the "pest" command to "php vendor/bin/pest"...elif [ "$1" == "pest" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" php vendor/bin/pest "$@")elsesail_is_not_runningfi# Proxy the "pint" command to "php vendor/bin/pint"...elif [ "$1" == "pint" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" php vendor/bin/pint "$@")elsesail_is_not_runningfi# Proxy the "dusk" command to the "php artisan dusk" Artisan command...elif [ "$1" == "dusk" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=(-e "APP_URL=http://${APP_SERVICE}")ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub")ARGS+=("$APP_SERVICE" php artisan dusk "$@")elsesail_is_not_runningfi# Proxy the "dusk:fails" command to the "php artisan dusk:fails" Artisan command...elif [ "$1" == "dusk:fails" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=(-e "APP_URL=http://${APP_SERVICE}")ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub")ARGS+=("$APP_SERVICE" php artisan dusk:fails "$@")elsesail_is_not_runningfi# Initiate a Laravel Tinker session within the application container...elif [ "$1" == "tinker" ] ; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" php artisan tinker)elsesail_is_not_runningfi# Proxy Node commands to the "node" binary on the application container...elif [ "$1" == "node" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" node "$@")elsesail_is_not_runningfi# Proxy NPM commands to the "npm" binary on the application container...elif [ "$1" == "npm" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" npm "$@")elsesail_is_not_runningfi# Proxy NPX commands to the "npx" binary on the application container...elif [ "$1" == "npx" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" npx "$@")elsesail_is_not_runningfi# Proxy YARN commands to the "yarn" binary on the application container...elif [ "$1" == "yarn" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" yarn "$@")elsesail_is_not_runningfi# Initiate a MySQL CLI terminal session within the "mysql" container...elif [ "$1" == "mysql" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec)[ ! -t 0 ] && ARGS+=(-T)ARGS+=(mysql bash -c)ARGS+=("MYSQL_PWD=\${MYSQL_PASSWORD} mysql -u \${MYSQL_USER} \${MYSQL_DATABASE}")elsesail_is_not_runningfi# Initiate a MySQL CLI terminal session within the "mariadb" container...elif [ "$1" == "mariadb" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec)[ ! -t 0 ] && ARGS+=(-T)ARGS+=(mariadb bash -c)ARGS+=("MYSQL_PWD=\${MYSQL_PASSWORD} mysql -u \${MYSQL_USER} \${MYSQL_DATABASE}")elsesail_is_not_runningfi# Initiate a PostgreSQL CLI terminal session within the "pgsql" container...elif [ "$1" == "psql" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec)[ ! -t 0 ] && ARGS+=(-T)ARGS+=(pgsql bash -c)ARGS+=("PGPASSWORD=\${PGPASSWORD} psql -U \${POSTGRES_USER} \${POSTGRES_DB}")elsesail_is_not_runningfi# Initiate a Bash shell within the application container...elif [ "$1" == "shell" ] || [ "$1" == "bash" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec -u sail)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" bash "$@")elsesail_is_not_runningfi# Initiate a root user Bash shell within the application container...elif [ "$1" == "root-shell" ] || [ "$1" == "root-bash" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec)[ ! -t 0 ] && ARGS+=(-T)ARGS+=("$APP_SERVICE" bash "$@")elsesail_is_not_runningfi# Initiate a Redis CLI terminal session within the "redis" container...elif [ "$1" == "redis" ] ; thenshift 1if [ "$EXEC" == "yes" ]; thenARGS+=(exec)[ ! -t 0 ] && ARGS+=(-T)ARGS+=(redis redis-cli)elsesail_is_not_runningfi# Share the site...elif [ "$1" == "share" ]; thenshift 1if [ "$EXEC" == "yes" ]; thendocker run --init --rm -p "$SAIL_SHARE_DASHBOARD":4040 -t beyondcodegmbh/expose-server:latest share http://host.docker.internal:"$APP_PORT" \--server-host="$SAIL_SHARE_SERVER_HOST" \--server-port="$SAIL_SHARE_SERVER_PORT" \--auth="$SAIL_SHARE_TOKEN" \--server="$SAIL_SHARE_SERVER" \--subdomain="$SAIL_SHARE_SUBDOMAIN" \--domain="$SAIL_SHARE_DOMAIN" \"$@"exitelsesail_is_not_runningfi# Open the site...elif [ "$1" == "open" ]; thenshift 1if [ "$EXEC" == "yes" ]; thenopen $APP_URLexitelsesail_is_not_runningfi# Pass unknown commands to the "docker-compose" binary...elseARGS+=("$@")fi# Run Docker Compose with the defined arguments..."${DOCKER_COMPOSE[@]}" "${ARGS[@]}"