前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用GitHub Actions 来进行项目远程服务器部署

使用GitHub Actions 来进行项目远程服务器部署

作者头像
拿我格子衫来
发布2023-08-24 10:55:22
4130
发布2023-08-24 10:55:22
举报
文章被收录于专栏:TopFE

由于项目源码是托管在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:用户名

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
代码语言:javascript
复制
# 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

需要做的事,配置三个密钥,检查路径和重启指令。调试。

运行完成示意图

在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-07-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档