services:
  nginx:
    image: nginx:alpine
    restart: always
    volumes:
      - "./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro"
    labels:
      - "traefik.enable=true"
      # Roteador de Produção (clube67.com e newwhats.clube67.com)
      - "traefik.http.routers.clube67-prod.rule=Host(`clube67.com`) || Host(`www.clube67.com`) || Host(`newwhats.clube67.com`)"
      - "traefik.http.routers.clube67-prod.entrypoints=websecure"
      - "traefik.http.routers.clube67-prod.tls.certresolver=le"
      - "traefik.http.services.clube67-prod.loadbalancer.server.port=80"
      - "traefik.docker.network=web"
    networks:
      - soc
      - web
    depends_on:
      - newwhats-backend
      - newwhats-frontend

  newwhats-backend:
    image: node:20
    container_name: newwhats-backend-prod
    restart: always
    # rootless docker: container UID 0 já é mapeado para o usuário deploy do host
    working_dir: /app
    env_file:
      - "./newwhats.local/backend/.env"
    environment:
      - BAILEYS_ENGINE=infinite
      - PORT=8008
      - NODE_ENV=production
      - DATABASE_URL=postgresql://newwhats:clube67_newwhats_pass_9903@10.99.0.3:5432/newwhats?schema=public
      - DRAGONFLY_URL=redis://:clube67_dragonfly_pass_9903@10.99.0.3:6379
      - NATS_URL=nats://10.99.0.3:4222
      - TEMPORAL_ADDRESS=10.99.0.3:7233
      - BAILEYS_SESSIONS_PATH=/app/sessions
    volumes:
      - "/home/deploy/newwhats-sessions:/app/sessions"
      - "/home/deploy/newwhats-media:/app/media"
      - "./newwhats.local/plugins:/app/plugins"
      # Montar diretórios e arquivos pré-compilados pelo builder (VPS 4)
      - "./newwhats.local/backend/dist:/app/dist"
      - "./newwhats.local/backend/package.json:/app/package.json"
      - "./newwhats.local/backend/node_modules:/app/node_modules"
      - "./newwhats.local/backend/prisma:/app/prisma"
    command: node dist/server.js
    security_opt:
      - no-new-privileges:true
    networks:
      - soc
      - web

  newwhats-frontend:
    image: node:20-alpine
    container_name: newwhats-frontend-prod
    restart: always
    # rootless docker: container UID 0 já é mapeado para o usuário deploy do host
    working_dir: /app
    env_file:
      - "./newwhats.local/frontend/.env.production.local"
    environment:
      - PORT=3003
      - NODE_ENV=production
      - NEXT_PUBLIC_API_URL=https://clube67.com/api
    volumes:
      # Montar diretórios e arquivos pré-compilados pelo builder (VPS 4)
      - "./newwhats.local/frontend/.next:/app/.next"
      - "./newwhats.local/frontend/public:/app/public"
      - "./newwhats.local/frontend/next.config.mjs:/app/next.config.mjs"
      - "./newwhats.local/frontend/package.json:/app/package.json"
      - "./newwhats.local/frontend/node_modules:/app/node_modules"
    command: npx next start -p 3003
    security_opt:
      - no-new-privileges:true
    networks:
      - soc
      - web

networks:
  soc:
    external: true
  web:
    external: true
