#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT_DIR" if ! command -v docker >/dev/null 2>&1; then echo "[deploy] Docker is required but was not found." exit 1 fi if docker compose version >/dev/null 2>&1; then COMPOSE=(docker compose) elif command -v docker-compose >/dev/null 2>&1; then COMPOSE=(docker-compose) else echo "[deploy] Docker Compose is required but was not found." exit 1 fi if [ ! -f .env.local ]; then cp .env.example .env.local echo "[deploy] Created .env.local from .env.example" echo "[deploy] Real generation requires API keys in .env.local. Empty keys keep mock/local flows available." fi mkdir -p .runtime/data .runtime/uploads .runtime/generated-results if [ -z "${APP_PORT:-}" ] && [ -f .env.local ]; then APP_PORT_FROM_FILE="$(sed -n 's/^APP_PORT=//p' .env.local | tail -n 1)" APP_PORT_FROM_FILE="${APP_PORT_FROM_FILE//\"/}" if [ -n "$APP_PORT_FROM_FILE" ]; then export APP_PORT="$APP_PORT_FROM_FILE" fi fi "${COMPOSE[@]}" up -d --build "${COMPOSE[@]}" ps HEALTH_URL="http://127.0.0.1:${APP_PORT:-3000}/api/health" if command -v curl >/dev/null 2>&1; then echo "[deploy] Waiting for health check: ${HEALTH_URL}" for _ in $(seq 1 40); do if curl -fsS "$HEALTH_URL" >/dev/null 2>&1; then echo "[deploy] Health check passed." break fi sleep 2 done if ! curl -fsS "$HEALTH_URL" >/dev/null 2>&1; then echo "[deploy] Health check did not pass yet. Inspect logs with: ${COMPOSE[*]} logs -f zhinian-aigc" fi fi echo "[deploy] 智念AIGC平台 is available at http://127.0.0.1:${APP_PORT:-3000}" echo "[deploy] If this is a public server, set NEXT_PUBLIC_APP_URL in .env.local to your domain." echo "[deploy] Web service and zhinian-worker are both managed by Docker Compose." echo "[deploy] API docs: docs/API.md" echo "[deploy] OpenAPI: ${HEALTH_URL%/api/health}/api/v1/openapi.json"