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

services:
  frpc:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}snowdreamtech/frpc:${FRPC_VERSION:-0.68.1}
    ports:
      - '${FRP_ADMIN_PORT:-7400}:${FRP_ADMIN_PORT:-7400}'
    volumes:
      - ./frpc.toml:/etc/frp/frpc.toml
    environment:
      TZ: ${TZ:-UTC}
      FRP_SERVER_ADDR: ${FRP_SERVER_ADDR:-127.0.0.1}
      FRP_SERVER_PORT: ${FRP_SERVER_PORT:-7000}
      FRP_SERVER_TOKEN: ${FRP_SERVER_TOKEN:-server_token}
      FRP_APP_HOST: ${FRP_APP_HOST:-127.0.0.1}
      FRP_ADMIN_ADDR: ${FRP_ADMIN_ADDR:-0.0.0.0}
      FRP_ADMIN_PORT: ${FRP_ADMIN_PORT:-7400}
      FRP_ADMIN_USER: ${FRP_ADMIN_USER:-admin}
      FRP_ADMIN_PASSWORD: ${FRP_ADMIN_PASSWORD:-password}
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    deploy:
      resources:
        limits:
          cpus: ${FRPC_CPU_LIMIT:-0.5}
          memory: ${FRPC_MEMORY_LIMIT:-128M}
        reservations:
          cpus: ${FRPC_CPU_RESERVATION:-0.1}
          memory: ${FRPC_MEMORY_RESERVATION:-64M}
    healthcheck:
      test:
        - CMD
        - sh
        - -c
        - 'curl -f http://$${FRP_ADMIN_USER}:$${FRP_ADMIN_PASSWORD}@localhost:$${FRP_ADMIN_PORT}/api/status || exit 1'

      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
