Skip to content
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
21 changes: 12 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Deploy Cloudflare Workers

on:
push:
branches:
- main
workflow_dispatch:
inputs:
target:
Expand All @@ -16,12 +19,12 @@ permissions:
contents: read

concurrency:
group: deploy-${{ inputs.target }}
group: deploy-cloudflare-workers
cancel-in-progress: false

jobs:
deploy:
name: Deploy ${{ inputs.target }}
name: Deploy Worker
runs-on: ubuntu-latest
timeout-minutes: 15
env:
Expand All @@ -46,16 +49,16 @@ jobs:
run: npm run validate

- name: Verify deployment configuration
if: inputs.target == 'production'
if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'production'
run: npm run deploy:check --workspace @margrop-labs/web

- name: Verify preview deployment configuration
if: inputs.target == 'preview'
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'preview')
run: npm run deploy:check:preview --workspace @margrop-labs/web

- name: Deploy preview
id: deploy-preview
if: inputs.target == 'preview'
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'preview')
shell: bash
run: |
set +e
Expand All @@ -76,19 +79,19 @@ jobs:
echo "$deployment_url" >> "$GITHUB_STEP_SUMMARY"

- name: Smoke test preview
if: inputs.target == 'preview'
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'preview')
run: npm run smoke --workspace @margrop-labs/web -- "${{ steps.deploy-preview.outputs.deployment_url }}"

- name: Deploy production
if: inputs.target == 'production'
if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'production'
run: npm run deploy:production --workspace @margrop-labs/web

- name: Smoke test production
if: inputs.target == 'production'
if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'production'
run: npm run smoke --workspace @margrop-labs/web -- https://lab.margrop.net

- name: Record production URL
if: inputs.target == 'production'
if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'production'
run: |
echo "### Production deployed" >> "$GITHUB_STEP_SUMMARY"
echo "https://lab.margrop.net" >> "$GITHUB_STEP_SUMMARY"
9 changes: 6 additions & 3 deletions docs/adr/0005-token-forge-ai-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ ADR-0003 选择 Astro 静态输出与 Cloudflare Workers Static Assets,并要
Provider 正文、计划正文或原始错误。
10. 页面提供显式“AI 增强生成”和独立“仅生成模板”。AI、网络、限流、熔断或输出校验失败
时,完整模板和导出继续可用。
11. `main` 的每次 push 自动部署并 smoke test 隔离的 Preview Worker;Production 仍只允许
仓库所有者通过 `workflow_dispatch` 人工触发,且两种部署串行执行。

## 自定义端口约束

Worker 使用 `allow_custom_ports` compatibility flag 才能请求 `16666`。该上游主机名必须
保持 Cloudflare DNS-only(灰云),否则 Cloudflare Proxy 不接受的 HTTPS 端口不会被代理。
如果必须启用橙云,应把上游迁移到 443 或 Cloudflare 支持的 HTTPS 端口,再更新固定配置。
Worker 的 `compatibility_date` 晚于 `2024-09-02`,因此无需显式声明已经默认启用的
`allow_custom_ports`,仍可请求 `16666`。该上游主机名必须保持 Cloudflare DNS-only
(灰云),否则 Cloudflare Proxy 不接受的 HTTPS 端口不会被代理。如果必须启用橙云,应把
上游迁移到 443 或 Cloudflare 支持的 HTTPS 端口,再更新固定配置。

Cloudflare 参考:

Expand Down
16 changes: 9 additions & 7 deletions docs/cloudflare-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Secret。
`https://api-gpt.speedtest.margrop.net:16666/v1/chat/completions`,模型为
`qwen-latest`。由于使用自定义端口,`api-gpt.speedtest.margrop.net` 必须保持
Cloudflare DNS-only(灰云);若启用橙云,应先把服务迁移到 443 或受支持的 HTTPS 端口。
Worker 的 `allow_custom_ports` compatibility flag 已在配置中固定。
Worker 的 `compatibility_date` 晚于 `2024-09-02`,自定义端口能力已经默认启用,不再显式
声明 `allow_custom_ports`。

Bindings、变量和 Secrets 是按环境隔离的,见
[Wrangler environments](https://developers.cloudflare.com/workers/wrangler/environments/);
Expand All @@ -54,13 +55,14 @@ Bindings、变量和 Secrets 是按环境隔离的,见

## 发布流程

部署不会随 `main` 提交自动触发。进入 GitHub Actions 的
`Deploy Cloudflare Workers`,选择 `Run workflow`,然后选择:
每次提交合并或推送到 `main` 后,`Deploy Cloudflare Workers` 会自动执行 Preview 的完整
质量门、Wrangler dry-run、部署和在线 smoke test。自动 Preview 失败时停止,不会继续执行
Production。

1. `preview`:执行完整质量门、Wrangler dry-run、部署和在线 smoke test。
2. 在手机宽度和桌面浏览器完成验收。
3. `production`:再次执行质量门、dry-run、正式部署和
`https://lab.margrop.net` 在线 smoke test。
需要重新运行 Preview 时,也可以在 GitHub Actions 中选择 `Run workflow` 和 `preview`。
完成手机宽度与桌面浏览器验收后,仓库所有者才能手动选择 `production`;Production 会再次
执行质量门、dry-run、正式部署和 `https://lab.margrop.net` 在线 smoke test。Preview 与
Production 共用串行部署队列,不会同时修改 Cloudflare Worker。

命令行等价操作:

Expand Down