Go to file
Dragan Filipovic 2cd8a820e2 feat: Add SSH remote script support - before and after rsync
fix: remove _unsafe _dirname

feat: add sshCmdArgs option

fix: Add promise instead of callback

fix: improve logs

fix: Add simple command exists instead of a plugin

fix: add non interactive install

feat: add onStderr and onStdout logs

fix: Improve reject messages

feat: Add RSYNC_STDOUT env variable

feat: Update emojis

fix: update workflow actions
2023-01-02 21:13:46 +01:00
.github/workflows feat: Add SSH remote script support - before and after rsync 2023-01-02 21:13:46 +01:00
dist Feature/ssh cmd (#94) 2023-01-02 21:06:33 +01:00
docs chore(release): 3.1.1 [skip ci] 2023-01-02 20:09:00 +00:00
src Feature/ssh cmd (#94) 2023-01-02 21:06:33 +01:00
test permissions fix 2022-12-31 10:20:28 +01:00
.editorconfig [tests] add editorconfig and eslint 2020-04-11 16:26:19 +02:00
.eslintrc.js Feature/ssh cmd (#94) 2023-01-02 21:06:33 +01:00
.gitignore start e2e 2022-12-29 15:46:56 +01:00
.releaserc fix: add assets to semantic-release git 2021-05-28 01:23:17 +02:00
LICENSE [init]: update Licence 2019-09-25 23:54:12 +02:00
README.md Feature/ssh cmd (#94) 2023-01-02 21:06:33 +01:00
action.yml Feature/ssh cmd (#94) 2023-01-02 21:06:33 +01:00
package-lock.json Feature/ssh cmd (#94) 2023-01-02 21:06:33 +01:00
package.json chore(release): 3.1.1 [skip ci] 2023-01-02 20:09:00 +00:00

README.md

ssh deployments

Deploy code with rsync over ssh.

Execute remote scripts before or after rsync

NodeJS version is more than a minute faster than simple Docker version.

This GitHub Action deploys specific directory from GITHUB_WORKSPACE to a folder on a server via rsync over ssh, using NodeJS.

This action would usually follow a build/test action which leaves deployable code in GITHUB_WORKSPACE, eg dist;

In addition to rsync, this action provides scripts execution on remote host before and/or after rsync.

Configuration

Pass configuration with env vars

1. SSH_PRIVATE_KEY [required]

Private key part of an SSH key pair. The public key part should be added to the authorized_keys file on the server that receives the deployment.

More info for SSH keys: https://www.ssh.com/ssh/public-key-authentication

The keys should be generated using the PEM format. You can use this command

ssh-keygen -m PEM -t rsa -b 4096
2. REMOTE_HOST [required]

eg: mydomain.com

3. REMOTE_USER [required]

eg: myusername

4. REMOTE_PORT (optional, default '22')

eg: '59184'

5. ARGS (optional, default '-rltgoDzvO')

For any initial/required rsync flags, eg: -avzr --delete

6. SOURCE (optional, default '')

The source directory, path relative to $GITHUB_WORKSPACE root, eg: dist/

7. TARGET (optional, default '/home/REMOTE_USER/')

The target directory

8. EXCLUDE (optional, default '')

path to exclude separated by ,, ie: /dist/, /node_modules/

9. SCRIPT_BEFORE (optional, default '')

Script to run on host machine before rsync. Single line or multiline commands. Execution is preformed by storing commands in .sh file and executing it via .bash over ssh

10. SCRIPT_AFTER (optional, default '')

Script to run on host machine after rsync. Rsync output is stored in $RSYNC_STDOUT env variable.

Usage

Use the latest version from Marketplace,eg: ssh-deploy@v2 or use the latest version from a branch, eg: ssh-deploy@main

  - name: Deploy to Staging server
    uses: easingthemes/ssh-deploy@main
    env:
      SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
      ARGS: "-rltgoDzvO"
      SOURCE: "dist/"
      REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
      REMOTE_USER: ${{ secrets.REMOTE_USER }}
      TARGET: ${{ secrets.REMOTE_TARGET }}
      EXCLUDE: "/dist/, /node_modules/"
      SCRIPT_BEFORE: |
        whoami
        ls -al
      SCRIPT_AFTER: |
        whoami
        ls -al
        echo $RSYNC_STDOUT

Example usage in workflow

name: Node CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Install Node.js
      uses: actions/setup-node@v1
      with:
        node-version: '10.x'
    - name: Install npm dependencies
      run: npm install
    - name: Run build task
      run: npm run build --if-present
    - name: Deploy to Server
      uses: easingthemes/ssh-deploy@main
      env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
          ARGS: "-rltgoDzvO --delete"
          SOURCE: "dist/"
          REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
          REMOTE_USER: ${{ secrets.REMOTE_USER }}
          TARGET: ${{ secrets.REMOTE_TARGET }}
          EXCLUDE: "/dist/, /node_modules/"

Issues

This is a GitHub Action wrapping rsync via ssh. Only issues with action functionality can be fixed here.

Almost 95% of the issues are related to wrong SSH connection or rsync params and permissions. These issues are not related to the action itself.

  • Check manually your ssh connection from your client before opening a bug report.
  • Check rsync params for your use-case. Default params are not going to be enough wor everyone, it highly depends on your setup.
  • Check manually your rsync command from your client before opening a bug report.

I've added e2e test for this action. Real example is executed on every PR merge to main. Check actions tab for example.

More info for SSH keys: https://www.ssh.com/ssh/public-key-authentication

Disclaimer

Check your keys. Check your deployment paths. And use at your own risk.