#!/usr/bin/env bash set -euo pipefail SERVICE=pagepiper WEB_PORT=8521 CLOUD_WEB_PORT=8533 COMPOSE_FILE="compose.yml" COMPOSE_CLOUD_FILE="compose.cloud.yml" CLOUD_PROJECT="pagepiper-cloud" OVERRIDE_ARGS=() [[ -f "compose.override.yml" ]] && OVERRIDE_ARGS=(-f compose.override.yml) usage() { echo "Usage: $0 {start|stop|restart|status|logs [svc]|open|build|test|update" echo " |cloud-start|cloud-stop|cloud-restart|cloud-status|cloud-logs [svc]|cloud-build|cloud-update}" exit 1 } cmd="${1:-help}" shift || true case "$cmd" in start) docker compose -f "$COMPOSE_FILE" "${OVERRIDE_ARGS[@]}" up -d --build echo "Pagepiper running → http://localhost:${WEB_PORT}" ;; stop) docker compose -f "$COMPOSE_FILE" "${OVERRIDE_ARGS[@]}" down ;; restart) docker compose -f "$COMPOSE_FILE" "${OVERRIDE_ARGS[@]}" down docker compose -f "$COMPOSE_FILE" "${OVERRIDE_ARGS[@]}" up -d --build echo "Pagepiper running → http://localhost:${WEB_PORT}" ;; status) docker compose -f "$COMPOSE_FILE" "${OVERRIDE_ARGS[@]}" ps ;; logs) docker compose -f "$COMPOSE_FILE" "${OVERRIDE_ARGS[@]}" logs -f "${1:-}" ;; open) xdg-open "http://localhost:${WEB_PORT}" 2>/dev/null || open "http://localhost:${WEB_PORT}" ;; build) docker compose -f "$COMPOSE_FILE" "${OVERRIDE_ARGS[@]}" build --no-cache ;; test) conda run -n cf pytest tests/ -v ;; update) git pull docker compose -f "$COMPOSE_FILE" "${OVERRIDE_ARGS[@]}" down docker compose -f "$COMPOSE_FILE" "${OVERRIDE_ARGS[@]}" up -d --build echo "Pagepiper updated and running → http://localhost:${WEB_PORT}" ;; cloud-start) docker compose -f "$COMPOSE_CLOUD_FILE" -p "$CLOUD_PROJECT" up -d --build echo "Pagepiper cloud running → http://localhost:${CLOUD_WEB_PORT}" ;; cloud-stop) docker compose -f "$COMPOSE_CLOUD_FILE" -p "$CLOUD_PROJECT" down ;; cloud-restart) docker compose -f "$COMPOSE_CLOUD_FILE" -p "$CLOUD_PROJECT" down docker compose -f "$COMPOSE_CLOUD_FILE" -p "$CLOUD_PROJECT" up -d --build echo "Pagepiper cloud running → http://localhost:${CLOUD_WEB_PORT}" ;; cloud-status) docker compose -f "$COMPOSE_CLOUD_FILE" -p "$CLOUD_PROJECT" ps ;; cloud-logs) docker compose -f "$COMPOSE_CLOUD_FILE" -p "$CLOUD_PROJECT" logs -f "${1:-}" ;; cloud-build) docker compose -f "$COMPOSE_CLOUD_FILE" -p "$CLOUD_PROJECT" build --no-cache ;; cloud-update) git pull docker compose -f "$COMPOSE_CLOUD_FILE" -p "$CLOUD_PROJECT" down docker compose -f "$COMPOSE_CLOUD_FILE" -p "$CLOUD_PROJECT" up -d --build echo "Pagepiper cloud updated and running → http://localhost:${CLOUD_WEB_PORT}" ;; *) usage ;; esac