-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
name: Build app and deploy | ||
name: Deploy My Server | ||
|
||
on: | ||
#监听push操作 | ||
push: | ||
branches: | ||
# main分支,你也可以改成其他分支 | ||
- main | ||
|
||
jobs: | ||
build: | ||
# runs-on 指定job任务运行所需要的虚拟机环境(必填字段) | ||
runs-on: ubuntu-latest | ||
steps: | ||
# 获取源码 | ||
- name: Checkout | ||
# 使用action库 actions/checkout获取源码 | ||
uses: actions/checkout@master | ||
# 安装 Node | ||
- name: use Node.js 18.17.0 | ||
# 使用action库 actions/setup-node安装node | ||
deploy: | ||
runs-on: ubuntu-latest # 使用ubuntu系统镜像运行自动化脚本 | ||
|
||
steps: # 自动化步骤 | ||
#下载代码仓库 | ||
- uses: actions/checkout@v1 | ||
|
||
# 使用action库,安装node | ||
- name: use Node.js # 使用action库 actions/setup-node安装node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 18.17.0 | ||
node-version: 18.17.0 # 指定node版本 | ||
# 安装依赖 | ||
- name: npm install | ||
run: npm install | ||
# 打包 | ||
- name: npm run build | ||
|
||
#打包项目 | ||
- name: Build | ||
run: npm run build | ||
# 部署到云服务器 | ||
- name: Deploy to Server # 第二步,rsync推文件 | ||
uses: AEnterprise/[email protected] # 使用别人包装好的步骤镜像 | ||
|
||
#部署到服务器 | ||
- name: Deploy to Staging My server | ||
uses: easingthemes/[email protected] | ||
env: | ||
DEPLOY_KEY: ${{ secrets.MY_SERVER_PRIVATE_KEY }} # 引用配置,SSH私钥 | ||
ARGS: -avz --delete --exclude='*.pyc' # rsync参数,排除.pyc文件 | ||
SERVER_PORT: "22" # SSH端口 | ||
FOLDER: ./docs/.vuepress/dist # 要推送的文件夹,路径相对于代码仓库的根目录,视情况替换为自己的文件夹路径 | ||
SERVER_IP: ${{ secrets.IP }} # 引用配置,服务器的host名(IP或者域名domain.com) | ||
USERNAME: root # 引用配置,服务器登录名 | ||
SERVER_DESTINATION: /root/app # 部署到目标文件夹 | ||
#私钥 | ||
SSH_PRIVATE_KEY: ${{ secrets.MY_SERVER_PRIVATE_KEY }} | ||
ARGS: "-rltgoDzvO" | ||
SOURCE: "docs/.vuepress/dist" | ||
REMOTE_HOST: ${{ secrets.IP }} #服务器ip | ||
REMOTE_USER: "root" | ||
TARGET: "/root/app/" | ||
EXCLUDE: "/dist/, /node_modules/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,13 +31,21 @@ author: | |
|
||
首先我们需要**配置私钥到 GitHub Actions** ,以便其可以与我们的云服务器交互 | ||
|
||
首先我们需要在云服务器生成 SSH 密钥,然后在`~/.ssh`文件夹下就会生成`id_rsa`和`id_rsa.pub`两个文件,分别为私钥和公钥 | ||
首先我们需要在**云服务器生成 SSH 密钥**,然后在`~/.ssh`文件夹下就会生成`id_rsa`和`id_rsa.pub`两个文件,分别为私钥和公钥 | ||
|
||
```bash | ||
ssh-keygen -t rsa -C "[email protected]" | ||
``` | ||
|
||
然后打开上面我们提供的博客仓库地址,找到 Settings 中的 Actinons ,然后点击 `New repository secret`,然后自定义密钥名称(我的名字是 KEY),然后填入上面的 `id_rsa`,然后即可生成成功 | ||
或者说我们可以**指定私钥和公钥的名称** | ||
|
||
```bash | ||
ssh-keygen -t rsa -f action -C "[email protected]" | ||
``` | ||
|
||
然后就会在 `~/.ssh`下生成两个文件:`mysite`(私钥)和`mysite.pub`(公钥) | ||
|
||
之后打开上面我们提供的博客仓库地址,找到 Settings 中的 Actinons ,然后点击 `New repository secret`,然后自定义密钥名称,然后填入上面的 `id_rsa`,然后即可生成成功 | ||
|
||
![image-20231014151411628](C:\Users\86150\AppData\Roaming\Typora\typora-user-images\image-20231014151411628.png) | ||
|
||
|
@@ -55,9 +63,7 @@ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys | |
|
||
### 工作流配置 | ||
|
||
首先我们需要配置服务器 IP 环境变量,创建 `IP` 变量,填写自己服务器的域名或是 IP,当然不创建使用明文也是可以的 | ||
|
||
![image-20231014154149241](https://cdn.jsdelivr.net/gh/Returntmp/blog-image@main/blog/202310141541324.png) | ||
然后我们按照同样的方法创建 `IP` 变量,填写自己服务器的域名或是 IP,当然不创建后面直接使用明文也是可以的 | ||
|
||
我们需要在博客项目的根目录下创建`.github/workflows`文件夹,创建文件`deploy.yml`,填写如下内容 | ||
|
||
|
@@ -106,6 +112,8 @@ jobs: | |
|
||
其中 `/root/app` 是我们需要部署博客的目标文件夹,需要提前创建 | ||
|
||
> 注:其中 action 详细配置可以自行查找对应仓库,例如 actions/checkout action ,仓库位于:https://github.com/actions/checkout | ||
|
||
|
||
### 配置 Nginx | ||
|
@@ -127,10 +135,24 @@ systemctl restart nginx | |
|
||
|
||
|
||
### 文件同步 | ||
|
||
我们需要配置文件同步,实现本地主机和远程主机上的文件同步,在云服务器执行如下命令安装 `rsync` | ||
|
||
```bash | ||
yum install rsync -y | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
### 工作流推送 | ||
|
||
最后推送本地的 `deploy.yml` 到远程 GitHub 源码库,查看最后 Actions 执行效果即可 | ||
|
||
![image-20231014170229221](https://cdn.jsdelivr.net/gh/Returntmp/blog-image@main/blog/202310141702704.png) | ||
|
||
|
||
|
||
## 参考链接 | ||
|