feat(ci): 试点规范 2(test → LAN → 手动 ubuntu2)
All checks were successful
CI-CD-2 / test (push) Successful in 2s
CI-CD-2 / deploy-lan (push) Successful in 3s
CI-CD-2 / deploy-cloud (push) Has been skipped

This commit is contained in:
2026-11-10 14:46:47 +08:00
parent 6d590673ae
commit adb1328b75
8 changed files with 271 additions and 0 deletions

48
deploy/cloud.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# 发布到 ubuntu2(101.133.145.181:/var/www/shashann-homepage)
# 注意:不切 DNS、不碰 ShannonProd;公网验证用 health-cloud.sh 的 --resolve。
set -euo pipefail
cd "$(dirname "$0")/.."
TARGET="${1:-}"
case "$TARGET" in
ubuntu2)
SSH_HOST="root@101.133.145.181"
DEPLOY_DIR="/var/www/shashann-homepage"
;;
*)
echo "不支持的目标: $TARGET"
exit 1
;;
esac
# 手动发布按 tag 注入版本;普通提交按短 SHA
VERSION="${TARGET_REF:-$GITEA_SHA}"
if printf '%s' "$VERSION" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
VERSION="${VERSION#v}"
else
VERSION="${GITEA_SHA:0:8}"
fi
python3 - "$VERSION" <<'PY'
import re
import sys
version = sys.argv[1]
path = "index.html"
html = open(path, encoding="utf-8").read()
html = re.sub(r'(assets/css/style\.css)\?v=[^"\']*', r"\1?v=" + version, html)
html = re.sub(r'(assets/js/main\.js)\?v=[^"\']*', r"\1?v=" + version, html)
open(path, "w", encoding="utf-8").write(html)
PY
mkdir -p ~/.ssh && chmod 700 ~/.ssh
printf '%s\n' "${DEPLOY_SSH_KEY:?DEPLOY_SSH_KEY 未配置}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H 101.133.145.181 >> ~/.ssh/known_hosts 2>/dev/null || true
ssh "$SSH_HOST" "mkdir -p ${DEPLOY_DIR} && find ${DEPLOY_DIR} -mindepth 1 -maxdepth 1 -exec rm -rf {} +"
tar czf - index.html assets robots.txt sitemap.xml llms.txt \
| ssh "$SSH_HOST" "tar xzf - -C ${DEPLOY_DIR}"
echo "ubuntu2 已发布 ${VERSION}"

8
deploy/health-cloud.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# 只验证 ubuntu2 上的副本;DNS 当前仍指向 ShannonProd,不能按公网 DNS 判断。
set -euo pipefail
curl -skf -m 10 --noproxy '*' \
--resolve www.shashann.com:443:101.133.145.181 \
https://www.shashann.com/ > /dev/null
echo "OK ubuntu2 https://www.shashann.com/ (101.133.145.181)"

13
deploy/health-lan.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
for _ in $(seq 1 10); do
if curl -skf -m 5 --noproxy '*' https://192.168.51.66/homepage/ > /dev/null; then
echo "OK https://192.168.51.66/homepage/"
exit 0
fi
sleep 3
done
echo "FAIL https://192.168.51.66/homepage/"
exit 1

30
deploy/lan.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# 发布到局域网 192.168.51.66:/home/ubuntu/homepage-site
set -euo pipefail
cd "$(dirname "$0")/.."
STAMP="${GITEA_SHA:0:8}"
[ -n "$STAMP" ] || { echo "GITEA_SHA 为空"; exit 1; }
python3 - "$STAMP" <<'PY'
import re
import sys
stamp = sys.argv[1]
path = "index.html"
html = open(path, encoding="utf-8").read()
html = re.sub(r'(assets/css/style\.css)\?v=[^"\']*', r"\1?v=" + stamp, html)
html = re.sub(r'(assets/js/main\.js)\?v=[^"\']*', r"\1?v=" + stamp, html)
open(path, "w", encoding="utf-8").write(html)
PY
mkdir -p ~/.ssh && chmod 700 ~/.ssh
printf '%s\n' "${DEPLOY_SSH_KEY:?DEPLOY_SSH_KEY 未配置}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H 192.168.51.66 >> ~/.ssh/known_hosts 2>/dev/null || true
ssh ubuntu@192.168.51.66 'mkdir -p /home/ubuntu/homepage-site && find /home/ubuntu/homepage-site -mindepth 1 -maxdepth 1 -exec rm -rf {} +'
tar czf - index.html assets robots.txt sitemap.xml llms.txt \
| ssh ubuntu@192.168.51.66 'tar xzf - -C /home/ubuntu/homepage-site'
echo "局域网已发布 ${STAMP}"