由于项目源码是托管在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
:远程主机ipDC_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-nodejs
name: 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/dist
last_ssh: |
echo $LASTSSH
nginx -t
nginx -s reload
需要做的事,配置三个密钥,检查路径和重启指令。调试。文章来源:https://www.toymoban.com/news/detail-633051.html
运行完成示意图
文章来源地址https://www.toymoban.com/news/detail-633051.html
到了这里,关于使用GitHub Actions 来进行项目远程服务器部署的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!