LisonEvf commited on
Commit
f3410f9
·
1 Parent(s): d384f76
Files changed (3) hide show
  1. Dockerfile +13 -1
  2. scripts/deploy-hf-space.ps1 +35 -24
  3. sub2api-hf-rootfs.tar +3 -0
Dockerfile CHANGED
@@ -1,4 +1,14 @@
1
- FROM weishaw/sub2api:latest
 
 
 
 
 
 
 
 
 
 
2
 
3
  USER root
4
 
@@ -17,6 +27,8 @@ ENV DATA_DIR=/tmp/gateway-data \
17
  GIN_MODE=release \
18
  AUTO_SETUP=true \
19
  DATABASE_SSLMODE=require \
 
 
20
  TZ=Asia/Shanghai
21
 
22
  COPY start-space.sh /app/start-space.sh
 
1
+ # =============================================================================
2
+ # Sub2API Hugging Face Space Dockerfile
3
+ # =============================================================================
4
+ # This Space deploys from the exported root filesystem tar generated by the
5
+ # EvfWorkSpace/sub2api project, then layers the Space-specific startup wrapper
6
+ # on top. Keep sub2api-hf-rootfs.tar in this repository root.
7
+ # =============================================================================
8
+
9
+ FROM scratch
10
+
11
+ ADD sub2api-hf-rootfs.tar /
12
 
13
  USER root
14
 
 
27
  GIN_MODE=release \
28
  AUTO_SETUP=true \
29
  DATABASE_SSLMODE=require \
30
+ QUNYOU_SKILL_ROOT=/app/tools/qunyou_skill \
31
+ QUNYOU_PYTHON=python3 \
32
  TZ=Asia/Shanghai
33
 
34
  COPY start-space.sh /app/start-space.sh
scripts/deploy-hf-space.ps1 CHANGED
@@ -7,7 +7,7 @@ param(
7
  $ErrorActionPreference = "Stop"
8
 
9
  if (-not $env:HF_TOKEN) {
10
- throw "请先设置环境变量 HF_TOKEN。示例:`$env:HF_TOKEN = 'hf_xxx'"
11
  }
12
 
13
  $root = Resolve-Path (Join-Path $PSScriptRoot "..")
@@ -15,29 +15,28 @@ Set-Location $root
15
 
16
  $requiredFiles = @(
17
  "Dockerfile",
 
18
  "start-space.sh",
19
  "README.md",
20
  "PUBLIC_USAGE.md",
21
  "ADMIN_SETUP.md",
22
  ".env.example",
23
  ".gitattributes",
24
- ".gitignore"
 
 
 
 
25
  )
26
 
27
  foreach ($file in $requiredFiles) {
28
  if (-not (Test-Path -LiteralPath (Join-Path $root $file))) {
29
- throw "缺少部署文件:$file"
30
  }
31
  }
32
 
33
- $headers = @{
34
- Authorization = "Bearer $env:HF_TOKEN"
35
- }
36
-
37
- $whoami = Invoke-RestMethod `
38
- -Uri "https://huggingface.co/api/whoami-v2" `
39
- -Headers $headers `
40
- -Method GET
41
 
42
  if (-not $Owner) {
43
  $Owner = $whoami.name
@@ -55,29 +54,41 @@ if ($Owner -ne $whoami.name) {
55
  $createBody.organization = $Owner
56
  }
57
 
58
- $json = $createBody | ConvertTo-Json -Depth 5
59
-
60
  try {
61
  Invoke-RestMethod `
62
  -Uri "https://huggingface.co/api/repos/create" `
63
  -Headers ($headers + @{ "Content-Type" = "application/json" }) `
64
  -Method POST `
65
- -Body $json | Out-Null
66
- Write-Host "已创建 Hugging Face Space$repoId"
67
  } catch {
68
  $statusCode = $null
69
  if ($_.Exception.Response) {
70
  $statusCode = [int] $_.Exception.Response.StatusCode
71
  }
72
-
73
  if ($statusCode -eq 409) {
74
- Write-Host "Space 已存在,继续推送文件:$repoId"
75
  } else {
76
  throw
77
  }
78
  }
79
 
80
- git add Dockerfile start-space.sh README.md PUBLIC_USAGE.md ADMIN_SETUP.md .env.example .gitattributes .gitignore package.json scripts/check-supabase.mjs scripts/generate-secrets.ps1 scripts/deploy-hf-space.ps1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  $hasCommit = $true
83
  git rev-parse --verify HEAD *> $null
@@ -92,21 +103,21 @@ if ($LASTEXITCODE -ne 0) {
92
  }
93
 
94
  if ($hasStagedChanges) {
95
- git commit -m "Deploy sub2api HF Space"
96
  } elseif (-not $hasCommit) {
97
- throw "没有可提交的文件,请检查 git 状态。"
98
  } else {
99
- Write-Host "没有新的本地文件需要提交。"
100
  }
101
 
102
  $pushUrl = "https://hf_user:$($env:HF_TOKEN)@huggingface.co/spaces/$repoId"
103
  git push $pushUrl HEAD:main
104
 
105
  Write-Host ""
106
- Write-Host "部署文件已推送。Space 页面:"
107
  Write-Host "https://huggingface.co/spaces/$repoId"
108
  Write-Host ""
109
- Write-Host "构建完成后的公开访问地址:"
110
  Write-Host "https://$($Owner)-$($SpaceName).hf.space"
111
  Write-Host ""
112
- Write-Host "下一步:到 Space Settings -> Variables and secrets 添加 Supabase 和管理员 Secrets。"
 
7
  $ErrorActionPreference = "Stop"
8
 
9
  if (-not $env:HF_TOKEN) {
10
+ throw "Set HF_TOKEN first. Example: `$env:HF_TOKEN = 'hf_xxx'"
11
  }
