Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ 支持Huggingface Space部署方式使用Cloudflare Tunnels自定义访问域名 #707

Merged
merged 8 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion docs/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| [Railway 部署](#railway-部署) | ★★☆☆☆ | 有免费额度但不足以支持一个月连续运行,部署简单,适合全球访问。 |
| [Zeabur 部署](#zeabur-部署) | ★☆☆☆☆ | 需要绑定支付宝或信用卡,部署简单,适合中国大陆访问,免费计划环境随时可能会被删除。 |
| [Netlify 部署](#netlify-部署) | ★★★★☆ | 有充足的免费额度,中国大陆访问速度不错。 |
| [Hugging Face 部署](#hugging-face-部署) | ★★★★☆ | 免费,中国大陆访问速度不错。 |
| [Hugging Face 部署](#hugging-face-部署) | ★★★★☆ | 免费,中国大陆访问速度不错。允许通过 Cloudflare Tunnels 自定义域名。 |
| [AWS Lambda 部署](#aws-lambda-部署) | ★★★☆☆ | 全球最大的云平台,适合已经使用 AWS 全家桶的用户。 |
| [Cloudflare workers 部署](#cloudflare-workers-部署) | ★★☆☆☆ | 部署需使用命令行,冷启动时间较短,功能有部分限制。 |
| [私有部署](#私有部署) | ★★☆☆☆ | 适用于有服务器的用户,需要自行申请 HTTPS 证书。 |
Expand Down Expand Up @@ -208,6 +208,27 @@ EXPOSE 7860

![](./static/hugging-6.png)

### 如果你需要自定义域名

> ps:除了 `CF_ZERO_TRUST_TOKEN` 这个环境变量以外,其他环境变量的配置方式与上一步相同

1. 申请 Cloudflare Zero Trust,关于申请方式请自行查找

![](./static/hugging-7.png)

2. 添加一条隧道,连接方式选择 Cloudflared,名称任意

![](./static/hugging-8.png)

3.添加一个 Public Hostname,回源选择 HTTP,端口选择8080
4.Clone Twikoo 仓库,找到src\server\hf-space
5.去 Huggingface 创建一个 Space,然后Clone下来,将 hf-space 文件夹内的所有内容复制进去
6.在 Huggingface Space 的设置中添加一个环境变量,变量名 `CF_ZERO_TRUST_TOKEN` ,值是 Tunnels 给的令牌(删掉 `cloudflared.exe service install`,只保留令牌部分)

![](./static/hugging-9.png)

7.Push 到 Huggingface Space 仓库

## AWS Lambda 部署

1. 注册 AWS 账号并配置 Terraform CLI。
Expand Down
Binary file added docs/static/hugging-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/hugging-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/hugging-9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/server/hf-space/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:lts-slim AS build

RUN useradd -m app

USER root

RUN npm i -g tkserver

ADD https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 /usr/local/bin/cloudflared
RUN chmod +x /usr/local/bin/cloudflared

COPY ./src/start.sh /usr/bin/start.sh

USER app
WORKDIR /home/app/twikoo

CMD ["sh", "/usr/bin/start.sh"]
9 changes: 9 additions & 0 deletions src/server/hf-space/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Twikoo Huggingface Space
emoji: 📚
colorFrom: yellow
colorTo: indigo
sdk: docker
pinned: false
app_port: 8080
---
4 changes: 4 additions & 0 deletions src/server/hf-space/src/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

nohup /usr/local/bin/cloudflared tunnel --no-autoupdate run --token $CF_ZERO_TRUST_TOKEN >> /dev/stdout 2>&1 &
tkserver
Loading