Files
merchbay/run.sh
2025-08-12 00:28:17 +08:00

69 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Helper script for docker compose workflow
# Usage examples:
# ./run.sh up # build (if needed) and start in background
# ./run.sh rebuild # force full rebuild (no cache) and start
# ./run.sh down # stop and remove containers
# ./run.sh logs # follow logs
# ./run.sh artisan migrate
# ./run.sh sh # shell into PHP app container
# ./run.sh restart # restart containers
# ./run.sh build # build images (uses cache)
CMD=${1:-up}
shift || true
case "$CMD" in
build)
echo "[build] Building images (with cache)..."
docker compose build
;;
up)
echo "[up] Starting services (build if needed)..."
docker compose up -d --build
;;
rebuild)
echo "[rebuild] Full rebuild without cache..."
docker compose down || true
docker compose build --no-cache
docker compose up -d
;;
down)
echo "[down] Stopping and removing services..."
docker compose down
;;
restart)
echo "[restart] Restarting services..."
docker compose restart
;;
logs)
echo "[logs] Following logs (Ctrl+C to exit)..."
docker compose logs -f --tail=200 "$@"
;;
artisan)
echo "[artisan] php artisan $*"
docker compose exec app php artisan "$@"
;;
sh)
echo "[sh] Opening shell in app container..."
docker compose exec app sh
;;
*)
cat <<EOF
Usage: ./run.sh <command> [args]
Commands:
up Build (if needed) and start containers
build Build images using cache
rebuild Rebuild images without cache then start
down Stop and remove containers
restart Restart running containers
logs Follow logs (pass service names optionally)
artisan Run php artisan <args>
sh Shell into app container
EOF
exit 1
;;
esac