由于项目源码是托管在github的,而部署是放在远程服务器上,并且使用nginx部署。
现在的部署流程时,需要更新时,在本地切换到master分支,执行构建操作,拿到构建出的dist目录,将其上传到远程服务的某个nginx目录,重启nginx服务。 基于以上,使用GitHub Actions做CI/CD流程。
推送代码到master分支,或者master分别合并了pr时,执行流水线.
流水线文件存放在
.github/workflows/deploy.yml
基于node16.x版本,全局安装pnpm,并安装项目依赖,并进行构建。
构建完成后,使用Actions
ssh-scp-ssh-pipelines
https://github.com/marketplace/actions/ssh-scp-ssh-pipelines
使用该插需要配置三个密钥
DC_HOST
:远程主机ip
DC_PASS
:密码
DC_USER
:用户名
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejsname: ssh deploy
on:push:branches:["master"]pull_request:branches:["master"]jobs:build:runs-on: ubuntu-latest
steps:-uses: actions/checkout@v3
-name: Use Node.js Build
uses: actions/setup-node@v3
with:node-version: 16.16.0
cache:'npm'-run: npm i -g pnpm
-run: pnpm install
-run: pnpm run build
-run: ls -l
-name: scp ssh pipelines
uses: cross-the-world/ssh-scp-ssh-pipelines@latest
env:LASTSSH:"Doing something after copying"with:host: ${{ secrets.DC_HOST }}user: ${{ secrets.DC_USER }}pass: ${{ secrets.DC_PASS }}scp:|
./dist/* => /usr/share/nginx/visual-editor/distlast_ssh:|
echo $LASTSSH
nginx -t
nginx -s reload
需要做的事,配置三个密钥,检查路径和重启指令。调试。
运行完成示意图
版权归原作者 拿我格子衫来 所有, 如有侵权,请联系我们删除。