其他分享
首页 > 其他分享> > 提交即部署 - Github Action 自动化部署

提交即部署 - Github Action 自动化部署

作者:互联网

文章目录

实现效果

环境

本地环境:Mac OS
服务器环境:Ubuntu Server

步骤

生成公私钥

ssh-keygen -m PEM -t rsa -b 4096
Enter file in which to save the key (/Users/zero/.ssh/id_rsa):deploy_key

Github 配置

Image.png

cat ~/.ssh/deploy_key

Image.png

Image.png

服务器配置

cat ~/.ssh/deploy_key.pub
vim ~/.ssh/authorized_keys

代码配置

name: Depoly Action

on:
  push:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2

    - name: ssh deploy
      uses: easingthemes/ssh-deploy@v2.1.5
      with:
        REMOTE_HOST: ${{ secrets.HOST }}
        REMOTE_USER: ${{ secrets.USER }}
        SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_KEY }}
        SOURCE: "[部署内容路径(以项目目录为根目录)]"
        TARGET: "[服务器部署位置的绝对路径]"

    - name: Prepare For Django
      uses: webfactory/ssh-agent@v0.5.0
      with:
        ssh-private-key: ${{ secrets.DEPLOY_KEY }}

    - name: Restart Django
      run: ssh ${{ secrets.USER }}@${{ secrets.HOST }} "kill -HUP [Django uwsgi 进程号]"

查看日志

Image.png

参考资料

标签:Github,deploy,部署,Django,Secrets,github,ssh,Action,服务器
来源: https://blog.csdn.net/y_silence_/article/details/121712073