x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  nacos:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}nacos/nacos-server:${NACOS_VERSION:-v3.1.0-slim}
    ports:
      - '${NACOS_HTTP_PORT_OVERRIDE:-8848}:8848'
      - '${NACOS_GRPC_PORT_OVERRIDE:-9848}:9848'
      - '${NACOS_GRPC_PORT2_OVERRIDE:-9849}:9849'
    volumes:
      - nacos_logs:/home/nacos/logs
    environment:
      - TZ=${TZ:-UTC}
      - MODE=${NACOS_MODE:-standalone}
      - PREFER_HOST_MODE=hostname
      - NACOS_AUTH_ENABLE=${NACOS_AUTH_ENABLE:-true}
      - NACOS_AUTH_TOKEN=${NACOS_AUTH_TOKEN:-SecretKey012345678901234567890123456789012345678901234567890123456789}
      - NACOS_AUTH_IDENTITY_KEY=${NACOS_AUTH_IDENTITY_KEY:-serverIdentity}
      - NACOS_AUTH_IDENTITY_VALUE=${NACOS_AUTH_IDENTITY_VALUE:-security}
      - SPRING_DATASOURCE_PLATFORM=${SPRING_DATASOURCE_PLATFORM:-}
      - JVM_XMS=${JVM_XMS:-512m}
      - JVM_XMX=${JVM_XMX:-512m}
      - JVM_XMN=${JVM_XMN:-256m}
    deploy:
      resources:
        limits:
          cpus: ${NACOS_CPU_LIMIT:-1.0}
          memory: ${NACOS_MEMORY_LIMIT:-1G}
        reservations:
          cpus: ${NACOS_CPU_RESERVATION:-0.1}
          memory: ${NACOS_MEMORY_RESERVATION:-512M}
    healthcheck:
      test: [CMD, wget, --no-verbose, --tries=1, --spider, 'http://localhost:8848/nacos/']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

volumes:
  nacos_logs:
