version: '3.8'

services:
  # Frontend (Astro) - Static site served with nginx
  frontend:
    build:
      context: ./apps/frontend
      dockerfile: Dockerfile.frontend
    image: enchun-frontend:latest
    container_name: enchun-frontend
    ports:
      - "4321:4321"
    networks:
      - enchun-network
    environment:
      - NODE_ENV=production

  # Backend (Payload CMS)
  backend:
    build:
      context: ./apps/backend
      dockerfile: Dockerfile.backend
    image: enchun-backend:latest
    container_name: enchun-backend
    ports:
      - "3000:3000"
    environment:
      # Database
      - DATABASE_URI=${DATABASE_URI}
      # Payload
      - PAYLOAD_CMS_URL=http://localhost:3000
      - PAYLOAD_SECRET=${PAYLOAD_SECRET}
      - NEXT_PUBLIC_SERVER_URL=${NEXT_PUBLIC_SERVER_URL}
      # Preview
      - PREVIEW_SECRET=${PREVIEW_SECRET}
      # Resend
      - RESEND_API_KEY=${RESEND_API_KEY}
      - RESEND_FROM_EMAIL=${RESEND_FROM_EMAIL}
      # R2
      - R2_ACCESS_KEY_ID=${R2_ACCESS_KEY_ID}
      - R2_ACCOUNT_ID=${R2_ACCOUNT_ID}
      - R2_BUCKET=${R2_BUCKET}
      - R2_SECRET_ACCESS_KEY=${R2_SECRET_ACCESS_KEY}
      # Velcer
      - VERCEL_PROJECT_PRODUCTION_URL=${VERCEL_PROJECT_PRODUCTION_URL}
      # Node options
      - NODE_OPTIONS=--no-deprecation
    networks:
      - enchun-network
    depends_on:
      - frontend

  # Optional: MongoDB (if you need a containerized database)
  # mongodb:
  #   image: mongo:7
  #   container_name: enchun-mongodb
  #   ports:
  #     - "27017:27017"
  #   volumes:
  #     - mongodb_data:/data/db
  #   networks:
  #     - enchun-network

networks:
  enchun-network:
    driver: bridge
