# StackShip — OpenClaw Stack
# Generated by: stackship deploy openclaw
# Docs: https://github.com/ai-engineering-lab/stackship

services:
  # One-off: fix volume permissions so node user can write (canvas, cron, etc.)
  openclaw-init:
    image: alpine
    volumes:
      - openclaw_data:/data
    command: sh -c "chown -R 1000:1000 /data 2>/dev/null || true"
    user: root
    restart: "no"

  openclaw:
    image: ghcr.io/openclaw/openclaw:latest
    container_name: stackship-openclaw
    restart: unless-stopped
    ports:
      - "{{ gateway_port | default('18789') }}:18789"
    volumes:
      - openclaw_data:/home/node/.openclaw
      - ./config:/app/config:ro
    env_file:
      - .env
    environment:
      - OPENCLAW_HOST=0.0.0.0
      - OPENCLAW_CONFIG_PATH=/app/config/openclaw.json
      - OLLAMA_HOST=http://ollama:11434
      - QDRANT_URL=http://qdrant:6333
    depends_on:
      openclaw-init:
        condition: service_completed_successfully
      ollama:
        condition: service_started
      qdrant:
        condition: service_healthy
    networks:
      - stackship

  ollama:
    image: ollama/ollama:latest
    container_name: stackship-ollama
    restart: unless-stopped
{% if ollama_port is not none %}
    ports:
      - "{{ ollama_port }}:11434"
{% endif %}
{% if gpu %}
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
{% endif %}
    volumes:
      - ollama_models:/root/.ollama
    networks:
      - stackship

  qdrant:
    image: qdrant/qdrant:latest
    container_name: stackship-qdrant
    restart: unless-stopped
    ports:
      - "6333:6333"
    volumes:
      - qdrant_data:/qdrant/storage
    healthcheck:
      # Qdrant image has no curl/wget; use TCP check (bash /dev/tcp)
      test: ["CMD-SHELL", "bash -c ':> /dev/tcp/127.0.0.1/6333' || exit 1"]
      interval: 5s
      timeout: 5s
      retries: 10
      start_period: 15s
    networks:
      - stackship

volumes:
  openclaw_data:
  ollama_models:
  qdrant_data:

networks:
  stackship:
    driver: bridge
