diff --git a/backend/services/presence-service/deploy.sh b/backend/services/presence-service/deploy.sh index 8296dc2d..3288f4e4 100644 --- a/backend/services/presence-service/deploy.sh +++ b/backend/services/presence-service/deploy.sh @@ -2,13 +2,16 @@ # ============================================================================= # Presence Service - Individual Deployment Script # ============================================================================= +# Uses shared infrastructure from main docker-compose.yml +# ============================================================================= set -e SERVICE_NAME="presence-service" -CONTAINER_NAME="presence-service" -IMAGE_NAME="presence-service" -PORT=3001 +CONTAINER_NAME="rwa-presence-service" +IMAGE_NAME="services-presence-service" +PORT=3011 +HEALTH_ENDPOINT="http://localhost:${PORT}/api/v1/health" # Colors RED='\033[0;31m' @@ -24,11 +27,18 @@ log_error() { echo -e "${RED}[ERROR]${NC} $1"; } # Get script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SERVICES_DIR="$(dirname "$SCRIPT_DIR")" -# Load environment -if [ -f "$SCRIPT_DIR/.env.production" ]; then - export $(cat "$SCRIPT_DIR/.env.production" | grep -v '^#' | xargs) -fi +# Load environment from parent services directory (shared .env) +load_env() { + if [ -f "$SERVICES_DIR/.env" ]; then + export $(cat "$SERVICES_DIR/.env" | grep -v '^#' | xargs) + log_info "Loaded .env from $SERVICES_DIR" + elif [ -f "$SCRIPT_DIR/.env.production" ]; then + export $(cat "$SCRIPT_DIR/.env.production" | grep -v '^#' | xargs) + log_info "Loaded .env.production from $SCRIPT_DIR" + fi +} case "$1" in build) @@ -44,14 +54,18 @@ case "$1" in ;; start) - log_info "Starting $SERVICE_NAME..." - cd "$SCRIPT_DIR" - docker compose up -d + load_env + log_info "Starting $SERVICE_NAME using shared infrastructure..." + cd "$SERVICES_DIR" + docker compose up -d "$SERVICE_NAME" log_success "$SERVICE_NAME started" + log_info "Waiting for service to be healthy..." + sleep 5 + $0 health ;; start-deps) - log_info "Starting dependencies only..." + log_info "Starting dependencies only (for local development)..." cd "$SCRIPT_DIR" docker compose -f docker-compose.dev.yml up -d log_success "Dependencies started" @@ -59,8 +73,8 @@ case "$1" in stop) log_info "Stopping $SERVICE_NAME..." - cd "$SCRIPT_DIR" - docker compose down + docker stop "$CONTAINER_NAME" 2>/dev/null || true + docker rm "$CONTAINER_NAME" 2>/dev/null || true log_success "$SERVICE_NAME stopped" ;; @@ -76,6 +90,13 @@ case "$1" in $0 start ;; + up) + load_env + log_info "Starting $SERVICE_NAME in foreground..." + cd "$SERVICES_DIR" + docker compose up "$SERVICE_NAME" + ;; + logs) docker logs -f "$CONTAINER_NAME" ;; @@ -84,6 +105,11 @@ case "$1" in docker logs --tail 100 "$CONTAINER_NAME" ;; + logs-all) + cd "$SERVICES_DIR" + docker compose logs -f "$SERVICE_NAME" + ;; + status) if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then log_success "$SERVICE_NAME is running" @@ -95,10 +121,10 @@ case "$1" in health) log_info "Checking health of $SERVICE_NAME..." - if curl -sf "http://localhost:$PORT/api/v1/health" > /dev/null 2>&1; then - HEALTH=$(curl -s "http://localhost:$PORT/api/v1/health") + if curl -sf "$HEALTH_ENDPOINT" > /dev/null 2>&1; then + HEALTH=$(curl -s "$HEALTH_ENDPOINT") log_success "$SERVICE_NAME is healthy" - echo "$HEALTH" + echo "$HEALTH" | jq . 2>/dev/null || echo "$HEALTH" else log_error "$SERVICE_NAME health check failed" exit 1 @@ -158,12 +184,19 @@ case "$1" in clean) log_info "Cleaning up..." - cd "$SCRIPT_DIR" - docker compose down -v - docker rmi "$IMAGE_NAME" 2>/dev/null || true + docker stop "$CONTAINER_NAME" 2>/dev/null || true + docker rm "$CONTAINER_NAME" 2>/dev/null || true log_success "Cleanup completed" ;; + clean-all) + log_info "Cleaning $SERVICE_NAME (removing container and image)..." + docker stop "$CONTAINER_NAME" 2>/dev/null || true + docker rm "$CONTAINER_NAME" 2>/dev/null || true + docker rmi "$IMAGE_NAME" 2>/dev/null || true + log_success "$SERVICE_NAME fully cleaned" + ;; + *) echo "Usage: $0 {command}" echo "" @@ -172,15 +205,17 @@ case "$1" in echo " build-no-cache - Build Docker image without cache" echo "" echo "Service Commands:" - echo " start - Start the full stack (service + dependencies)" + echo " start - Start using shared infrastructure" echo " start-deps - Start dependencies only (for local development)" - echo " stop - Stop all containers" + echo " stop - Stop the service container" echo " stop-deps - Stop dependencies only" echo " restart - Restart the service" + echo " up - Start in foreground mode" echo "" echo "Monitoring Commands:" echo " logs - Follow logs" echo " logs-tail - Show last 100 log lines" + echo " logs-all - Follow logs via docker compose" echo " status - Show service status" echo " health - Check service health" echo "" @@ -198,7 +233,8 @@ case "$1" in echo " test-e2e - Run E2E tests only" echo "" echo "Maintenance Commands:" - echo " clean - Remove containers and images" + echo " clean - Remove container" + echo " clean-all - Remove container and image" exit 1 ;; esac