sail 18 KB

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