version: '3.8'

services:
  db:
    image: postgres:15-alpine
    container_name: mjb-db
    restart: always
    environment:
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=mjb
      # LINHA ADICIONADA: Instrui o Postgres a aceitar conexões de rede com senha (md5)
      - POSTGRES_HOST_AUTH_METHOD=md5
    volumes:
      - mjb-data:/var/lib/postgresql/data

  backend:
    container_name: mjb-backend
    image: victorsalles/mjb-backend
    restart: always
    platform: linux/amd64/v4
    environment:
      - HOST=0.0.0.0
      - PORT=1337
      - APP_KEYS=LmJ3rslfo+mSIuCjXkkemg==,2qpoD5bqiYVoq7jFwP5gXQ==,g7aQFBI7JVfkGo3iUdxjlA==,jvpZaskMGQqgzTnxJcsn9Q==
      - API_TOKEN_SALT=5M1nM5+ksBYqWHedZ73FYw==
      - ADMIN_JWT_SECRET=nvyURQLqm5CFgbswrBDz9Q==
      - TRANSFER_TOKEN_SALT=m3ACnbSQ30T4bY0MM/r40w==
      - DATABASE_CLIENT=postgres
      - DATABASE_HOST=db
      - DATABASE_PORT=5432
      - DATABASE_NAME=mjb
      - DATABASE_USERNAME=postgres
      - DATABASE_PASSWORD=postgres
      - DATABASE_SSL=false
      - JWT_SECRET=QQdyLwW8eyfcrdKL0Cbedw==
    ports:
      - "1337:1337"
    depends_on:
      - db
    volumes:
      - media-storage:/opt/app/public/uploads
      
  frontend:
    container_name: mjb-frontend
    image: victorsalles/mjb-frontend
    # CORREÇÃO: Mudado de 'yarn dev' para 'yarn start' para modo de produção
    command: yarn start
    restart: always
    environment:
      - API_HOST=https://api.museujardimbotanico.org.br/api
      - NEXT_PUBLIC_UPLOAD_HOST=https://api.museujardimbotanico.org.br/uploads
      - NODE_TLS_REJECT_UNAUTHORIZED=0
      - NEXT_PUBLIC_API_ROOT=https://api.museujardimbotanico.org.br
    ports:
      - "3000:3000"
    depends_on:
      - backend
    deploy:
      resources:
        limits:
          memory: 1G
          
volumes:
  mjb-data:
    name: www_mjb-data
    external: true
  media-storage:
    name: www_media-storage
    external: true

