version: "3.4"


services:

  nginx:
    image: mathwave/sprint-repo:sprint-nginx
    volumes:
      - /sprint-data/static:/var/www/html/static
    networks:
      - net
    ports:
      - "1235:80"
    deploy:
      mode: replicated
      restart_policy:
        condition: any
      placement:
        constraints: [node.role == manager]
      update_config:
        parallelism: 1
        order: start-first

  migrations:
    image: mathwave/sprint-repo:sprint
    command: ./manage.py migrate
    networks:
      - net
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
    deploy:
      mode: replicated
      restart_policy:
        condition: on-failure

  web:
    image: mathwave/sprint-repo:sprint
    networks:
      - net
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN
      VK_SERVICE_TOKEN: $VK_SERVICE_TOKEN
    command: sh -c "./manage.py collectstatic --noinput && ./manage.py runserver 0.0.0.0:8000 --noreload --insecure"
    deploy:
      mode: replicated
      restart_policy:
        condition: any
      update_config:
        parallelism: 1
        order: start-first

  polling:
    image: mathwave/sprint-repo:sprint
    networks:
      - net
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
    command: ./manage.py runserver 0.0.0.0:7998 --noreload
    deploy:
      mode: replicated
      restart_policy:
        condition: any
      update_config:
        parallelism: 1
        order: start-first

  storage:
    image: mathwave/sprint-repo:sprint
    networks:
      - net
    command: ./manage.py storage
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
    volumes:
      - /sprint-data/data:/usr/src/app/data
    deploy:
      mode: replicated
      restart_policy:
        condition: any
      placement:
        constraints: [node.role == manager]
      update_config:
        parallelism: 1
        order: start-first

  bot:
    image: mathwave/sprint-repo:sprint
    networks:
      - net
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
    command: ./manage.py bot
    deploy:
      mode: replicated
      restart_policy:
        condition: any
      update_config:
        parallelism: 1
        order: stop-first

  checker_cleaner:
    image: mathwave/sprint-repo:sprint
    networks:
      - net
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
    command: ./manage.py checker_cleaner
    deploy:
      mode: replicated
      restart_policy:
        condition: any
      update_config:
        parallelism: 1
        order: stop-first

  worker:
    image: mathwave/sprint-repo:sprint
    networks:
      - net
    command: ./manage.py receive
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
    volumes:
      - /tmp:/tmp
      - /var/run/docker.sock:/var/run/docker.sock
    deploy:
      mode: replicated
      replicas: 2
      restart_policy:
        condition: any
      update_config:
        parallelism: 1
        order: start-first

  file_generator:
    image: mathwave/sprint-repo:sprint
    networks:
      - net
    command: ./manage.py file_generator
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: any
      update_config:
        parallelism: 1
        order: start-first

  notification_manager:
    image: mathwave/sprint-repo:sprint
    networks:
      - net
    command: ./manage.py notification_manager
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: any
      update_config:
        parallelism: 1
        order: start-first

  apply-languages:
    image: mathwave/sprint-repo:sprint
    networks:
      - net
    command: ./manage.py apply_languages
    environment:
      DB_HOST: "pg.develop.sprinthub.ru"
      FS_HOST: "storage"
      RABBIT_HOST: "rabbitmq.develop.sprinthub.ru"
      REDIS_HOST: "redis.develop.sprinthub.ru"
      RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV
      REDIS_PASSWORD: $REDIS_PASSWORD_DEV
      DB_PASSWORD: $DB_PASSWORD_DEV
      DEBUG: "true"
      TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
    deploy:
      mode: replicated
      restart_policy:
        condition: on-failure

networks:
  net:
    driver: overlay
