sail 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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 APP_USER=${APP_USER:-"sail"}
  134. export DB_PORT=${DB_PORT:-3306}
  135. export WWWUSER=${WWWUSER:-$UID}
  136. export WWWGROUP=${WWWGROUP:-$(id -g)}
  137. export SAIL_FILES=${SAIL_FILES:-""}
  138. export SAIL_SHARE_DASHBOARD=${SAIL_SHARE_DASHBOARD:-4040}
  139. export SAIL_SHARE_SERVER_HOST=${SAIL_SHARE_SERVER_HOST:-"laravel-sail.site"}
  140. export SAIL_SHARE_SERVER_PORT=${SAIL_SHARE_SERVER_PORT:-8080}
  141. export SAIL_SHARE_SUBDOMAIN=${SAIL_SHARE_SUBDOMAIN:-""}
  142. export SAIL_SHARE_DOMAIN=${SAIL_SHARE_DOMAIN:-"$SAIL_SHARE_SERVER_HOST"}
  143. export SAIL_SHARE_SERVER=${SAIL_SHARE_SERVER:-""}
  144. # Function that outputs Sail is not running...
  145. function sail_is_not_running {
  146. echo "${BOLD}Sail is not running.${NC}" >&2
  147. echo "" >&2
  148. echo "${BOLD}You may Sail using the following commands:${NC} './vendor/bin/sail up' or './vendor/bin/sail up -d'" >&2
  149. exit 1
  150. }
  151. # Define Docker Compose command prefix...
  152. if docker compose &> /dev/null; then
  153. DOCKER_COMPOSE=(docker compose)
  154. else
  155. DOCKER_COMPOSE=(docker-compose)
  156. fi
  157. if [ -n "$SAIL_FILES" ]; then
  158. # Convert SAIL_FILES to an array...
  159. IFS=':' read -ra SAIL_FILES <<< "$SAIL_FILES"
  160. for FILE in "${SAIL_FILES[@]}"; do
  161. if [ -f "$FILE" ]; then
  162. DOCKER_COMPOSE+=(-f "$FILE")
  163. else
  164. echo "${BOLD}Unable to find Docker Compose file: '${FILE}'${NC}" >&2
  165. exit 1
  166. fi
  167. done
  168. fi
  169. EXEC="yes"
  170. if [ -z "$SAIL_SKIP_CHECKS" ]; then
  171. # Ensure that Docker is running...
  172. if ! docker info > /dev/null 2>&1; then
  173. echo "${BOLD}Docker is not running.${NC}" >&2
  174. exit 1
  175. fi
  176. # Determine if Sail is currently up...
  177. if "${DOCKER_COMPOSE[@]}" ps "$APP_SERVICE" 2>&1 | grep 'Exit\|exited'; then
  178. echo "${BOLD}Shutting down old Sail processes...${NC}" >&2
  179. "${DOCKER_COMPOSE[@]}" down > /dev/null 2>&1
  180. EXEC="no"
  181. elif [ -z "$("${DOCKER_COMPOSE[@]}" ps -q)" ]; then
  182. EXEC="no"
  183. fi
  184. fi
  185. ARGS=()
  186. # Proxy PHP commands to the "php" binary on the application container...
  187. if [ "$1" == "php" ]; then
  188. shift 1
  189. if [ "$EXEC" == "yes" ]; then
  190. ARGS+=(exec -u "$APP_USER")
  191. [ ! -t 0 ] && ARGS+=(-T)
  192. ARGS+=("$APP_SERVICE" "php")
  193. else
  194. sail_is_not_running
  195. fi
  196. # Proxy vendor binary commands on the application container...
  197. elif [ "$1" == "bin" ]; then
  198. shift 1
  199. if [ "$EXEC" == "yes" ]; then
  200. CMD=$1
  201. shift 1
  202. ARGS+=(exec -u "$APP_USER")
  203. [ ! -t 0 ] && ARGS+=(-T)
  204. ARGS+=("$APP_SERVICE" ./vendor/bin/"$CMD")
  205. else
  206. sail_is_not_running
  207. fi
  208. # Proxy commands on the application container...
  209. elif [ "$1" == "run" ]; then
  210. shift 1
  211. if [ "$EXEC" == "yes" ]; then
  212. CMD=$1
  213. shift 1
  214. ARGS+=(exec -u "$APP_USER")
  215. [ ! -t 0 ] && ARGS+=(-T)
  216. ARGS+=("$APP_SERVICE" "$CMD")
  217. else
  218. sail_is_not_running
  219. fi
  220. # Proxy docker-compose commands to the docker-compose binary on the application container...
  221. elif [ "$1" == "docker-compose" ]; then
  222. shift 1
  223. if [ "$EXEC" == "yes" ]; then
  224. ARGS+=(exec -u "$APP_USER")
  225. [ ! -t 0 ] && ARGS+=(-T)
  226. ARGS+=("$APP_SERVICE" "${DOCKER_COMPOSE[@]}")
  227. else
  228. sail_is_not_running
  229. fi
  230. # Proxy Composer commands to the "composer" binary on the application container...
  231. elif [ "$1" == "composer" ]; then
  232. shift 1
  233. if [ "$EXEC" == "yes" ]; then
  234. ARGS+=(exec -u "$APP_USER")
  235. [ ! -t 0 ] && ARGS+=(-T)
  236. ARGS+=("$APP_SERVICE" "composer")
  237. else
  238. sail_is_not_running
  239. fi
  240. # Proxy Artisan commands to the "artisan" binary on the application container...
  241. elif [ "$1" == "artisan" ] || [ "$1" == "art" ] || [ "$1" == "a" ]; then
  242. shift 1
  243. if [ "$EXEC" == "yes" ]; then
  244. ARGS+=(exec -u "$APP_USER")
  245. [ ! -t 0 ] && ARGS+=(-T)
  246. ARGS+=("$APP_SERVICE" php artisan)
  247. else
  248. sail_is_not_running
  249. fi
  250. # Proxy the "debug" command to the "php artisan" binary on the application container with xdebug enabled...
  251. elif [ "$1" == "debug" ]; then
  252. shift 1
  253. if [ "$EXEC" == "yes" ]; then
  254. ARGS+=(exec -u "$APP_USER" -e XDEBUG_TRIGGER=1)
  255. [ ! -t 0 ] && ARGS+=(-T)
  256. ARGS+=("$APP_SERVICE" php artisan)
  257. else
  258. sail_is_not_running
  259. fi
  260. # Proxy the "test" command to the "php artisan test" Artisan command...
  261. elif [ "$1" == "test" ]; then
  262. shift 1
  263. if [ "$EXEC" == "yes" ]; then
  264. ARGS+=(exec -u "$APP_USER")
  265. [ ! -t 0 ] && ARGS+=(-T)
  266. ARGS+=("$APP_SERVICE" php artisan test)
  267. else
  268. sail_is_not_running
  269. fi
  270. # Proxy the "phpunit" command to "php vendor/bin/phpunit"...
  271. elif [ "$1" == "phpunit" ]; then
  272. shift 1
  273. if [ "$EXEC" == "yes" ]; then
  274. ARGS+=(exec -u "$APP_USER")
  275. [ ! -t 0 ] && ARGS+=(-T)
  276. ARGS+=("$APP_SERVICE" php vendor/bin/phpunit)
  277. else
  278. sail_is_not_running
  279. fi
  280. # Proxy the "pest" command to "php vendor/bin/pest"...
  281. elif [ "$1" == "pest" ]; then
  282. shift 1
  283. if [ "$EXEC" == "yes" ]; then
  284. ARGS+=(exec -u "$APP_USER")
  285. [ ! -t 0 ] && ARGS+=(-T)
  286. ARGS+=("$APP_SERVICE" php vendor/bin/pest)
  287. else
  288. sail_is_not_running
  289. fi
  290. # Proxy the "pint" command to "php vendor/bin/pint"...
  291. elif [ "$1" == "pint" ]; then
  292. shift 1
  293. if [ "$EXEC" == "yes" ]; then
  294. ARGS+=(exec -u "$APP_USER")
  295. [ ! -t 0 ] && ARGS+=(-T)
  296. ARGS+=("$APP_SERVICE" php vendor/bin/pint)
  297. else
  298. sail_is_not_running
  299. fi
  300. # Proxy the "dusk" command to the "php artisan dusk" Artisan command...
  301. elif [ "$1" == "dusk" ]; then
  302. shift 1
  303. if [ "$EXEC" == "yes" ]; then
  304. ARGS+=(exec -u "$APP_USER")
  305. [ ! -t 0 ] && ARGS+=(-T)
  306. ARGS+=(-e "APP_URL=http://${APP_SERVICE}")
  307. ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub")
  308. ARGS+=("$APP_SERVICE" php artisan dusk)
  309. else
  310. sail_is_not_running
  311. fi
  312. # Proxy the "dusk:fails" command to the "php artisan dusk:fails" Artisan command...
  313. elif [ "$1" == "dusk:fails" ]; then
  314. shift 1
  315. if [ "$EXEC" == "yes" ]; then
  316. ARGS+=(exec -u "$APP_USER")
  317. [ ! -t 0 ] && ARGS+=(-T)
  318. ARGS+=(-e "APP_URL=http://${APP_SERVICE}")
  319. ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub")
  320. ARGS+=("$APP_SERVICE" php artisan dusk:fails)
  321. else
  322. sail_is_not_running
  323. fi
  324. # Initiate a Laravel Tinker session within the application container...
  325. elif [ "$1" == "tinker" ]; then
  326. shift 1
  327. if [ "$EXEC" == "yes" ]; then
  328. ARGS+=(exec -u "$APP_USER")
  329. [ ! -t 0 ] && ARGS+=(-T)
  330. ARGS+=("$APP_SERVICE" php artisan tinker)
  331. else
  332. sail_is_not_running
  333. fi
  334. # Proxy Node commands to the "node" binary on the application container...
  335. elif [ "$1" == "node" ]; then
  336. shift 1
  337. if [ "$EXEC" == "yes" ]; then
  338. ARGS+=(exec -u "$APP_USER")
  339. [ ! -t 0 ] && ARGS+=(-T)
  340. ARGS+=("$APP_SERVICE" node)
  341. else
  342. sail_is_not_running
  343. fi
  344. # Proxy NPM commands to the "npm" binary on the application container...
  345. elif [ "$1" == "npm" ]; then
  346. shift 1
  347. if [ "$EXEC" == "yes" ]; then
  348. ARGS+=(exec -u "$APP_USER")
  349. [ ! -t 0 ] && ARGS+=(-T)
  350. ARGS+=("$APP_SERVICE" npm)
  351. else
  352. sail_is_not_running
  353. fi
  354. # Proxy NPX commands to the "npx" binary on the application container...
  355. elif [ "$1" == "npx" ]; then
  356. shift 1
  357. if [ "$EXEC" == "yes" ]; then
  358. ARGS+=(exec -u "$APP_USER")
  359. [ ! -t 0 ] && ARGS+=(-T)
  360. ARGS+=("$APP_SERVICE" npx)
  361. else
  362. sail_is_not_running
  363. fi
  364. # Proxy PNPM commands to the "pnpm" binary on the application container...
  365. elif [ "$1" == "pnpm" ]; then
  366. shift 1
  367. if [ "$EXEC" == "yes" ]; then
  368. ARGS+=(exec -u "$APP_USER")
  369. [ ! -t 0 ] && ARGS+=(-T)
  370. ARGS+=("$APP_SERVICE" pnpm)
  371. else
  372. sail_is_not_running
  373. fi
  374. # Proxy PNPX commands to the "pnpx" binary on the application container...
  375. elif [ "$1" == "pnpx" ]; then
  376. shift 1
  377. if [ "$EXEC" == "yes" ]; then
  378. ARGS+=(exec -u "$APP_USER")
  379. [ ! -t 0 ] && ARGS+=(-T)
  380. ARGS+=("$APP_SERVICE" pnpx)
  381. else
  382. sail_is_not_running
  383. fi
  384. # Proxy Yarn commands to the "yarn" binary on the application container...
  385. elif [ "$1" == "yarn" ]; then
  386. shift 1
  387. if [ "$EXEC" == "yes" ]; then
  388. ARGS+=(exec -u "$APP_USER")
  389. [ ! -t 0 ] && ARGS+=(-T)
  390. ARGS+=("$APP_SERVICE" yarn)
  391. else
  392. sail_is_not_running
  393. fi
  394. # Proxy Bun commands to the "bun" binary on the application container...
  395. elif [ "$1" == "bun" ]; then
  396. shift 1
  397. if [ "$EXEC" == "yes" ]; then
  398. ARGS+=(exec -u "$APP_USER")
  399. [ ! -t 0 ] && ARGS+=(-T)
  400. ARGS+=("$APP_SERVICE" bun)
  401. else
  402. sail_is_not_running
  403. fi
  404. # Proxy Bun X commands to the "bunx" binary on the application container...
  405. elif [ "$1" == "bunx" ]; then
  406. shift 1
  407. if [ "$EXEC" == "yes" ]; then
  408. ARGS+=(exec -u "$APP_USER")
  409. [ ! -t 0 ] && ARGS+=(-T)
  410. ARGS+=("$APP_SERVICE" bunx)
  411. else
  412. sail_is_not_running
  413. fi
  414. # Initiate a MySQL CLI terminal session within the "mysql" container...
  415. elif [ "$1" == "mysql" ]; then
  416. shift 1
  417. if [ "$EXEC" == "yes" ]; then
  418. ARGS+=(exec)
  419. [ ! -t 0 ] && ARGS+=(-T)
  420. ARGS+=(mysql bash -c)
  421. ARGS+=("MYSQL_PWD=\${MYSQL_PASSWORD} mysql -u \${MYSQL_USER} \${MYSQL_DATABASE} \${MYSQL_EXTRA_OPTIONS}")
  422. else
  423. sail_is_not_running
  424. fi
  425. # Initiate a MySQL CLI terminal session within the "mariadb" container...
  426. elif [ "$1" == "mariadb" ]; then
  427. shift 1
  428. if [ "$EXEC" == "yes" ]; then
  429. ARGS+=(exec)
  430. [ ! -t 0 ] && ARGS+=(-T)
  431. ARGS+=(mariadb bash -c)
  432. ARGS+=("MYSQL_PWD=\${MYSQL_PASSWORD} mariadb -u \${MYSQL_USER} \${MYSQL_DATABASE}")
  433. else
  434. sail_is_not_running
  435. fi
  436. # Initiate a PostgreSQL CLI terminal session within the "pgsql" container...
  437. elif [ "$1" == "psql" ]; then
  438. shift 1
  439. if [ "$EXEC" == "yes" ]; then
  440. ARGS+=(exec)
  441. [ ! -t 0 ] && ARGS+=(-T)
  442. ARGS+=(pgsql bash -c)
  443. ARGS+=("PGPASSWORD=\${PGPASSWORD} psql -U \${POSTGRES_USER} \${POSTGRES_DB}")
  444. else
  445. sail_is_not_running
  446. fi
  447. # Initiate a Bash shell within the application container...
  448. elif [ "$1" == "shell" ] || [ "$1" == "bash" ]; then
  449. shift 1
  450. if [ "$EXEC" == "yes" ]; then
  451. ARGS+=(exec -u "$APP_USER")
  452. [ ! -t 0 ] && ARGS+=(-T)
  453. ARGS+=("$APP_SERVICE" bash)
  454. else
  455. sail_is_not_running
  456. fi
  457. # Initiate a root user Bash shell within the application container...
  458. elif [ "$1" == "root-shell" ] || [ "$1" == "root-bash" ]; then
  459. shift 1
  460. if [ "$EXEC" == "yes" ]; then
  461. ARGS+=(exec -u root)
  462. [ ! -t 0 ] && ARGS+=(-T)
  463. ARGS+=("$APP_SERVICE" bash)
  464. else
  465. sail_is_not_running
  466. fi
  467. # Initiate a MongoDB Shell within the "mongodb" container...
  468. elif [ "$1" == "mongodb" ]; then
  469. shift 1
  470. if [ "$EXEC" == "yes" ]; then
  471. ARGS+=(exec)
  472. [ ! -t 0 ] && ARGS+=(-T)
  473. ARGS+=(mongodb mongosh --port "${FORWARD_MONGODB_PORT:-27017}" --username "$MONGODB_USERNAME" --password "$MONGODB_PASSWORD" --authenticationDatabase admin)
  474. else
  475. sail_is_not_running
  476. fi
  477. # Initiate a Redis CLI terminal session within the "redis" container...
  478. elif [ "$1" == "redis" ]; then
  479. shift 1
  480. if [ "$EXEC" == "yes" ]; then
  481. ARGS+=(exec)
  482. [ ! -t 0 ] && ARGS+=(-T)
  483. ARGS+=(redis redis-cli)
  484. else
  485. sail_is_not_running
  486. fi
  487. # Initiate a Valkey CLI terminal session within the "valkey" container...
  488. elif [ "$1" == "valkey" ]; then
  489. shift 1
  490. if [ "$EXEC" == "yes" ]; then
  491. ARGS+=(exec)
  492. [ ! -t 0 ] && ARGS+=(-T)
  493. ARGS+=(valkey valkey-cli)
  494. else
  495. sail_is_not_running
  496. fi
  497. # Share the site...
  498. elif [ "$1" == "share" ]; then
  499. shift 1
  500. if [ "$EXEC" == "yes" ]; then
  501. 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" \
  502. --server-host="$SAIL_SHARE_SERVER_HOST" \
  503. --server-port="$SAIL_SHARE_SERVER_PORT" \
  504. --auth="$SAIL_SHARE_TOKEN" \
  505. --server="$SAIL_SHARE_SERVER" \
  506. --subdomain="$SAIL_SHARE_SUBDOMAIN" \
  507. --domain="$SAIL_SHARE_DOMAIN" \
  508. "$@"
  509. exit
  510. else
  511. sail_is_not_running
  512. fi
  513. # Open the site...
  514. elif [ "$1" == "open" ]; then
  515. shift 1
  516. if command -v open &>/dev/null; then
  517. OPEN="open"
  518. elif command -v xdg-open &>/dev/null; then
  519. OPEN="xdg-open"
  520. else
  521. echo "Neither open nor xdg-open is available. Exiting."
  522. exit 1
  523. fi
  524. if [ "$EXEC" == "yes" ]; then
  525. if [[ -n "$APP_PORT" && "$APP_PORT" != "80" ]]; then
  526. FULL_URL="${APP_URL}:${APP_PORT}"
  527. else
  528. FULL_URL="$APP_URL"
  529. fi
  530. $OPEN "$FULL_URL"
  531. exit
  532. else
  533. sail_is_not_running
  534. fi
  535. fi
  536. # Run Docker Compose with the defined arguments...
  537. "${DOCKER_COMPOSE[@]}" "${ARGS[@]}" "$@"