12
 
13
  $root = Resolve-Path (Join-Path $PSScriptRoot "..")
 
15
 
16
  $requiredFiles = @(
17
  "Dockerfile",
18
+ "sub2api-hf-rootfs.tar",
19
  "start-space.sh",
20
  "README.md",
21
  "PUBLIC_USAGE.md",
22
  "ADMIN_SETUP.md",
23
  ".env.example",
24
  ".gitattributes",
25
+ ".gitignore",
26
+ "package.json",
27
+ "scripts/check-supabase.mjs",
28
+ "scripts/generate-secrets.ps1",
29
+ "scripts/deploy-hf-space.ps1"
30
  )
31
 
32
  foreach ($file in $requiredFiles) {
33
  if (-not (Test-Path -LiteralPath (Join-Path $root $file))) {
34
+ throw "Missing deployment file: $file"
35
  }
36
  }
37
 
38
+ $headers = @{ Authorization = "Bearer $env:HF_TOKEN" }
39
+ $whoami = Invoke-RestMethod -Uri "https://huggingface.co/api/whoami-v2" -Headers $headers -Method GET
 
 
 
 
 
 
40
 
41
  if (-not $Owner) {
42
  $Owner = $whoami.name
 
54
  $createBody.organization = $Owner
55
  }
56
 
 
 
57
  try {
58
  Invoke-RestMethod `
59
  -Uri "https://huggingface.co/api/repos/create" `
60
  -Headers ($headers + @{ "Content-Type" = "application/json" }) `
61
  -Method POST `
62
+ -Body ($createBody | ConvertTo-Json -Depth 5) | Out-Null
63
+ Write-Host "Created Hugging Face Space: $repoId"
64
  } catch {
65
  $statusCode = $null
66
  if ($_.Exception.Response) {
67
  $statusCode = [int] $_.Exception.Response.StatusCode
68
  }
 
69
  if ($statusCode -eq 409) {
70
+ Write-Host "Space already exists, continuing: $repoId"
71
  } else {
72
  throw
73
  }
74
  }
75
 
76
+ git lfs install
77
+
78
+ git add `
79
+ Dockerfile `
80
+ sub2api-hf-rootfs.tar `
81
+ start-space.sh `
82
+ README.md `
83
+ PUBLIC_USAGE.md `
84
+ ADMIN_SETUP.md `
85
+ .env.example `
86
+ .gitattributes `
87
+ .gitignore `
88
+ package.json `
89
+ scripts/check-supabase.mjs `
90
+ scripts/generate-secrets.ps1 `
91
+ scripts/deploy-hf-space.ps1
92
 
93
  $hasCommit = $true
94
  git rev-parse --verify HEAD *> $null
 
103
  }
104
 
105
  if ($hasStagedChanges) {
106
+ git commit -m "Deploy sub2api rootfs tar on HF Space"
107
  } elseif (-not $hasCommit) {
108
+ throw "No files were staged and the repository has no commits. Check git status."
109
  } else {
110
+ Write-Host "No new local files to commit."
111
  }
112
 
113
  $pushUrl = "https://hf_user:$($env:HF_TOKEN)@huggingface.co/spaces/$repoId"
114
  git push $pushUrl HEAD:main
115
 
116
  Write-Host ""
117
+ Write-Host "Deployment files pushed. Space page:"
118
  Write-Host "https://huggingface.co/spaces/$repoId"
119
  Write-Host ""
120
+ Write-Host "Public app URL after build:"
121
  Write-Host "https://$($Owner)-$($SpaceName).hf.space"
122
  Write-Host ""
123
+ Write-Host "Next: configure Space Settings -> Variables and secrets, then restart the Space."
sub2api-hf-rootfs.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b35d65716f0dd3c6bcd39eb33741a6152dd1ffb71bfcd88f154bb21f5cbcd86d
3
+ size 418663936