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

services:
  frps:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}snowdreamtech/frps:${FRPS_VERSION:-0.65.0}
    volumes:
      - ./frps.toml:/etc/frp/frps.toml
    ports:
      - ${FRP_PORT_OVERRIDE_SERVER:-7000}:${FRP_SERVER_PORT:-7000}/tcp
      - ${FRP_PORT_OVERRIDE_SERVER:-7000}:${FRP_SERVER_PORT:-7000}/udp
      - ${FRP_PORT_OVERRIDE_ADMIN:-7500}:${FRP_ADMIN_PORT:-7500}
    environment:
      TZ: ${TZ:-UTC}
      FRP_AUTH_METHOD: ${FRP_AUTH_METHOD:-token}
      FRP_SERVER_TOKEN: ${FRP_SERVER_TOKEN:-server_token}
      FRP_SERVER_PORT: ${FRP_SERVER_PORT:-7000}
      FRP_ADMIN_ADDR: ${FRP_ADMIN_ADDR:-0.0.0.0}
      FRP_ADMIN_PORT: ${FRP_ADMIN_PORT:-7500}
      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: ${FRPS_CPU_LIMIT:-0.5}
          memory: ${FRPS_MEMORY_LIMIT:-128M}
        reservations:
          cpus: ${FRPS_CPU_RESERVATION:-0.1}
          memory: ${FRPS_MEMORY_RESERVATION:-64M}
    healthcheck:
      test:
        - CMD
        - sh
        - -c
        - 'curl -f http://$${FRP_ADMIN_USER}:$${FRP_ADMIN_PASSWORD}@localhost:$${FRP_ADMIN_PORT}/api/serverinfo || exit 1'

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