services:
  db:
    image: mariadb:11.6
    restart: unless-stopped
    env_file:
      - .env
    environment:
      - MYSQL_ROOT_PASSWORD=${DJANGO_DB_ROOT_PASSWORD:-rootpassword}
      - MYSQL_DATABASE=${DJANGO_DB_NAME}
      - MYSQL_USER=${DJANGO_DB_USER}
      - MYSQL_PASSWORD=${DJANGO_DB_PASSWORD}
    ports:
      - "${DJANGO_DB_PORT}:3306"
    volumes:
      - ./db_data:/var/lib/mysql
    networks:
      default:

  bot:
    image: lottery_py
    build: .
    restart: unless-stopped
    container_name: bot
    entrypoint: ["./wait-for-db.sh"]
    command: ["python3", "manage.py", "runbot"]
    depends_on:
      - db
    env_file:
      - .env
    volumes:
      - .:/app
      - ./var:/app/var
    networks:
      default:
  celery:
    build:
      context: .
      dockerfile: docker/celery.Dockerfile
    container_name: celery_worker
    volumes:
      - .:/app
      - /var/run/docker.sock:/var/run/docker.sock 
    depends_on:
      - db
      - bot
      - redis
    environment:
      - DJANGO_SETTINGS_MODULE=lottery.settings
    networks:
      - default
  redis:
    image: redis:7
    container_name: redis
    restart: unless-stopped
  web:
    image: lottery_py
    build: .
    restart: unless-stopped
    entrypoint: ["./wait-for-db.sh"]
    command: ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
    ports:
      - "${DOCKER_HTTP_BIND:-8000}:8000"
    depends_on:
      - db
      - redis  
    env_file:
      - .env
    environment:
      - DJANGO_SETTINGS_MODULE=lottery.settings
      - CELERY_BROKER_URL=redis://redis:6379/0 
    volumes:
      - .:/app
    networks:
      default:


  flower:
    build:
      context: .
      dockerfile: docker/flower.Dockerfile
    container_name: flower
    restart: unless-stopped
    working_dir: /app
    volumes:
      - .:/app
    ports:
      - "5555:5555"
    command: ["python", "-m", "celery", "-A", "lottery", "-b", "redis://redis:6379/0", "flower", "--port=5555", "--basic_auth=admin:secret"]
    depends_on:
      - redis
      - celery
    networks:
      - default

volumes:
  db_data:

networks:
  default:
    driver: bridge
