| services:
  redis-master:
    image: 'bitnami/redis:latest'
    ports:
      - "${REDIS_PORT}:${REDIS_PORT2}"
    networks:
      - bames_network
    volumes:
      - './docker/redis/data:/data'
      - './docker/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro'
    restart: always
    command: redis-server /usr/local/etc/redis/redis.conf
  postgres:
    image: 'postgres:11.1-alpine'
    container_name: bames_postgres
    restart: unless-stopped
    working_dir: /application
    volumes:
      - './:/application'
      - './docker/postgres/pg-config:/etc/postgresql'
      - './docker/postgres/init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql'
    environment:
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_USER=${DB_USERNAME}
      - POSTGRES_DB=${DB_DATABASE}
    ports:
      - 8050:5432
    networks:
      - bames_network
  api-autenticacao:
    image: 'nginx:alpine'
    container_name: bames_api_auth_nginx
    working_dir: /application
    depends_on:
      - postgres
    volumes:
      - './:/application'
      - './docker/nginx/api_auth_nginx.conf:/etc/nginx/conf.d/default.conf'
    ports:
      - '8052:80'
    networks:
      - bames_network
  api-main:
    image: 'nginx:alpine'
    container_name: bames_api_main_nginx
    working_dir: /application
    depends_on:
      - postgres
    volumes:
      - './:/application'
      - './docker/nginx/api_main_nginx.conf:/etc/nginx/conf.d/default.conf'
    ports:
      - '8053:80'
    networks:
      - bames_network
  api-webhook:
    image: 'nginx:alpine'
    container_name: bames_api_webhook_nginx
    working_dir: /application
    depends_on:
      - postgres
    volumes:
      - './:/application'
      - './docker/nginx/api_webhook_nginx.conf:/etc/nginx/conf.d/default.conf'
    ports:
      - '8054:80'
    networks:
      - bames_network
  laucher-queue:
    build: ./docker/php-fpm # Use o Dockerfile para construir a imagem
    command: php src/Infraestrutura/Adaptadores/Mensageria/InicializadorMensageria.php # Comando para iniciar o worker
    volumes:
      - './:/application' # Mapeie o código-fonte para o contêiner
    depends_on:
      - rabbitmq-master # Certifique-se de que o RabbitMQ esteja disponível antes de iniciar o worker
    deploy:
      replicas: 1 # Número inicial de réplicas
    networks:
      - bames_network
  worker-email:
    build: ./docker/php-fpm # Use o Dockerfile para construir a imagem
    command: php src/Infraestrutura/Workers/Email/WorkerEmail.php # Comando para iniciar o worker
    volumes:
      - './:/application' # Mapeie o código-fonte para o contêiner
    depends_on:
      - laucher-queue
      - rabbitmq-master # Certifique-se de que o RabbitMQ esteja disponível antes de iniciar o worker
    deploy:
      replicas: 2 # Número inicial de réplicas
    networks:
      - bames_network
  worker-novo-evento:
    build: ./docker/php-fpm # Use o Dockerfile para construir a imagem
    command: php src/Infraestrutura/Workers/Agenda/NovoEvento/Worker.php # Comando para iniciar o worker
    volumes:
      - './:/application' # Mapeie o código-fonte para o contêiner
    depends_on:
      - laucher-queue
      - rabbitmq-master # Certifique-se de que o RabbitMQ esteja disponível antes de iniciar o worker
    deploy:
      replicas: 2 # Número inicial de réplicas
    networks:
      - bames_network
  worker-empresa-recem-cadastrada:
    build: ./docker/php-fpm # Use o Dockerfile para construir a imagem
    command: php src/Infraestrutura/Workers/EmpresaRecemCadastrada/Worker.php # Comando para iniciar o worker
    volumes:
      - './:/application' # Mapeie o código-fonte para o contêiner
    depends_on:
      - laucher-queue
      - rabbitmq-master # Certifique-se de que o RabbitMQ esteja disponível antes de iniciar o worker
    deploy:
      replicas: 2 # Número inicial de réplicas
    networks:
      - bames_network
  php-fpm:
    build: ./docker/php-fpm
    container_name: bames_php
    working_dir: /application
    depends_on:
      - postgres
    volumes:
      - './:/application'
      - './docker/php-fpm/php-ini-overrides.ini:/etc/php/8.3/fpm/conf.d/99-overrides.ini'
    networks:
      - bames_network
    environment:
      - DB_HOST=${DB_CONNECTION}
      - DB_PORT=${DB_PORT}
      - DB_DATABASE=${DB_DATABASE}
      - DB_USER=${DB_USERNAME}
      - DB_PASSWORD=${DB_PASSWORD}
  rabbitmq-master:
    image: rabbitmq:3.8-management-alpine
    hostname: rabbitmq-master
    restart: unless-stopped
    ports:
      - "1${EVENT_BUS_PORT}:1${EVENT_BUS_PORT}"
      - "${EVENT_BUS_PORT}:${EVENT_BUS_PORT}"
      - "15692:15692"
    volumes:
      - './docker/rabbitmq:/var/lib/rabbitmq'
    networks:
      - bames_network
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.role == manager
  rabbitmq-slave:
    image: rabbitmq:3.8-management-alpine
    hostname: rabbitmq-slave
    restart: unless-stopped
    volumes:
      - './docker/rabbitmq:/var/lib/rabbitmq'
    networks:
      - bames_network
    healthcheck:
      test: [ "CMD", "curl", "-f", "localhost", "${EVENT_BUS_PORT}" ]
      interval: 5s
      timeout: 15s
      retries: 1
    deploy:
      replicas: 2
      placement:
        constraints:
          - node.role == worker
networks:
  bames_network:
volumes:
  pg-data:
  pg-config:
    driver: local
    driver_opts:
      type: "none"
      o: "bind"
      device: "$PWD/./docker/postgres"
 |