didi-lot1-ai/ai_platform/modules/gateway/deploy/deploy.sh

90 lines
1.9 KiB
Bash

#!/usr/bin/env bash
#
# Docker Compose Startup Script for API Gateway
#
# Usage: ./deploy/deploy.sh [OPTIONS]
#
# Options:
# --detach, -d Run in detached mode
# --down Stop and remove containers
# --logs Show logs
# --help, -h Show this help message
#
# Required: Set GATEWAY_API_TOKEN in deploy/.env file.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Load .env file
if [[ -f "$SCRIPT_DIR/.env" ]]; then
echo "Loading environment from: $SCRIPT_DIR/.env"
set -a
source "$SCRIPT_DIR/.env"
set +a
fi
DETACH=""
ACTION="up"
show_help() {
sed -n '2,15p' "$0" | sed 's/^# //' | sed 's/^#//'
exit 0
}
check_required_var() {
local var_name="$1"
if [[ -z "${!var_name:-}" ]]; then
echo "ERROR: Required environment variable $var_name is not set"
echo "Set it in deploy/.env file or export it before running this script"
exit 1
fi
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--detach|-d)
DETACH="-d"
shift
;;
--down)
ACTION="down"
shift
;;
--logs)
ACTION="logs"
shift
;;
--help|-h)
show_help
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Fail-fast required vars
check_required_var "GATEWAY_API_TOKEN"
cd "$SCRIPT_DIR"
case $ACTION in
up)
echo "Starting API Gateway on port 11000"
echo " Routes: /llm/ /audio/ /web/ /catalog/ /health"
echo ""
# shellcheck disable=SC2086
exec docker compose up $DETACH
;;
down)
echo "Stopping API Gateway..."
exec docker compose down
;;
logs)
exec docker compose logs -f
;;
esac