services:
  db:
    build:
      context: .
      dockerfile: docker/db/Dockerfile
    container_name: mariadb
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    ports:
      - "${DB_PORT}:3306"
    volumes:
      - ./db_storage/mysql:/var/lib/mysql
    env_file:
      - .env

  redis:
    image: redis:7.2
    container_name: redis
    restart: unless-stopped
    ports:
      - "${REDIS_PORT}:6379"
    env_file:
      - .env

  django:
    build:
      context: .
      dockerfile: docker/main/Dockerfile
    container_name: django
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/app
    ports:
      - "8000:8000"
    env_file:
      - .env
    depends_on:
      - db
      - redis

  bot:
    build:
      context: .
      dockerfile: docker/bot/Dockerfile
    container_name: bot
    command: python manage.py runbot
    volumes:
      - .:/app
    env_file:
      - .env
    depends_on:
      - db
      - redis

  celery_worker:
    build:
      context: .
      dockerfile: docker/celery/Dockerfile
    container_name: celery_worker
    command: celery -A tg_autopost worker -l info
    volumes:
      - .:/app
    env_file:
      - .env
    depends_on:
      - db
      - redis

  celery_beat:
    build:
      context: .
      dockerfile: docker/celery/Dockerfile
    container_name: celery_beat
    command: celery -A tg_autopost beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
    volumes:
      - .:/app
    env_file:
      - .env
    depends_on:
      - db
      - redis
