volumes:
  certbot_volume:
  nginx_log_volume:
  mysql_data_volume:
  mysql_backup_volume:
  php_var_volume:
  rabbitmq_volume:
  redis_volume:
  php_support_volume:


x-defaults-php: &defaults-php
  image: registry.dot-dot.ru/dot-dot:${DOTDOT_TAG}
  restart: unless-stopped
  user: www-data
  volumes:
    - ./configs/php/.env.local:/application/.env.local
    - ./configs/php/zz-docker.conf:/usr/local/etc/php-fpm.d/zz-docker.conf
    - ./configs/php/pdf_result:/application/var/tmp/pdf_result
    - php_var_volume:/application/var
    - php_support_volume:/application/var/support-issue
    - ./configs/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
    - ./configs/php/firebase-fcm-dotdot-key.json:/application/config/firebase-fcm-dotdot-key.json
  depends_on:
    - db
    - rabbitmq
  extra_hosts:
    - "sentry.dot-dot.ru:192.168.100.111"
    - "staging.dot-dot.ru:192.168.100.110"
    - "staging.spottorg.ru:192.168.100.110"
    - "testesigner.dot-dot.ru:192.168.100.110"
    - "staginglms.spottorg.ru:192.168.100.110"
  networks:
    - dd

networks:
  dd:
    name: ${NETWORK}
  ingress:
    external: true

services:
  db:
    image: mariadb:10.3.25
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    ports:
      - ${MYSQL_PORT}:3306
    volumes:
      - mysql_data_volume:/var/lib/mysql
      - mysql_backup_volume:/backups
    networks:
      - dd

  backend:
    <<: *defaults-php

  php:
    command: ./bin/console app:auction:reload
    <<: *defaults-php

  statistic-export:
    <<: *defaults-php
    command: ./bin/console messenger:consume StatisticExport

  carrier-offers:
    <<: *defaults-php
    command: ./bin/console messenger:consume CarrierOffers

  order-import:
    <<: *defaults-php
    command: ./bin/console messenger:consume OrderImport

  reconciliation-act:
    <<: *defaults-php
    command: ./bin/console messenger:consume ReconciliationAct

  ws-order-state-update:
    <<: *defaults-php
    command: ./bin/console messenger:consume WSOrderStateUpdate

  user-trust:
    <<: *defaults-php
    command: sh -c 'while true; do echo run; ./bin/console messenger:consume UserTrust; sleep 10;done'

  auction:
    <<: *defaults-php
    command: sh -c 'while true; do echo run; ./bin/console app:auction:process; sleep 10;done'
   
  sync-auctions:
    <<: *defaults-php
    command: ./bin/console messenger:consume SyncAuctions

  sync-carriers:
    <<: *defaults-php
    command: ./bin/console messenger:consume SyncCarriers

  sync-change-data:
    <<: *defaults-php
    command: ./bin/console messenger:consume SyncChangeData

  relevant-carrier-export:
    <<: *defaults-php
    command: ./bin/console messenger:consume RelevantCarrierExport

  static:
    image: registry.dot-dot.ru/dot-dot-static:${DOTDOT_TAG}
    restart: unless-stopped
    networks:
      - dd


  lms:
    image: registry.dot-dot.ru/lms:${LMS_TAG}
    restart: unless-stopped
    command: npm run start
    volumes:
      - ./configs/lms/.env:/app/.env
      - ./configs/lms/entrypoint.sh:/entrypoint.sh
    env_file:
      - ./configs/lms/.env
    entrypoint: /entrypoint.sh
    networks:
      - dd

  admin:
    image: registry.dot-dot.ru/admin:${ADMIN_TAG}
    restart: unless-stopped
    command: sh -c 'php-fpm -D; nginx'
    volumes:
      - ./configs/admin/default:/etc/nginx/sites-enabled/default
      - ./configs/admin/.env:/application/.env
      - /home/ddadmin/dotdot/configs/nginx/ssl:/etc/nginx/ssl
    depends_on:
      - db
    networks:
      dd:


  nginx:
    image: nginx:1.25.3-alpine3.18
    restart: unless-stopped
    volumes:
      - ./configs/nginx/conf.d:/etc/nginx/conf.d
      - ./configs/nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./configs/nginx/www:/var/www
      - /home/ddadmin/dotdot/configs/nginx/ssl:/etc/nginx/ssl
      - ./configs/nginx/other:/etc/nginx/other
      - certbot_volume:/etc/letsencrypt
      - nginx_log_volume:/var/log/nginx
    depends_on:
      - php
      - static
    networks:
      dd:
      ingress:
        aliases:
          - ${NETWORK}-nginx

  rabbitmq:
    image: rabbitmq:3.12.1-management-alpine
    restart: unless-stopped
    hostname: ${COMPOSE_PROJECT_NAME}
    volumes:
      - rabbitmq_volume:/var/lib/rabbitmq
      - ./configs/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins
    environment:
      - RABBITMQ_DEFAULT_USER=${RABBITMQ_USERNAME}
      - RABBITMQ_DEFAULT_PASS=${RABBITMQ_PASSWORD}
      - RABBITMQ_CONFIG_FILE=/etc/rabbitmq/rabbitmq.conf
    networks:
      dd: {}

  redis:
    image: redis:7.2.4-alpine3.19
    restart: unless-stopped
    volumes:
      - redis_volume:/data
      - ./configs/redis:/usr/local/etc/redis
    environment:
      - REDIS_PORT=6379
    networks:
      dd: {}

  redis-exporter:
    image: oliver006/redis_exporter:v1.59.0
    command:
      - "--redis.addr=redis://redis:6379"
    networks:
      dd: {}

  cabinet:
    image: registry.dot-dot.ru/dot_dot_cargo_carrier:${CABINET_TAG}
    restart: unless-stopped
    command: npm run start
    volumes:
      - ./configs/cabinet/.env:/app/.env
      - ./configs/cabinet/entrypoint.sh:/entrypoint.sh
    env_file:
      - ./configs/cabinet/.env
    entrypoint: /entrypoint.sh
    networks:
      - dd

  centrifugo:
    image: centrifugo/centrifugo:v5
    volumes:
      - ./configs/centrifugo/config.json:/centrifugo/config.json
    command: centrifugo -c config.json
    ulimits:
      nofile:
        soft: 65535
        hard: 65535
    restart: unless-stopped
    networks:
      - dd

  landing:
    image: registry.dot-dot.ru/landing:${LANDING_TAG}
    command: sh -c 'nginx; php-fpm -R'
    volumes:
      - ./configs/landing/config.php:/application/backend/config.php
    user: root
    restart: unless-stopped
    networks:
      - dd
