services:
  # ---------------------------------------------
  # 1. The Cloud Server running the Head Model
  # ---------------------------------------------
  fsl-server:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: fsl-server
    command: uv run python src/nodes/server_node.py
    ports:
      - "50051:50051"
    environment:
      - PYTHONUNBUFFERED=1
      - PYTHONPATH=/app
      - FSL_DEVICE=${FSL_DEVICE:-cpu}
      - UV_PROJECT_ENVIRONMENT=/opt/venv
      - UV_LINK_MODE=copy
      - UV_CACHE_DIR=/root/.cache/uv
      - UV_NO_SYNC=1
      - FSL_CONFIG_PATH=${FSL_CONFIG_PATH:-/app/config.yaml}
      - SESSION_ID=${SESSION_ID:-}
      - SCENARIO_ID=${SCENARIO_ID:-}
    volumes:
      - .:/app:delegated
      - ./results:/app/results:delegated
      - ./bestweights:/app/bestweights:delegated
      - uv-cache:/root/.cache/uv
    healthcheck:
      test: [ "CMD-SHELL", "uv run python -c \"import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.settimeout(1); s.connect(('127.0.0.1', 50051)); s.close()\" || exit 1" ]
      interval: 5s
      timeout: 3s
      retries: 5
      start_period: 2s

  # ---------------------------------------------
  # 2. The Edge Client running the ClientLSTM
  # ---------------------------------------------
  fsl-client:
    build:
      context: .
      dockerfile: Dockerfile
    command: uv run python src/nodes/client_node.py
    depends_on:
      fsl-server:
        condition: service_healthy
    environment:
      - PYTHONUNBUFFERED=1
      - PYTHONPATH=/app
      - FSL_DEVICE=${FSL_DEVICE:-cpu}
      - UV_PROJECT_ENVIRONMENT=/opt/venv
      - UV_LINK_MODE=copy
      - UV_CACHE_DIR=/root/.cache/uv
      - UV_NO_SYNC=1
      - FSL_CONFIG_PATH=${FSL_CONFIG_PATH:-/app/config.yaml}
      - SESSION_ID=${SESSION_ID:-}
      - SCENARIO_ID=${SCENARIO_ID:-}
    volumes:
      - .:/app:delegated
      - ./dataset:/app/dataset:delegated
      - ./results:/app/results:delegated
      - ./bestweights:/app/bestweights:delegated
      - uv-cache:/root/.cache/uv
    working_dir: /app

volumes:
  uv-cache:
