# OpenClaw - Personal AI Assistant Docker Compose Configuration
# Official Repository: https://github.com/openclaw/openclaw
# Documentation: https://docs.openclaw.bot

x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  openclaw-gateway:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-ghcr.io/}openclaw/openclaw:${OPENCLAW_VERSION:-2026.2.3}
    environment:
      - TZ=${TZ:-UTC}
      - HOME=/home/node
      - NODE_ENV=production
      - TERM=xterm-256color
      # Gateway configuration
      - OPENCLAW_GATEWAY_TOKEN=${OPENCLAW_GATEWAY_TOKEN}
      - OPENCLAW_GATEWAY_BIND=${OPENCLAW_GATEWAY_BIND:-lan}
      - OPENCLAW_GATEWAY_PORT=${OPENCLAW_GATEWAY_PORT:-18789}
      # Optional: Model API keys (if not using OAuth)
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
      - OPENAI_API_KEY=${OPENAI_API_KEY:-}
      - CLAUDE_AI_SESSION_KEY=${CLAUDE_AI_SESSION_KEY:-}
      - CLAUDE_WEB_SESSION_KEY=${CLAUDE_WEB_SESSION_KEY:-}
      - CLAUDE_WEB_COOKIE=${CLAUDE_WEB_COOKIE:-}
    volumes:
      - openclaw_config:/home/node/.openclaw
      - openclaw_workspace:/home/node/openclaw-workspace
    ports:
      - '${OPENCLAW_GATEWAY_PORT_OVERRIDE:-18789}:18789'
      - '${OPENCLAW_BRIDGE_PORT_OVERRIDE:-18790}:18790'
    command:
      - node
      - dist/index.js
      - gateway
      - --bind
      - '${OPENCLAW_GATEWAY_BIND:-lan}'
      - --port
      - '18789'
    healthcheck:
      test: [CMD, node, dist/index.js, health, --port, '18789']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    deploy:
      resources:
        limits:
          cpus: ${OPENCLAW_CPU_LIMIT:-2.0}
          memory: ${OPENCLAW_MEMORY_LIMIT:-2G}
        reservations:
          cpus: ${OPENCLAW_CPU_RESERVATION:-0.1}
          memory: ${OPENCLAW_MEMORY_RESERVATION:-1G}

  openclaw-cli:
    <<: *defaults
    restart: no
    image: ${GLOBAL_REGISTRY:-ghcr.io/}openclaw/openclaw:${OPENCLAW_VERSION:-2026.2.3}
    environment:
      - TZ=${TZ:-UTC}
      - HOME=/home/node
      - TERM=xterm-256color
      - BROWSER=echo
      - CLAUDE_AI_SESSION_KEY=${CLAUDE_AI_SESSION_KEY:-}
      - CLAUDE_WEB_SESSION_KEY=${CLAUDE_WEB_SESSION_KEY:-}
      - CLAUDE_WEB_COOKIE=${CLAUDE_WEB_COOKIE:-}
    volumes:
      - openclaw_config:/home/node/.openclaw
      - openclaw_workspace:/home/node/openclaw-workspace
    stdin_open: true
    tty: true
    entrypoint: [node, dist/index.js]
    profiles:
      - cli
    deploy:
      resources:
        limits:
          cpus: ${OPENCLAW_CLI_CPU_LIMIT:-1.0}
          memory: ${OPENCLAW_CLI_MEMORY_LIMIT:-512M}

volumes:
  openclaw_config:
  openclaw_workspace:
