Repository navigation
97 lines (90 loc) · 4.77 KB
/
Copy pathweb-deploy.yml
File metadata and controls
97 lines (90 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Builds and deploys the browser/WASM web client to Cloudflare (Worker +
# R2 -- see client/deploy/cloudflare-web/). Reusable (workflow_call, used by
# release-all.yml's client-web-deploy job on every real release) AND
# directly dispatchable (workflow_dispatch) so this exact deploy can be
# tested/re-run on its own without needing a full multi-platform release --
# useful right after rotating CLOUDFLARE_API_TOKEN or any of the other
# CLOUDFLARE_* secrets, to confirm they actually work before the next real
# release depends on them.
#
# All account-specific config (account id, R2 bucket, target domain) comes
# from repo secrets and is templated into wrangler.toml at deploy time --
# nothing account-identifying is committed anywhere in this repo.
name: web-deploy
on:
workflow_call: {}
workflow_dispatch: {}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: client/go.mod
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Build web client
working-directory: client
run: ./scripts/build_web.sh
- name: Upload oversized files to R2
# Anything over Cloudflare's 25MiB static-asset limit bypasses
# wrangler/the Worker's ASSETS binding entirely -- uploaded directly
# via the R2 API instead; worker.js's r2Routes streams each back out
# on request. Keys here MUST match worker.js's r2Routes exactly.
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CF_R2_BUCKET: ${{ secrets.CLOUDFLARE_R2_BUCKET }}
run: |
set -euo pipefail
put() {
curl -sf -X PUT \
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/r2/buckets/$CF_R2_BUCKET/objects/$1" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: $2" \
--data-binary @"$3"
}
put "app.wasm" "application/wasm" "client/web/app.wasm"
put "models/icon_detect.onnx" "application/octet-stream" "client/web/models/icon_detect.onnx"
put "vendor/ort/ort-wasm-simd-threaded.jsep.wasm" "application/wasm" "client/web/vendor/ort/ort-wasm-simd-threaded.jsep.wasm"
put "vendor/ort/ort-wasm-simd-threaded.asyncify.wasm" "application/wasm" "client/web/vendor/ort/ort-wasm-simd-threaded.asyncify.wasm"
- name: Deploy Worker (static assets + custom domain)
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CF_R2_BUCKET: ${{ secrets.CLOUDFLARE_R2_BUCKET }}
CF_WEB_DOMAIN: ${{ secrets.CLOUDFLARE_WEB_DOMAIN }}
run: |
set -euo pipefail
cd client/deploy/cloudflare-web
mkdir -p public/vendor/ort
cp ../../web/index.html ../../web/lite.html ../../web/gui.html ../../web/join.html ../../web/wasm_exec.js ../../web/ai_vision.js ../../web/favicon.ico public/
# Every vendor/ort/* file except the two oversized wasm binaries
# uploaded to R2 above -- the small *.mjs loaders and the plain
# (non-jsep, non-asyncify) CPU-fallback wasm, all under the 25MiB
# limit, served as normal static assets like everything else in
# public/.
find ../../web/vendor/ort -maxdepth 1 -type f \
! -name 'ort-wasm-simd-threaded.jsep.wasm' \
! -name 'ort-wasm-simd-threaded.asyncify.wasm' \
-exec cp {} public/vendor/ort/ \;
# The MCP bridge's prebuilt single-file bundle (see
# web/mcp-bridge/README.md) -- the Scripts & AI tab links straight
# to /mcp-bridge/bin/bridge.cjs for its "download the bridge"
# step. Path preserved as-is (not flattened) so it's identical to
# how build_web.sh --serve serves the same file locally.
mkdir -p public/mcp-bridge/bin
cp ../../web/mcp-bridge/bin/bridge.cjs public/mcp-bridge/bin/bridge.cjs
# dbnet.onnx (2.3MiB) and svtr.onnx (8.6MiB) -- the OCR stage's
# weights, see internal/localui/parser_wasm.go -- both comfortably
# under the 25MiB limit, unlike icon_detect.onnx (77MiB, R2-routed
# above), so served as plain static assets under Wrangler's own
# default asset caching rather than r2Routes' explicit
# Cache-Control.
mkdir -p public/models
cp ../../web/models/dbnet.onnx ../../web/models/svtr.onnx public/models/
sed -e "s/__R2_BUCKET__/$CF_R2_BUCKET/" -e "s/__WEB_DOMAIN__/$CF_WEB_DOMAIN/" \
wrangler.toml.template > wrangler.toml
npx --yes wrangler@3 deploy