--
:
--
:
--
1450 字
8 分钟
-- 次
cnb私有库发布到eop反代
最后更新于:
cnb私有库发布到eop反代

目录
[toc]
场景1:cnb公开库发布到eop反代(测试成功)
.cnb.yml代码:
1master:
2 push:
3 "volume-cache":
4 name: 云原生构建
5 runner:
6 cpus: 8
7 imports:
8 - https://cnb.cool/onedayxyy/secret/-/blob/main/envs.yml
9 docker:
10 image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/hugo-teek-blog:latest
11 volumes:
12 - node_modules:copy-on-write
13 env:
14 # 产物想要存入的分支名
15 DIST_BRANCH: dist
16 stages:
17 - name: set env
18 script: echo -n $(date +%s)
19 exports:
20 info: CUSTOM_ENV_START_TIME
21 - name: check
22 script: |
23 git fetch origin --prune --tags
24 #- name: install
25 # script: |
26 # apt update
27 # apt install -y rsync
28 # npm i -g pnpm
29 # pnpm i
30 - name: check branch
31 script: |
32 if ! git ls-remote --exit-code --heads origin ${DIST_BRANCH}; then
33 echo "Remote branch '${DIST_BRANCH}' not found, creating it..."
34 git checkout --orphan ${DIST_BRANCH}
35 git rm -rf .
36 echo "# ${DIST_BRANCH} initialized" > README.md
37 git add README.md
38 git commit -m "chore: init ${DIST_BRANCH} branch"
39 git push origin ${DIST_BRANCH}
40 git checkout -
41 fi
42 - name: 构建
43 script: |
44 make build-docker
45 git fetch origin ${DIST_BRANCH}:${DIST_BRANCH}
46 rm -rf .deploy-tmp
47 git worktree add .deploy-tmp ${DIST_BRANCH}
48 find .deploy-tmp -mindepth 1 \
49 -not -name ".git" \
50 -not -name ".gitkeep" \
51 -exec rm -rf {} +
52 cp -rf ./hugo-teek-site/public/* ./.deploy-tmp/
53 - name: 部署
54 script: |
55 cd ./.deploy-tmp/
56 git add -A
57 if ! git diff --cached --quiet; then
58 git commit -m "deploy: $(date '+%Y-%m-%d %H:%M:%S')" --allow-empty || echo "Nothing to commit"
59 git push origin ${DIST_BRANCH}
60 else
61 echo "No changes to deploy"
62 fi
63 cd ..
64 if [ -d ./.deploy-tmp/.git ]; then
65 git worktree remove .deploy-tmp --force
66 fi
67 - name: ⏱️ 计算耗时
68 script: |
69 # 计算耗时
70 end_time=$(date +%s)
71 duration=$((end_time - $CUSTOM_ENV_START_TIME))
72 minutes=$((duration / 60))
73 seconds=$((duration % 60))
74 time_str="${minutes}分${seconds}秒"
75 echo -n ${time_str}
76 exports:
77 info: CUSTOM_ENV_BUILD_TIME
78
79
80 - name: 钉钉通知
81 image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/tencentcom-dingtalk-bot-msg:latest_amd64
82 settings:
83 content: "「Hugo-Teek Blog」发布完成,耗时: ${CUSTOM_ENV_BUILD_TIME}"
84 c_type: "text" # 支持: text, markdown, link, actionCard, multiActionCard, feedCard
85 secret: $SECRET
86 webhook: $WEBHOOK
87 isAtAll: false
88 debug: false # 新增: 是否启用调试模式
89include:
90- .cnb/vscode.yml
场景2:cnb私有库发布到eop反代(测试成功)
基础信息
1仓库:https://cnb.cool/onedayxyy/hugo-teek-private
2hugo-teek-private 私有库 (存放hugo-tee源码及核心Md文档)
3
4仓库:https://cnb.cool/onedayxyy/hugo-teek-public-dist
5hugo-teek-public-dist 公开库(存放dist构建产物)
v2-2025.12.20(@xgq大佬写的 & w3c大佬改进的)(测试成功)
.cnb.yml代码:
1master:
2 push:
3 - runner:
4 cpus: 64
5
6 imports:
7 - https://cnb.cool/onedayxyy/secret/-/blob/main/envs.yml
8
9 docker:
10 image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/hugo-teek-blog:latest
11
12 env:
13 # 公开产物仓库
14 TARGET_REPO: "https://cnb.cool/onedayxyy/hugo-teek-public-dist.git"
15 # 产物分支
16 DIST_BRANCH: dist
17
18 stages:
19 # ------------------------------
20 # 1️⃣ 记录开始时间
21 # ------------------------------
22 - name: set env
23 script: echo -n $(date +%s)
24 exports:
25 info: CUSTOM_ENV_START_TIME
26
27 # ------------------------------
28 # 4️⃣ 构建 Hugo
29 # ------------------------------
30 - name: build
31 script: |
32 make build-docker
33
34 # ------------------------------
35 # 5️⃣ 部署到 public/dist
36 # ------------------------------
37 - name: deploy
38 script: |
39 REPO_URL=${TARGET_REPO}
40 DEPLOY_DIR="/workspace/deploy"
41 mkdir -p ${DEPLOY_DIR}
42 cd ${DEPLOY_DIR}
43 git init -b ${DIST_BRANCH} >/dev/null 2>&1
44 git remote add origin ${REPO_URL}
45 cp -al ../hugo-teek-site/public/. . >/dev/null 2>&1
46 git add -A >/dev/null 2>&1
47 git diff --cached --quiet || git commit -m "d:$(date +%s)" --no-gpg-sign >/dev/null 2>&1
48 git push --force --quiet origin ${DIST_BRANCH}
49
50 # ------------------------------
51 # 6️⃣ 计算耗时
52 # ------------------------------
53 - name: ⏱️ 计算耗时
54 script: |
55 end_time=$(date +%s)
56 duration=$((end_time - $CUSTOM_ENV_START_TIME))
57 minutes=$((duration / 60))
58 seconds=$((duration % 60))
59 echo -n "${minutes}分${seconds}秒"
60 exports:
61 info: CUSTOM_ENV_BUILD_TIME
62
63 # ------------------------------
64 # 7️⃣ 钉钉通知
65 # ------------------------------
66 - name: 钉钉通知
67 image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/tencentcom-dingtalk-bot-msg:latest_amd64
68 settings:
69 content: "「Hugo-Teek Blog」发布完成,耗时: ${CUSTOM_ENV_BUILD_TIME}"
70 c_type: "text"
71 secret: $SECRET
72 webhook: $WEBHOOK
73 isAtAll: false
74 debug: false
75
76include:
77 - .cnb/vscode.yml
v1-豆包版本
.cnb.yml代码:
1master:
2 push:
3 "volume-cache":
4 name: 云原生构建
5 runner:
6 cpus: 8
7 imports:
8 - https://cnb.cool/onedayxyy/secret/-/blob/main/envs.yml
9 docker:
10 image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/hugo-teek-blog:latest
11 volumes:
12 - node_modules:copy-on-write
13 env:
14 # 产物将要被推送到的目标仓库 (公开库)
15 TARGET_REPO: "https://cnb.cool/onedayxyy/hugo-teek-public-dist.git"
16 # 产物在目标仓库中的分支名
17 DIST_BRANCH: "dist"
18 stages:
19 - name: set env
20 script: echo -n $(date +%s)
21 exports:
22 info: CUSTOM_ENV_START_TIME
23
24 - name: 配置 Git
25 script: |
26 # 确保 Git 有一个用户身份,这在 CI 环境中很重要
27 git config --global user.name "CNB Bot"
28 git config --global user.email "bot@cnb.cool"
29
30 # 检查是否已存在名为 'public' 的远程仓库,如果存在则更新 URL
31 if git remote | grep -q "public"; then
32 git remote set-url public "$TARGET_REPO"
33 else
34 # 否则,添加 'public' 作为指向公开库的远程仓库
35 git remote add public "$TARGET_REPO"
36 fi
37
38 - name: check
39 script: |
40 # 拉取私有库 (origin) 的最新代码
41 git fetch origin --prune --tags
42 # 也拉取一下公开库 (public) 的最新代码,特别是 dist 分支
43 git fetch public --prune --tags
44
45 - name: check and create branch on public repo
46 script: |
47 # 检查公开库的 'dist' 分支是否存在
48 if ! git ls-remote --exit-code --heads public "${DIST_BRANCH}"; then
49 echo "Remote branch '${DIST_BRANCH}' not found in public repo, creating it..."
50 # 创建一个孤立的本地分支,没有任何历史
51 git checkout --orphan "${DIST_BRANCH}"
52 # 删除所有本地文件,因为这是一个全新的、只包含产物的分支
53 git rm -rf .
54 echo "# ${DIST_BRANCH} branch for public distribution" > README.md
55 git add README.md
56 git commit -m "chore: init ${DIST_BRANCH} branch"
57 # 将这个新分支推送到公开库 (public)
58 git push public "${DIST_BRANCH}"
59 # 切换回原来的工作分支 (master)
60 git checkout master
61 fi
62
63 - name: 构建
64 script: |
65 # 执行你的构建命令
66 make build-docker
67
68 # 确保本地有 'dist' 分支的最新版本
69 git checkout "${DIST_BRANCH}"
70 git pull public "${DIST_BRANCH}"
71 git checkout master
72
73 # 使用 git worktree 将 'dist' 分支的内容 checkout 到 .deploy-tmp 目录
74 rm -rf .deploy-tmp
75 git worktree add .deploy-tmp "${DIST_BRANCH}"
76
77 # 清空 .deploy-tmp 目录下的所有内容,准备放入新的构建产物
78 find .deploy-tmp -mindepth 1 \
79 -not -name ".git" \
80 -exec rm -rf {} +
81
82 # 将构建好的产物复制到 .deploy-tmp
83 cp -rf ./hugo-teek-site/public/* ./.deploy-tmp/
84
85 - name: 部署到公开库
86 script: |
87 cd ./.deploy-tmp/
88
89 # 检查是否有文件变化
90 git add -A
91 if ! git diff --cached --quiet; then
92 git commit -m "deploy: $(date '+%Y-%m-%d %H:%M:%S')"
93 # 将更改推送到公开库 (public) 的 'dist' 分支
94 git push public "${DIST_BRANCH}"
95 else
96 echo "No changes to deploy"
97 fi
98
99 cd ..
100 # 清理 worktree
101 if [ -d ./.deploy-tmp ]; then
102 git worktree remove .deploy-tmp --force
103 fi
104
105 - name: ⏱️ 计算耗时
106 script: |
107 end_time=$(date +%s)
108 duration=$((end_time - $CUSTOM_ENV_START_TIME))
109 minutes=$((duration / 60))
110 seconds=$((duration % 60))
111 time_str="${minutes}分${seconds}秒"
112 echo -n ${time_str}
113 exports:
114 info: CUSTOM_ENV_BUILD_TIME
115
116 - name: 钉钉通知
117 image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/tencentcom-dingtalk-bot-msg:latest_amd64
118 settings:
119 content: "「hugo-teek-private Blog」发布完成,耗时: ${CUSTOM_ENV_BUILD_TIME}"
120 c_type: "text"
121 secret: $SECRET
122 webhook: $WEBHOOK
123 isAtAll: false
124 debug: false
125
126include:
127- .cnb/vscode.yml
(3)eop反代云函数
下载地址:https://img.onedayxyy.cn/images/20251124-hugo-teek-private-functions.zip

(4)验证
https://hugo-teek.onedayxyy.cn/



结束。
📡
👤
作者:
余温Gueen
🌐
版权:
本站文章除特别声明外,均采用
CC BY-NC-SA 4.0
协议,转载请注明来自
余温Gueen Blog!
推荐使用微信支付

推荐使用支付宝

- 01snowshot 2025-12-26
- 02博客和文档是否需要拆分开 2025-12-26
- 03我的博客首页截图记录 2025-12-26