hugo-teek is loading...

eop部署加速

最后更新于:

eop部署加速

加速从cnb发布到eop时间方案

image-20251111065249243

目录

[toc]

背景

hugo的构建速度很快,但是从cnb推送构建产物到eop很耗时,这里使用下之前w3c大佬提供的 eop的云函数 实现的一个方法,可以加速从cnb发布到eop的构建时间。 XGQ大佬提供了具体的实现方式。请看下文。

通过次方案实现后,从cnb传输构建产物到eop会从原来的耗时很长时间,直接缩短到0.5s左右,非常好用。😜

image-20251111065721411

版权

w3c大佬 之前提供的方案。

XGQ大佬 参考我写的那个文档:《CNB配合Pages另一种部署方法

我经实际测试是生效的。

环境

hugo-teek博客

效果

image-20251110123143516

image-20251110123217490

image-20251110123202587

配置

1、eo pages的一个项目里上传云函数文件

  • 新建一个Pages:

image-20251111064516964

image-20250813071118593

  • 本地编辑好eo云函数wiki-functions.zip

次压缩包位置:https://img.onedayxyy.cn/images/wiki-functions.zip

修改地方1:

编辑functions\[[cnburi]].js

image-20251111064730360

修改地方2:

编辑functions\index.js

image-20251111064836039

只修好这2处地方就好,然后打包成zip格式。

这里只需修改自己的仓库名称就好,分支默认为dist分支就好。

  • 把打包好的functions.zip上传到这个地方:

image-20250813071131529

image-20250813071118593

  • 绑定自定义域名

image-20251111064918268

2、cnb公开库推送代码

  • 编辑.cnb.yml

本次代码是 XGQ 大佬 针对 hugo-teek 专门写的。

 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
45            git fetch origin ${DIST_BRANCH}:${DIST_BRANCH}
46            rm -rf .deploy-tmp
47            #pnpm run docs:build
48            git worktree add .deploy-tmp ${DIST_BRANCH}
49            find .deploy-tmp -mindepth 1 \
50              -not -name ".git" \
51              -not -name ".gitkeep" \
52              -exec rm -rf {} +
53            cp -rf ./hugo-teek-site/public/* ./.deploy-tmp/
54        - name: 部署
55          script: |
56            cd ./.deploy-tmp/
57            git add -A
58            if ! git diff --cached --quiet; then
59              git commit -m "deploy: $(date '+%Y-%m-%d %H:%M:%S')" --allow-empty || echo "Nothing to commit"
60              git push origin ${DIST_BRANCH}
61            else
62              echo "No changes to deploy"
63            fi
64            cd ..
65            if [ -d ./.deploy-tmp/.git ]; then
66              git worktree remove .deploy-tmp --force
67            fi
68        - name: ⏱️ 计算耗时
69          script: |
70            # 计算耗时
71            end_time=$(date +%s)
72            duration=$((end_time - $CUSTOM_ENV_START_TIME))
73            minutes=$((duration / 60))
74            seconds=$((duration % 60))
75            time_str="${minutes}分${seconds}秒"
76            echo -n ${time_str}
77          exports:
78            info: CUSTOM_ENV_BUILD_TIME
79
80            
81        - name: 钉钉通知
82          image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/tencentcom-dingtalk-bot-msg:latest_amd64
83          settings:
84            content: "「Hugo-Teek Blog」发布完成,耗时: ${CUSTOM_ENV_BUILD_TIME}"
85            c_type: "text" # 支持: text, markdown, link, actionCard, multiActionCard, feedCard
86            secret: $SECRET
87            webhook: $WEBHOOK
88            isAtAll: false
89            debug: false # 新增: 是否启用调试模式       
90include:
91- .cnb/vscode.yml                 
  • 直接推送
1git add -A
2git commit -m"commit"
3git push

3、测试效果

  • 观察下cnb构建过程(OK的)

image-20251111064325738

  • 访问域名,观察效果:

https://hugo-teek.onedayxyy.cn/

image-20251111064201597

FAQ

(已解决)原来的404页面失效如何解决

(1)问题现象

使用了eop反代云函数后,网站输入不存在的url弹出的不友好提示该如何解决?

2025年11月11日提出。

https://hugo-teek.onedayxyy.cn/topic/hugo-teek-jieshao/

image-20251111012457905

image-20251111012534198

(2)解决办法

image-20251112200927196

我配置好的云函数压缩包地址:

https://img.onedayxyy.cn/images/hugo-teek-functions.zip

配置方法:(将以下404地址改为 自己的域名)

image-20251112201105007

测试效果是OK的:(到此,以上问题已完美解决)

https://hugo-teek.onedayxyy.cn/jj

image-20251112201137859

传统部署方式.cnb.yml文件

.cnb.yml_ori

 1# 这个需要填写仓库分支,默认是main,我的是master,所以改成master
 2master:
 3  push:
 4    "volume-cache":
 5      name: 云原生构建
 6      runner:
 7        cpus: 8
 8      imports:	
 9        - https://cnb.cool/yuwen-gueen/secrets/-/blob/main/wiki.yml
10      docker:
11        image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/hugo-teek-blog:latest
12      stages:
13        - name: set env
14          script: echo -n $(date +%s)
15          exports:
16            info: CUSTOM_ENV_START_TIME
17        - name: 🖨️ 编译打包
18          script: |
19            make build
20        - name: 🚚 部署到Pages
21          image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/node:22_amd64
22          script: >-
23            npx edgeone pages deploy ./hugo-teek-site/public --name
24            yuwen-wiki --token $EDGEONE_PAGES_API_TOKEN
25
26
27        # #同步仓库到gitee                  
28        # - name: sync to gitee
29        #   image: tencentcom/git-sync
30        #   settings:
31        #     branch: master
32        #     auth_type: https
33        #     username: ${GIT_USERNAME}
34        #     password: ${GIT_ACCESS_TOKEN}
35        #     target_url: https://gitee.com/onlyonexl/vitepress-theme-teek-one-private.git
36        #     # git_email: 'github-actions[bot]@users.noreply.github.com'
37
38        # - name: build knowledge base
39        #   image: cnbcool/knowledge-base
40        #   settings:
41        #     embedding_model: bge-m3
42        #     include: "**/**.md"
43        #     exclude: ""    
44        #
45        - name: ⏱️ 计算耗时
46          script: |
47            # 计算耗时
48            end_time=$(date +%s)
49            duration=$((end_time - $CUSTOM_ENV_START_TIME))
50            minutes=$((duration / 60))
51            seconds=$((duration % 60))
52            time_str="${minutes}分${seconds}秒"
53            echo -n ${time_str}
54          exports:
55            info: CUSTOM_ENV_BUILD_TIME
56
57            
58        - name: 钉钉通知
59          image: docker.cnb.cool/yuwen-gueen/docker-images-chrom/tencentcom-dingtalk-bot-msg:latest_amd64
60          settings:
61            content: "「Hugo-Teek Blog」发布完成,耗时: ${CUSTOM_ENV_BUILD_TIME}"
62            c_type: "text" # 支持: text, markdown, link, actionCard, multiActionCard, feedCard
63            secret: $DINGDING_SECRET
64            webhook: $DINGDING_WEBHOOK
65            isAtAll: false
66            debug: false # 新增: 是否启用调试模式
67
68        # - name: 🔔 发布通知  
69        #   image: tencentcom/wecom-message
70        #   settings:
71        #     robot: ${WECOM_BOT}
72        #     msgType: markdown
73        #     content: |
74        #       > **🎉 余温Gueen Blog 又一次发布成功啦!**   
75        #       > **构建时间:** $CUSTOM_ENV_DATE_INFO 
76        #       > **构建耗时:** ${CUSTOM_ENV_BUILD_TIME}        
77        #       > **构建id:** $CNB_BUILD_ID  
78        #       > **提交id:** $CNB_COMMIT_SHORT            
79        #       > **构建分支:** $CNB_BRANCH
80        #       > **提交信息:** $CNB_COMMIT_MESSAGE_TITLE
81        #       > **提交者:** $CNB_COMMITTER
82        #       > **仓库地址:** [$CNB_REPO_URL_HTTPS]($CNB_REPO_URL_HTTPS)
83        #       > **我的网站:** [wiki.xxdevops.cn](https://wiki.xxdevops.cn/) 

如何把私有库构建好的产物推送到 公开库的dist分支呢

提示

以上方法是公开开teek仓库推送到公开库dist分支的。

但是如何把私有库构建好的产物推送到 公开库的dist分支呢?

请看如下代码:([二丫](https://jenkinsguide.opsre.top/)贡献的代码,经实际测试OK的)

关于我

我的博客主旨:

  • 排版美观,语言精炼;
  • 文档即手册,步骤明细,拒绝埋坑,提供源码;
  • 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!

🍀 个人网站

image-20250109220325748

🍀 微信二维码

x2675263825 (舍得), qq:2675263825。

image-20230107215114763

🍀 微信公众号

《云原生架构师实战》

image-20230107215126971

🍀 csdn

https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

image-20230107215149885

🍀 知乎

https://www.zhihu.com/people/foryouone

image-20230107215203185

最后

如果你还有疑惑,可以去我的网站查看更多内容或者联系我帮忙查看。

如果你有更好的方式,评论区留言告诉我。谢谢!

好了,本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!

推荐使用微信支付
微信支付二维码
推荐使用支付宝
支付宝二维码
最新文章

文档导航