aizu's Knowledge Base
    • Go to: aizu.my Homepage
    • Recent
    • Tags
    • Register
    • Login

    Github Action

    Ref
    1
    1
    76
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      aizu
      last edited by aizu

      On Linux server

      Run:

      cd .ssh
      ssh-keygen -t ed25519 -a 200 -C "[email protected]"
      cat id_ed25519.pub >> authorized_keys
      

      Now, copy the content of .ssh/ed25519 file into GitHub Action secret variable. (Repo > Settings > Secret & Variables > Actions > New Repository Secret)

      The copied content of .ssh/ed25519 file has to start from:

      -----BEGIN PRIVATE KEY-----
      ...... key ......
      -----END PRIVATE KEY-----
      

      Suggestion name : REMOTE_PRIVATE_KEY


      Create 2 more keys & value for;

      • REMOTE_HOST (example: 172.0.0.1)
      • REMOTE_USER (example: root)

      So, you will have 3 secrets.


      Now, create a folder & YAML file in the repo.

      File: .github/workflows/ssh-remote-execution.yml

      name: Remote SSH Command
      
      on:
        push:
          branches:
            - master
      
      jobs:
        execute-remote-script:
          runs-on: ubuntu-latest
          steps:
          - name: Execute script on remote server
            uses: appleboy/ssh-action@master
            with:
              host: ${{ secrets.REMOTE_HOST }}
              username: ${{ secrets.REMOTE_USER }}
              key: ${{ secrets.REMOTE_PRIVATE_KEY }}
              script: |
                cd /var/www/app_location/www/source
                git reset --hard
                git pull
                npm i
                npm run build
                pm2 restart app_name
      

      Then, commit to branch master.

      1 Reply Last reply Reply Quote 0
      • A aizu moved this topic from Linux on
      • First post
        Last post