version: '3.8'
name: nexcut-ai-python
services:
  app:
    build: .
    container_name: nexcut-ai-app
    restart: always
    ports:
      - "8004:8004"
    env_file:
      - .env
    volumes:
      - ./static:/app/static
      - .:/app
    depends_on:
      - db
      - redis
    networks:
      - nexcut-network

  tcp-server:
    build: .
    container_name: nexcut-tcp-server
    restart: always
    ports:
      - "18883:18883"
    volumes:
      - ./static:/app/static
      - .:/app
    command: python scripts/tcp_server.py
    env_file:
      - .env
    depends_on:
      - db
    networks:
      - nexcut-network
    logging:
     driver: "json-file"
     options:
       max-size: "10m"   # limit each log file to 10MB
       max-file: "3"     # keep 3 rotated files
 

  celery-worker:
    build: .
    container_name: nexcut-celery-worker
    restart: always
    command: celery -A app.background.celery_app worker --loglevel=info --concurrency=2 --pool=solo
    volumes:
      - ./static:/app/static
      - .:/app
    env_file:
      - .env
    depends_on:
      - db
      - redis
    networks:
      - nexcut-network

  # Celery Beat - schedules periodic tasks (runs every 10 seconds)
  celery-beat:
    build: .
    container_name: nexcut-celery-beat
    restart: always
    command: celery -A app.background.celery_app beat --loglevel=info --schedule=/app/celerybeat-schedule.db
    volumes:
      - ./static:/app/static
      - .:/app
    env_file:
      - .env
    depends_on:
      - db
      - redis
      - celery-worker
    networks:
      - nexcut-network

  db:
    image: postgres:16-alpine
    container_name: nexcut-ai-db
    restart: always
    env_file:
      - .env
    volumes:
      - postgres_data:/var/lib/postgresql/data/pgdata
    networks:
      - nexcut-network

  # redis:
  #   image: redis:7-alpine
  #   container_name: nexcut-ai-redis
  #   restart: always
  #   command: redis-server --appendonly yes
  #   volumes:
  #     - redis_data:/data
  #   networks:
  #     - nexcut-network
  redis:
    image: redis:7
    container_name: nexcut-ai-redis
    restart: always
    command: redis-server
    volumes:
      - redis_data:/data
    networks:
      - nexcut-network
      
volumes:
  postgres_data:
    name: nexcut_postgres_data
  redis_data:
    name: nexcut_redis_data

networks:
  nexcut-network:
    name: nexcut-network
    driver: bridge