应用 hugo 搭建集体博客,GitHub 治理博客资源,GitHub Actions 主动构建更新博客站点。
后期筹备
- GitHub
- Docker
- Nginx
- Hugo
- 一个曾经备案的域名
- 一台在线的服务器
- Let’s Encrypt HTTPS 证书
GitHub Actions 主动公布
name: Deploy Blog
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy Blog
uses: appleboy/ssh-action@master
with:
host: ${{secrets.BLOG_ALIYUN_HOST}}
username: ${{secrets.BLOG_ALIYUN_USERNAME}}
key: ${{secrets.ID_RSA_HUG_BLOG_ALIYUN}}
script: |
if [! -d "kk70-blog-source"]; then
git clone https://github.com/kevin70/blog.git kk70-blog-source
fi
cd kk70-blog-source
git pull --rebase
git submodule update --init --recursive
docker run --rm -i -v ~/kk70-blog-source:/src klakegg/hugo:0.74.3
if [! -d "/usr/share/nginx/kk70.top"]; then
mkdir -p /usr/share/nginx/kk70.top
else
rm -rf /usr/share/nginx/kk70.top/*
fi
cp -R public/* /usr/share/nginx/kk70.top/
应用 appleboy/ssh-action 连贯近程服务器构建更新 Blog。
在 GitHub 仓库的 Settings > Secrets 中配置敏感参数。
- 服务器主机
- 服务器登录用户名
- SSH 证书私钥
检出源码 shell
if [! -d "kk70-blog-source"]; then
git clone https://github.com/kevin70/blog.git kk70-blog-source
fi
cd kk70-blog-source
git pull --rebase
git submodule update --init --recursive
应用 docker 构建
docker run --rm -i -v ~/kk70-blog-source:/src klakegg/hugo:0.74.3
将站点部署到 Nginx
if [! -d "/usr/share/nginx/kk70.top"]; then
mkdir -p /usr/share/nginx/kk70.top
else
rm -rf /usr/share/nginx/kk70.top/*
fi
cp -R public/* /usr/share/nginx/kk70.top/
主站 https://kk70.top/
代码仓库 https://github.com/kevin70/blog