services:
  frpc:
    image: apiv1/frpc-ex
    # FRPC_SERVER_HOST_ADDR: 获取主机地址的命令
    # FRPC_SERVER_HOST_ADDR_FROM_URL: 返回主机地址的GET-URL
    entrypoint: sh
    command: |
      -c '
        HOST_ADDR=${FRPC_SERVER_HOST_ADDR:-$(wget --no-check-certificate --timeout=10 --tries=10 -qO - ${FRPC_SERVER_HOST_ADDR_FROM_URL:-})}
        HOST=$${HOST_ADDR%%:*}
        PORT=$$(echo $$HOST_ADDR | sed 's/^[^:]*[:]*//g')
        PORT=$${PORT:-${FRPS_BIND_PORT}}
        cp /config.toml /tmp/config.toml
        sed -i "s/\$$SERVER_HOST/$$HOST/g" /tmp/config.toml
        sed -i "s/\$$SERVER_PORT/$$PORT/g" /tmp/config.toml
        if test -n "${DEBUG:-}"; then
          echo -------------------------
          cat /tmp/config.toml
          echo -------------------------
        fi
        frpc-ex -c /tmp/config.toml
      '
    tmpfs:
      - /tmp
    configs:
      - source: config.toml
        target: /config.toml
    restart: always
    # 为主机设置域名以访问主机端口
    extra_hosts:
      - "host.docker.internal:host-gateway"
configs:
  config.toml:
    content: |
      auth.method = "token"
      auth.token = "${FRPS_TOKEN}"

      serverAddr = "$$SERVER_HOST"
      serverPort = $$SERVER_PORT

      ${FRPC_PROXIES:-}