version: '3'

services:
  
  fixPermissionsPostregres:
    image: 'postgres:14'
    user: root
    command: chown -R 1001:1001 /var/lib/postgresql
    volumes:
      - '$HOME/www/izing/database/pg:/var/lib/postgresql'
  
  izing-db:
    image: 'postgres:14'
    restart: always
    container_name: "izing-db"
    env_file:
      - ./backend/.env
    volumes:
      - "$HOME/www/izing/database/pg:/var/lib/postgresql"
    ports:
      - "5432:5432"
    networks:
      - db_network
    depends_on:
      - fixPermissionsPostregres

  izing-redis:
    container_name: "izing-redis"
    image: 'redis:latest'
    restart: always
    ports:
      - "6379:6379"
    env_file:
      - ./backend/.env
    volumes:
      - '$HOME/www/izing/database/redis:/data'
    networks:
      - redis_network
  
  izing-rabbitmq:
    image: rabbitmq:3-management
    container_name: "izing-rabbitmq"
    restart: always
    env_file:
      - ./backend/.env
    extra_hosts:
      - "host.docker.internal:host-gateway"
    # healthcheck:
    #   test: [ "CMD", "nc", "-z", "localhost", "5672" ]
    #   interval: 5s
    #   timeout: 10s
    #   retries: 3
    volumes:
      - $HOME/www/izing/database/rabbitmq/data/:/var/lib/rabbitmq/
      - $HOME/www/izing/database/rabbitmq/logs/:/var/log/rabbitmq/log
    ports:
      - 5672:5672
      - 15672:15672
    networks:
      - rabbitmq_network

  izing-backend:
    container_name: "izing-backend"
    build:
      context: ./backend
    env_file:
      - ./backend/.env
    restart: always
    stdin_open: true
    tty: true
    ports:
      - 3100:3100
      - 3000:3000
    # command: /start_production
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - "./backend:/usr/src/app"
      - $HOME/www/izing/media:/usr/src/app/public
    networks:
      - rabbitmq_network
      - redis_network
      - db_network
      - nginx_network
    depends_on:
      - izing-redis
      - izing-db
      - izing-rabbitmq
  
  nginx:
    container_name: nginx-proxy
    build:
      context: .
      # args:
      #   - DOMINIO_CLIENTE=${DOMINIO_CLIENTE}
    restart: always
    stdin_open: true
    tty: true
    entrypoint: nginx -g "daemon off;"
    ports:
      - "443:443"
      - "80:80"
      - "8080:8080"
    volumes:
      - $HOME/www/izing/media:/opt/services/app/media
    depends_on:
      - izing-backend
    networks:
      - nginx_network



networks:
  db_network:
    driver: bridge
  redis_network:
    driver: bridge
  rabbitmq_network:
    driver: bridge
  nginx_network:
    driver: bridge
