# File: frontend/docker-compose.yml
# DMS Container v0_8_0 แยก service/ lcbp3-frontend
x-restart: &restart_policy
  restart: unless-stopped

x-logging: &default_logging
  logging:
    driver: "json-file"
    options:
      max-size: "10m"
      max-file: "5"
volumes:
  frontend_node_modules:
  frontend_next:
  frontend_next_cache:
services:
  frontend:
    <<: [*restart_policy, *default_logging]
    image: dms-frontend:dev
    # pull_policy: never  # <-- FINAL FIX ADDED HERE
    container_name: dms_frontend
    stdin_open: true
    tty: true
    # user: "node"
    # user: "1000:1000"
    user: "0:0"
    # user: "${PUID:-1000}:${PGID:-1000}"
    working_dir: /app
    deploy:
      resources:
        limits:
          cpus: "2.0"
          memory: 2G
    environment:
      TZ: "Asia/Bangkok"
      NODE_ENV: "development"
      # NEXT_PUBLIC_API_BASE: "/api"
      CHOKIDAR_USEPOLLING: "1"
      CHOKIDAR_INTERVAL: "300"
      WATCHPACK_POLLING: "true"
      NEXT_TELEMETRY_DISABLED: "1"
      NEXT_PUBLIC_API_BASE: "https://lcbp3.np-dms.work"
      NEXT_PUBLIC_AUTH_MODE: "cookie"
      NEXT_PUBLIC_DEBUG_AUTH: "1"
      INTERNAL_API_BASE: "http://backend:3001"
      JWT_ACCESS_SECRET: "9a6d8705a6695ab9bae4ca1cd46c72a6379aa72404b96e2c5b59af881bb55c639dd583afdce5a885c68e188da55ce6dbc1fb4aa9cd4055ceb51507e56204e4ca"
      JWT_REFRESH_SECRET: "743e798bb10d6aba168bf68fc3cf8eff103c18bd34f1957a3906dc87987c0df139ab72498f2fe20d6c4c580f044ccba7d7bfa4393ee6035b73ba038f28d7480c"
    expose:
      - "3000"
    networks:
      lcbp3: {}
    volumes:
      - "/share/Container/dms/frontend:/app:rw"
      - "frontend_node_modules:/app/node_modules"
      - "frontend_next_cache:/app/.next/cache"
      #- "/share/Container/dms/frontend/node_modules:/app/node_modules"
      - "frontend_next:/app/.next"
      - "/share/Container/dms/logs/frontend:/app/.logs"
    healthcheck:
      test:
        [
          "CMD-SHELL",
          'wget -qO- http://127.0.0.1:3000/health | grep -q ''"ok":true''',
        ]
      interval: 15s
      timeout: 5s
      retries: 30
networks:
  lcbp3:
    external: true
