From 673914783def6542fdad3cd443ece90c27f295fd Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Mon, 6 Jul 2026 09:59:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ci):=20=E5=AE=98=E7=BD=91=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E6=94=B9=E7=94=A8=20Cloudflare=20Pages(=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=20rsync=20=E5=88=B0=20pangolin1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 节点 :443 被 sing-box(VPN 数据面)占用,CF 免费套餐回源只能打 :80/:443、改端口需 Enterprise —— 故官网改由 CF Pages 托管(项目 pangolin-site,自定义域 pangolin.yanmeiai.com), 纯静态、全程 HTTPS、_headers/CSP 自动生效、不落 VPS、彻底无 :443 冲突。 deploy-site.sh 改为 wrangler pages deploy(需 CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID Gitea secret);deploy-site.yml deploy 步骤在 node:20 容器内跑 wrangler。lib-ssh 仍供服务端部署用。 Co-Authored-By: Claude Opus 4.8 --- .gitea/workflows/deploy-site.yml | 10 ++++++--- scripts/ci/deploy-site.sh | 37 +++++++++++++++----------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.gitea/workflows/deploy-site.yml b/.gitea/workflows/deploy-site.yml index 086957b..992051f 100644 --- a/.gitea/workflows/deploy-site.yml +++ b/.gitea/workflows/deploy-site.yml @@ -23,7 +23,11 @@ jobs: -e SITE_URL=https://pangolin.yanmeiai.com \ node:20 bash scripts/ci/compile-site.sh - - name: Deploy → pangolin1 + - name: Deploy → Cloudflare Pages env: - DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} - run: bash scripts/ci/deploy-site.sh + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + run: | + docker run --rm -v "$PWD:/w" -w /w \ + -e CLOUDFLARE_API_TOKEN -e CLOUDFLARE_ACCOUNT_ID \ + node:20 bash scripts/ci/deploy-site.sh diff --git a/scripts/ci/deploy-site.sh b/scripts/ci/deploy-site.sh index 79bec6b..e4914c0 100755 --- a/scripts/ci/deploy-site.sh +++ b/scripts/ci/deploy-site.sh @@ -1,32 +1,29 @@ #!/usr/bin/env bash -# deploy-site.sh — rsync the built Astro 官网 (web/website/dist/) to the -# pangolin1 VPS web root (/var/www/pangolin-site). Deploy user is root — the -# CI deploy key (secrets.DEPLOY_SSH_KEY) is authorized for root on the host. -# Static files only; nginx/caddy serves them directly, no service restart -# needed. Assumes it is invoked from the repo root, after compile-site.sh has -# produced web/website/dist/. +# deploy-site.sh — 部署构建好的 Astro 官网 (web/website/dist/) 到 Cloudflare Pages。 +# +# 官网托管在 CF Pages(项目 pangolin-site,自定义域 pangolin.yanmeiai.com),纯静态、 +# 全程 HTTPS、CSP(_headers)自动生效,不落在 VPS 上 —— 故与节点 :443(sing-box)无冲突。 +# +# 需环境变量: +# CLOUDFLARE_API_TOKEN 带 Account > Cloudflare Pages > Edit 权限的 CF token +# CLOUDFLARE_ACCOUNT_ID CF 账户 ID +# 由 compile-site.sh 先产出 web/website/dist/;从 repo 根调用。 set -euo pipefail -# shellcheck source=scripts/ci/lib-ssh.sh -. scripts/ci/lib-ssh.sh - -# setup_ssh registers the EXIT cleanup trap itself (before writing the key), -# so a mid-setup failure still cleans up — see lib-ssh.sh. -setup_ssh - -# Guard against deploying a missing/empty build: `rsync --delete` against an -# empty source would wipe the live site. if [ ! -d web/website/dist ]; then - echo "==> deploy-site: web/website/dist/ does not exist — refusing to deploy" >&2 + echo "==> deploy-site: web/website/dist/ 不存在 — 拒绝部署" >&2 exit 1 fi if ! find web/website/dist -mindepth 1 -print -quit | grep -q .; then - echo "==> deploy-site: web/website/dist/ is empty — refusing to deploy" >&2 + echo "==> deploy-site: web/website/dist/ 为空 — 拒绝部署" >&2 exit 1 fi -DEPLOY_TARGET="root@${DEPLOY_HOST}:/var/www/pangolin-site/" -echo "==> deploy-site: rsync web/website/dist/ -> ${DEPLOY_TARGET}" -rsync -az --delete -e "${RSYNC_SSH}" web/website/dist/ "${DEPLOY_TARGET}" +: "${CLOUDFLARE_API_TOKEN:?deploy-site: CLOUDFLARE_API_TOKEN 未设(需带 Pages:Edit)}" +: "${CLOUDFLARE_ACCOUNT_ID:?deploy-site: CLOUDFLARE_ACCOUNT_ID 未设}" + +echo "==> deploy-site: wrangler pages deploy → project pangolin-site (branch main)" +npx --yes wrangler@4 pages deploy web/website/dist \ + --project-name=pangolin-site --branch=main --commit-dirty=true echo "==> deploy-site: done"