version: '3.8'

services:
  postgres:
    image: postgres:16-alpine
    container_name: postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: flower
    ports:
      - "5432:5432"
    volumes:
      - db_data:/var/lib/postgresql/data
    restart: unless-stopped

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: pgadmin
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    ports:
      - "5050:80"
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    depends_on:
      - postgres
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    container_name: redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    restart: unless-stopped

  rabbitmq:
    image: rabbitmq:3-management-alpine
    container_name: rabbitmq
    environment:
      RABBITMQ_DEFAULT_USER: guest
      RABBITMQ_DEFAULT_PASS: guest
    ports:
      - "5672:5672"
      - "15672:15672"
    volumes:
      - rabbitmq_data:/var/lib/rabbitmq
    restart: unless-stopped

  

  web:
    build:
      context: .
      target: base
    container_name: flower_web
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
    volumes:
      - .:/app
    environment:
      DJANGO_SETTINGS_MODULE: flower.settings
      PYTHONPATH: /app
      DEBUG: "1"
      ALLOWED_HOSTS: "localhost,127.0.0.1,0.0.0.0,8.148.215.233,yuwenerp.yuwen.cloud"
      DB_HOST: postgres
      DB_PORT: "5432"
      DB_NAME: flower
      DB_USER: postgres
      DB_PASSWORD: postgres
    depends_on:
      - postgres
      - redis
      - rabbitmq
    restart: unless-stopped

  celery_worker:
    build:
      context: .
      target: base
    container_name: celery_worker
    command:
      - celery
      - -A
      - flower
      - worker
      - -l
      - info
      - --concurrency=2
      - --pool=solo
    volumes:
      - .:/app
    depends_on:
      - postgres
      - redis
      - rabbitmq
    environment:
      CELERY_BROKER_URL: amqp://guest:guest@rabbitmq:5672//
      CELERY_RESULT_BACKEND: redis://redis:6379/0
      PYTHONPATH: /app
      DB_HOST: postgres
      DB_PORT: "5432"
      DB_NAME: flower
      DB_USER: postgres
      DB_PASSWORD: postgres
    restart: unless-stopped

  celery_beat:
    build:
      context: .
      target: base
    container_name: celery_beat
    command:
      - celery
      - -A
      - flower
      - beat
      - -l
      - info
    volumes:
      - .:/app
    depends_on:
      - postgres
      - redis
      - rabbitmq
    environment:
      DJANGO_SETTINGS_MODULE: flower.settings
      PYTHONPATH: /app
      DB_HOST: postgres
      DB_PORT: "5432"
      DB_NAME: flower
      DB_USER: postgres
      DB_PASSWORD: postgres
      CELERY_BROKER_URL: amqp://guest:guest@rabbitmq:5672//
      CELERY_RESULT_BACKEND: redis://redis:6379/0
    restart: unless-stopped

volumes:
  db_data:
  redis_data:
  pgadmin_data:
  rabbitmq_data:
