diff --git a/scripts/dev.sh b/scripts/dev.sh new file mode 100755 index 0000000..41910ac --- /dev/null +++ b/scripts/dev.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# Lifecycle commands for the local dev stack (mysql + api-server + web-view). +# Bots (telegram-bot, transfer-bot) are gated behind a compose 'bots' profile +# and do not start with 'up'. Status is used by scripts/bot_cli.sh. +set -euo pipefail + +usage() { + cat <<'EOF' +Lifecycle for the dev stack. + +Usage: + scripts/dev.sh up Start mysql + api-server + web-view in the background. + scripts/dev.sh down Stop the stack. mysql volume kept (DB persists). + scripts/dev.sh reset-db Stop the stack AND drop the mysql volume; then start. + scripts/dev.sh logs Tail logs from the running stack. + scripts/dev.sh status Print 'OK' if mysql is running, else exit 1. + +Environment: + NO_SUDO=1 Skip the 'sudo' prefix (use if your user is in the docker group). +EOF +} + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${ROOT_DIR}" + +SUDO="sudo" +[[ "${NO_SUDO:-0}" == "1" ]] && SUDO="" +# shellcheck disable=SC2206 +COMPOSE=(${SUDO} docker compose -f docker-compose.yml -f docker-compose.override.yml) + +if [[ ! -f .env ]]; then + echo "ERROR: .env not found at repo root. Run: cp envs/dev/.env.example .env (then edit)." >&2 + exit 2 +fi + +case "${1:-}" in + up) + "${COMPOSE[@]}" up -d --build mysql api-server web-view + "${COMPOSE[@]}" ps + ;; + down) + "${COMPOSE[@]}" down + ;; + reset-db) + "${COMPOSE[@]}" down --volumes + "${COMPOSE[@]}" up -d --build mysql api-server web-view + ;; + logs) + "${COMPOSE[@]}" logs -f mysql api-server web-view + ;; + status) + if "${COMPOSE[@]}" ps --status running --services 2>/dev/null | grep -q '^mysql$'; then + echo OK + else + echo "ERROR: dev stack not running. Run 'scripts/dev.sh up' first." >&2 + exit 1 + fi + ;; + -h|--help|help) + usage + exit 0 + ;; + "") + usage >&2 + exit 1 + ;; + *) + echo "unknown command: $1" >&2 + usage >&2 + exit 1 + ;; +esac