#!/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" echo " |cloud:start|cloud:stop|cloud:restart|cloud:status|cloud:logs [svc]|cloud:build}" 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 ;; 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 ;; *) usage ;; esac