#!/bin/bash

set -e

echo "=================================="
echo "Deploying Lucos Common Composer Service"
echo "=================================="

ROOT_DIR="/var/www/adpilot/adpilot-common-composer.com"

SERVICES=(
    "/var/www/adpilot/adpilot-common-composer.com"
    "/var/www/adpilot/adpilot-common-composer.com/services/adpilot-indexing-code-parser.com"
    "/var/www/adpilot/adpilot-common-composer.com/services/adpilot-indexing-commit-intel.com"
    "/var/www/adpilot/adpilot-common-composer.com/services/adpilot-indexing-docs-ingestion.com"
    "/var/www/adpilot/adpilot-common-composer.com/services/adpilot-indexing-embedding-engine.com"
    "/var/www/adpilot/adpilot-common-composer.com/services/adpilot-indexing-repo-sync.com"
    "/var/www/adpilot/adpilot-common-composer.com/services/adpilot-rag-service.com"
)

for SERVICE in "${SERVICES[@]}"
do
    echo ""
    echo "----------------------------------"
    echo "Updating: $SERVICE"
    echo "----------------------------------"

    cd "$SERVICE" || {
        echo "Directory not found: $SERVICE"
        exit 1
    }

    git pull
done

echo ""
echo "Building containers..."

cd "$ROOT_DIR" || exit 1

docker compose up -d --build

echo " Lucos Common Composer Service deployment completed."
