Skip to content

Commit 9c7ce1a

Browse files
committed
docs: ci.yml增加 deploy to vps
1 parent 557ff81 commit 9c7ce1a

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,22 @@ jobs:
3030
- name: Build VitePress
3131
run: yarn run docs:build
3232
# 步骤6:部署到Github Pages
33-
- name: Deploy to Github Pages
34-
uses: peaceiris/actions-gh-pages@v3
33+
# - name: Deploy to Github Pages
34+
# uses: peaceiris/actions-gh-pages@v3
35+
# with:
36+
# github_token: ${{ secrets.VITEPRESS_BLOG_TOKEN }} # 自定义的action环境变量
37+
# publish_dir: .vitepress/dist # 指定部署目录
38+
# publish_branch: gh-pages # 指定部署分支
39+
# dotfiles: true # 允许使用.gitignore文件
40+
# 步骤7: scp部署到 vps
41+
- name: Deploy to VPS
42+
uses: appleboy/scp-action@master
3543
with:
36-
github_token: ${{ secrets.VITEPRESS_BLOG_TOKEN }} # 自定义的action环境变量
37-
publish_dir: .vitepress/dist # 指定部署目录
38-
publish_branch: gh-pages # 指定部署分支
39-
dotfiles: true # 允许使用.gitignore文件
44+
host: ${{ secrets.SERVER_HOST }} # 服务器地址
45+
username: ${{ secrets.SERVER_USER }} # 服务器用户名
46+
port: ${{ secrets.SERVER_PORT }} # 服务器端口
47+
key: ${{ secrets.SERVER_SSH_KEY }} # 服务器SSH 密钥
48+
# password: ${{ secrets.SERVER_USER_PASSWORD }} # 服务器用户密码
49+
strip_components: 2 # 跳过指定目录
50+
source: '.vitepress/dist' # 源目录
51+
target: ${{ secrets.SERVER_TARGET }} # 目标目录

Docs/Back-End/Node/通过GithubAction将内容部署到vps.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,25 @@ jobs:
3636
- name: Build VitePress
3737
run: yarn run docs:build
3838
# 步骤6:部署到Github Pages
39-
- name: Deploy to Github Pages
40-
uses: peaceiris/actions-gh-pages@v3
39+
# - name: Deploy to Github Pages
40+
# uses: peaceiris/actions-gh-pages@v3
41+
# with:
42+
# github_token: ${{ secrets.VITEPRESS_BLOG_TOKEN }} # 自定义的action环境变量
43+
# publish_dir: .vitepress/dist # 指定部署目录
44+
# publish_branch: gh-pages # 指定部署分支
45+
# dotfiles: true # 允许使用.gitignore文件
46+
# 步骤7: scp部署到 vps
47+
- name: Deploy to VPS
48+
uses: appleboy/scp-action@master
4149
with:
42-
github_token: ${{ secrets.VITEPRESS_BLOG_TOKEN }} # 自定义的action环境变量
43-
publish_dir: .vitepress/dist # 指定部署目录
44-
publish_branch: gh-pages # 指定部署分支
45-
dotfiles: true # 允许使用.gitignore文件
50+
host: ${{ secrets.SERVER_HOST }} # 服务器地址
51+
username: ${{ secrets.SERVER_USER }} # 服务器用户名
52+
port: ${{ secrets.SERVER_PORT }} # 服务器端口
53+
key: ${{ secrets.SERVER_SSH_KEY }} # 服务器SSH 密钥
54+
# password: ${{ secrets.SERVER_USER_PASSWORD }} # 服务器用户密码
55+
strip_components: 2 # 跳过指定目录
56+
source: '.vitepress/dist' # 源目录
57+
target: ${{ secrets.SERVER_TARGET }} # 目标目录
4658
```
4759
4860
## 配置 Action 环境变量
@@ -66,12 +78,29 @@ jobs:
6678

6779
![github_pages](/Images/Back-End/Node/通过GithubAction将内容部署到vps/github_pages.png "github_pages")
6880

81+
## 配置action scp 部署到vps
6982

83+
1. 登录 `vps` ,生成 `SSH` 秘钥
84+
85+
```shell
86+
# 生成ssh秘钥
87+
ssh-keygen -t rsa -b 4096 -C "github-actions-node"
88+
# 将公钥复制到服务器的authorized_keys文件中
89+
cat /root/.ssh/id_rsa.pub >> authorized_keys
90+
```
91+
1. 配置 `Actions Secrets`
92+
93+
```shell
94+
# 打印私钥,复制粘贴到github action环境变量中,命名为SSH_KEY
95+
cat /root/.ssh/id_rsa
96+
```
7097

7198

7299
## 参考
73100
1. [GitHub Actions 入门教程](https://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html)
74101
1. [Github 管理个人访问令牌](https://docs.github.com/zh/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
75102
1. [通过 Github Action 将 GitHub 上的内容部署到 VPS](https://tourcoder.com/deploy-from-github-to-vps-via-github-action/)
76103
1. [使用 GitHub Actions 在代码更新时自动部署代码到 VPS](https://blog.csdn.net/m0_57236802/article/details/134216395)
77-
1. [vitepress项目使用github的action自动部署到github-pages中](https://blog.csdn.net/weixin_43972992/article/details/135123018)
104+
1. [vitepress项目使用github的action自动部署到github-pages中](https://blog.csdn.net/weixin_43972992/article/details/135123018)
105+
1. [使用Github Actions自动部署Golang应用到VPS服务器](https://github.com/axiaoxin/axiaoxin/issues/27)
106+
1. [使用 GitHub Actions 部署 Next.js 项目到 VPS](https://riddma.com/post/deploy-next-js-to-vps-using-github-actions)

0 commit comments

Comments
 (0)