version: '3.8'

# Coolify-Variante von docker-compose.simple.yml
#
# Unterschiede zum lokalen File:
#   1. Kein "env_file: .env" — Coolify injiziert alle Env-Vars über sein UI
#   2. Kein "container_name" — Coolify verwaltet die Container-Namen selbst
#   3. Port ohne 127.0.0.1-Bindung — Coolify's Traefik-Proxy übernimmt das Routing
#   4. Named volume für Logs statt Host-Pfad
#
# Coolify-Einrichtung:
#   - Resource Type: Docker Compose
#   - Compose File: docker-compose.coolify.yml
#   - Main Service: linkedin-posts
#   - Port: 8001
#   - Alle Env-Vars (API Keys, Supabase etc.) im Coolify UI setzen

services:
  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: redis-server --maxmemory 128mb --maxmemory-policy allkeys-lru --save ""
    labels:
      - traefik.enable=false
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3

  linkedin-scheduler:
    build: .
    restart: unless-stopped
    command: python -m src.services.scheduler_runner
    labels:
      - traefik.enable=false
    environment:
      - PYTHONPATH=/app
      - SCHEDULER_ENABLED=true
      - REDIS_URL=redis://redis:6379/0
    volumes:
      - logs:/app/logs
    depends_on:
      redis:
        condition: service_healthy

  linkedin-posts:
    build: .
    restart: unless-stopped
    command: python -m uvicorn src.web.app:app --host 0.0.0.0 --port 8001 --workers 2
    ports:
      - "8001:8001"
    environment:
      - PYTHONPATH=/app
      - PORT=8001
      - SCHEDULER_ENABLED=false
      - REDIS_URL=redis://redis:6379/0
    volumes:
      - logs:/app/logs
    depends_on:
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "python", "-c", "import httpx; httpx.get('http://localhost:8001/login', timeout=5)"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 15s

volumes:
  logs:
