惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
T
Threatpost
N
News and Events Feed by Topic
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
D
Docker
G
Google Developers Blog
Microsoft Security Blog
Microsoft Security Blog
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
T
Troy Hunt's Blog
Webroot Blog
Webroot Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
量子位
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
F
Full Disclosure
B
Blog
O
OpenAI News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security
Know Your Adversary
Know Your Adversary
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
Scott Helme
Scott Helme
T
The Exploit Database - CXSecurity.com
博客园 - 聂微东
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
Recorded Future
Recorded Future
IT之家
IT之家
Project Zero
Project Zero
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
SecWiki News
SecWiki News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

MadLife

算法部署从docker到K8s 聊一聊:Prometheus监控系统 聊一聊:AI时代的前夜 Web服务打包exe 聊一聊:我眼中的数据中台 内网ubuntu环境下离线部署K8s 聊一聊:FaaS 在大规模网络爬虫的实践 聊一聊:Golang 使用sync.Pool 降低GC压力 聊一聊:Python和Golang的垃圾回收 聊聊数据库的那些索引 源码阅读——robfig/cron 聊聊 MongoDB 聊一聊:敏捷开发 聊一聊:常见的分布式锁 2021书单 sentry部署 MongoDB——TTL索引 S3协议入门 使用 Go 客户端控制 Kubernetes
GitHub Actions+Serverless搭建博客
Yance Huang · 2021-09-11 · via MadLife

这个博客网站架构经历了好几次的变更:

  • 为了学习django:在学校对着视频,自己写了一个传统博客站点,对应的项目:Github
  • 自己写的前端太丑:转入博客园
  • 博客园也不稳定:转入gitpage
  • gitpage太慢:转入腾讯云

去年在V站上面,看到小伙伴在推荐良心云的云开发 CloudBase可以有免费的cdn用,也是觉得gitpage的访问速度属实太慢了,去年年底就把博客挂在了良心云上面,目前使用下来,访问速度还是比较满意的。

本文主要记录一下,配置github actions 自动化部署hexo站点到CloudBase。

获取配置信息

secretId 🔐

Required 云开发的访问密钥 secretId.

在腾讯云访问管理页面获取

secretKey 🔐

Required 云开发的访问密钥 secretKey.

在腾讯云访问管理页面获取

envId 🔐

Required 云开发的环境 id envId.

可以在云开发的控制台获取

staticSrcPath

Github 项目静态文件的路径。 默认值 build

如果需要上传项目根目录,可以填写 ./, 不过需要注意忽略不必要的文件,默认情况下会忽略 .git,.github,node_modules

staticDestPath

静态资源部署到云开发静态托管的路径,默认为根目录。

staticIgnore

v.1.1.0 版本开始支持

静态资源部署时忽略的文件路径,支持通配符,例如node_modules/**, 多个路径可以用,隔开,默认值 .git,.github,node_modules

Github仓库配置

前往项目 Github 文件夹的Settings标签页,在项目的Secrets中配置 准备工作 步骤获取的 SECRET_IDSECRET_KEYENV_ID

4Smrw9.jpg

创建工作流

Workflow 就是 GitHub Actions 的配置文件,类似于 .travis.yml

首先新建文件:

1
2
mkdir -p .github/workflows
touch .github/workflows/deploy.yml

编辑 deploy.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Deploy                      # Actions 显示的名字,随意设置

on: [push] # 监听到 push 事件后触发

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout # 拉取当前执行 Actions 仓库的指定分支
uses: actions/checkout@v2
with:
ref: hexo

- name: Update Submodule # 如果仓库有 submodule,在这里更新,没有则删掉此步骤
run: |
git submodule init
git submodule update --remote

- name: Setup Node # 安装 Node 环境
uses: actions/setup-node@v1
with:
node-version: "16.5"

- name: Hexo Generate # 安装 Hexo 依赖并且生成静态文件
run: |
rm -f .yarnclean
yarn --frozen-lockfile --ignore-engines --ignore-optional --non-interactive --silent --ignore-scripts --production=false
rm -rf ./public
yarn run hexo clean
yarn run hexo generate

- name: Deploy to Tencent CloudBase
uses: TencentCloudBase/cloudbase-action@v1.1.1
with:
secretId: ${{ secrets.SECRETID }}
secretKey: ${{ secrets.SECRETKEY }}
envId: ${{ secrets.ENVID }}
staticSrcPath: ./public
staticIgnore: .git,.github,node_modules

自动部署

配置完后即可提交代码体验自动部署,在每次 git push 命令完成后,Actions 都会自动运行,将项目的静态资源部署到您的云开发静态托管环境中,部署成功之后即可通过云开发提供的 默认域名 访问来您的网站。

4Sne0J.png