# Ghost Node — Docker Compose
# One-command startup: docker compose up -d
#
# Services:
#   ghostnode  — FastAPI + Playwright scraper (port 7000)
#   postgres   — PostgreSQL 16 database
#   redis      — Redis 7 cache + pub/sub
#
# First run: docker compose up --build
# Stop:      docker compose down
# Logs:      docker compose logs -f ghostnode
# Shell:     docker compose exec ghostnode bash

services:

  ghostnode:
    build: .
    container_name: ghostnode
    restart: unless-stopped
    ports:
      - "7000:7000"
    environment:
      # PostgreSQL — replaces SQLite when set
      DATABASE_URL: postgresql://ghostnode:ghostnode@postgres:5432/ghostnode
      # Redis — enables cache + pub/sub
      REDIS_URL: redis://redis:6379/0
      # Optional: pass Telegram token here instead of via Settings UI
      # TELEGRAM_TOKEN: ""
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    volumes:
      # Persist browser session cookies between restarts
      - ghostnode_sessions:/app/sessions
    shm_size: 512mb   # Chromium needs shared memory

  postgres:
    image: postgres:16-alpine
    container_name: ghostnode_postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: ghostnode
      POSTGRES_USER: ghostnode
      POSTGRES_PASSWORD: ghostnode
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ghostnode -d ghostnode"]
      interval: 5s
      timeout: 5s
      retries: 10
    ports:
      - "5432:5432"   # expose for local tools (pgAdmin, DBeaver)

  redis:
    image: redis:7-alpine
    container_name: ghostnode_redis
    restart: unless-stopped
    command: redis-server --appendonly yes --maxmemory 128mb --maxmemory-policy allkeys-lru
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 10
    ports:
      - "6379:6379"   # expose for local Redis clients

volumes:
  postgres_data:
  redis_data:
  ghostnode_sessions:
