version: '3.8'
services:
  db:
    image: postgres:15-alpine
    container_name: embed-backend-db
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: embed_db
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - embed_network
    restart: unless-stopped

  # NEW CODE - Added Redis service for Celery message broker
  redis:
    image: redis:7-alpine
    container_name: embed-backend-redis
    volumes:
      - redis_data:/data
    networks:
      - embed_network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: embed-backend-app
    command: ["sh", "-c", "./entry.sh"]
    ports:
      - "8006:8000"
    env_file:
      - .env
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
      - REDIS_HOST=redis
    depends_on:
      - db
      - redis
    volumes:
      - .:/app
      - ./logs:/app/logs
      - ./data:/app/data
    networks:
      - embed_network
    restart: unless-stopped

  # NEW CODE - Added Celery worker service for async task processing
  celery_worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: embed-backend-celery-worker
    command: celery -A app.core.celery_app worker --loglevel=info --queues=default,notifications
    env_file:
      - .env
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
      - REDIS_HOST=redis
    depends_on:
      - db
      - redis
    volumes:
      - .:/app
      - ./logs:/app/logs
    networks:
      - embed_network
    restart: unless-stopped

volumes:
  postgres_data:
    name: embed-backend-postgres-data
  # NEW CODE - Added Redis data volume
  redis_data:
    name: embed-backend-redis-data

networks:
  embed_network:
    name: embed-backend-network
    driver: bridge
