#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib.sh
source "${SCRIPT_DIR}/lib.sh"

if [[ "${SKIP_CLEANUP_V1:-0}" != "1" ]]; then
  "${SCRIPT_DIR}/03_cleanup_v1_legacy.sh" || true
fi

echo "[host] docker compose up -d (mvp)"
BUILD="${BUILD:-0}"
RAY_NODE_IMAGE="${RAY_NODE_IMAGE:-argus/argus-ray-node:vllm011.latest}"

# If the image isn't present locally, force build once.
if [[ "${BUILD}" != "1" ]]; then
  if ! docker image inspect "${RAY_NODE_IMAGE}" >/dev/null 2>&1; then
    BUILD="1"
  fi
fi

if [[ "${BUILD}" == "1" ]]; then
  dc up -d --build
else
  dc up -d
fi

echo "[host] containers:"
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' | (head -n 1 && grep -E "argus-ray-") || true
