version: '3.8'

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

  linkedin-scheduler:
    build: .
    container_name: linkedin-scheduler
    restart: unless-stopped
    command: sh -c "python -m src.services.scheduler_runner"
    env_file: .env
    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: .
    container_name: linkedin-posts
    restart: unless-stopped
    command: sh -c "python -m uvicorn src.web.app:app --host 0.0.0.0 --port ${PORT:-8001} --workers 2"
    ports:
      - "127.0.0.1:8001:8001"
    env_file: .env
    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
