name: sebn-taskbar-manager-dev

services:
  backend: &backend
    build:
      context: ./
      dockerfile: ./Dockerfile.development
      args:
        - HTTP_PROXY
        - HTTPS_PROXY
    command: >
      sh -c "echo 'Backend sleeping for 5 sec' && sleep '5s' && echo 'Backend continue...'&&
            true &&
            export SERVICE=backend &&
            python manage.py initadmin &&
            python manage.py inituser &&
            echo 'Generating project_visualization.png...' &&
            python manage.py graph_models &&
            echo 'Compiling locale message files...' &&
            django-admin compilemessages -i .venv &&
            python manage.py runserver 0.0.0.0:8000"
    restart: always
    environment:
      - ADMIN
      - CELERY_BROKER
      - CHANNELS_BROKER
      - DATA_ACQUISITION_URL
      - EMAIL_HOST
      - EMAIL_PORT
      - HTTP_PROXY
      - HTTPS_PROXY
      - LANG
      - LDAP_ADMINS
      - LDAP_BASE
      - LDAP_DOMAIN
      - LDAP_USERNAME
      - LDAP_PASSWORD
      - LDAP_HOST
      - LDAP_PORT
      - MYSQL_DATABASE
      - MYSQL_HOST
      - MYSQL_PASSWORD
      - MYSQL_PORT
      - MYSQL_USER
      - SECRET_KEY
      - SERVER_EMAIL
      - TELEGRAM_BOT_TOKEN
      - TZ
    image: sebn-taskbar-manager/backend:development
    ports:
      - "8000:8000"
      - "8001:8001"
    tty: true
    volumes:
      - ./backend:/sebn-taskbar-manager/backend
      - type: bind
        source: ./celery/celery.sh
        target: /sebn-taskbar-manager/celery.sh
    depends_on:
      - db
      - redis
      - broker

  task-queue:
    <<: *backend
    command: >
      sh -c "celery -A config beat -l info --detach & 
             python -m debugpy --listen 0.0.0.0:8002 -m celery -A config worker -l info --autoscale=8,2"
    ports:
      - "8002:8002"

  telegram-bot:
    <<: *backend
    command: >
      sh -c "export SERVICE=telegram-bot &&
            python manage.py start_polling"
    ports:
      - "8003:8001"

  broker:
    image: rabbitmq:3
    environment:
      - RABBITMQ_DEFAULT_USER
      - RABBITMQ_DEFAULT_PASS
    ports:
      - "5673:5672"

  redis:
    image: redis
    build:
      context: ./
      dockerfile: ./Dockerfile.redis
    ports:
      - "6380:6379"

  db:
    image: mysql:latest
    cap_add:
      - SYS_NICE
    ports:
      - "3307:3306"
    environment:
      - MYSQL_ROOT_PASSWORD
      - MYSQL_DATABASE
      - MYSQL_USER
      - MYSQL_PASSWORD
      - MYSQL_HOST
      - MYSQL_PORT
      - MYSQL_ROOT_HOST=%
    command: >
      --authentication_policy=mysql_native_password
      --federated
      --log-timestamps=SYSTEM
    volumes:
      - db_data:/var/lib/mysql
    restart: always

volumes:
  db_data:
  backend:

version: "3.8"
