GitHub Action for deploying code via rsync over ssh. (with NodeJS)
Go to file
github-actions 74b3a2aba4 chore(release): 2.2.0 [skip ci]
# [2.2.0](https://github.com/easingthemes/ssh-deploy/compare/v2.1.7...v2.2.0) (2021-05-27)

### Bug Fixes

* only=prod package json ([95f4dc8](95f4dc8069))
* replace i with ci ([50d1f57](50d1f576f9))
* update ncc ([20a0cae](20a0cae1ae))
* update plugins ([b2adc00](b2adc00c92))
* update plugins ([a50a999](a50a999528))

### Features

* add semantic-release-action ([ac3c9b5](ac3c9b51d5))
2021-05-27 21:00:10 +00:00
.github/workflows feat: add semantic-release-action 2021-05-27 22:56:27 +02:00
dist fix: update ncc 2021-05-27 22:04:06 +02:00
docs chore(release): 2.2.0 [skip ci] 2021-05-27 21:00:10 +00:00
src RSYNC use excludeFirst instead of exclude 2021-03-24 18:48:12 +01:00
.editorconfig [tests] add editorconfig and eslint 2020-04-11 16:26:19 +02:00
.eslintrc.js [tests] add editorconfig and eslint 2020-04-11 16:26:19 +02:00
.gitignore Merge branch 'master' into feature/SSH-DEPLOY-refactor 2020-04-11 16:54:21 +02:00
.releaserc feat: add semantic-release-action 2021-05-27 22:56:27 +02:00
action.yml Update action.yml 2021-03-12 07:26:41 +01:00
LICENSE [init]: update Licence 2019-09-25 23:54:12 +02:00
package-lock.json fix: only=prod package json 2021-05-27 22:03:15 +02:00
package.json feat: add semantic-release-action 2021-05-27 22:56:27 +02:00
README.md Added exclude parameter 2021-03-12 07:42:12 +01:00

ssh deployments

Deploy code with rsync over ssh, using NodeJS.

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;

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/

Usage

!!! Please use latest version, Readme file is just an example, eg: ssh-deploy@v2.1.5

  - name: Deploy to Staging server
    uses: easingthemes/ssh-deploy@v2.1.5
    env:
      SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
      ARGS: "-rltgoDzvO"
      SOURCE: "dist/"
      REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
      REMOTE_USER: ${{ secrets.REMOTE_USER }}
      TARGET: ${{ secrets.REMOTE_TARGET }}
      EXCLUDE: "/dist/, /node_modules/"

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@v2.1.5
      env:
          SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
          ARGS: "-rltgoDzvO --delete"
          SOURCE: "dist/"
          REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
          REMOTE_USER: ${{ secrets.REMOTE_USER }}
          TARGET: ${{ secrets.REMOTE_TARGET }}
          EXCLUDE: "/dist/, /node_modules/"

Disclaimer

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