ssh-deploy/README.md

99 lines
2.3 KiB
Markdown
Raw Normal View History

2019-09-25 21:24:25 +00:00
# ssh deployments
2019-02-09 13:17:45 +00:00
2019-10-02 22:51:32 +00:00
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.
2019-02-09 13:17:45 +00:00
2019-09-25 21:24:25 +00:00
This action would usually follow a build/test action which leaves deployable code in `GITHUB_WORKSPACE`, eg `dist`;
2019-02-09 13:17:45 +00:00
2019-09-25 21:52:29 +00:00
# Configuration
2019-02-09 13:17:45 +00:00
2019-09-25 21:52:29 +00:00
Pass configuration with `env` vars
2019-02-09 13:17:45 +00:00
2019-10-02 22:17:19 +00:00
1. `SSH_PRIVATE_KEY` [required]
2019-10-02 22:51:32 +00:00
2020-04-11 14:33:22 +00:00
This should be the 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.
The keys should be generated using the PEM format. You can us this command
```
ssh-keygen -m PEM -t rsa -b 4096
```
2019-02-09 13:17:45 +00:00
2. `REMOTE_HOST` [required]
2019-10-02 22:51:32 +00:00
eg: mydomain.com
3. `REMOTE_USER` [required]
2019-10-02 22:17:19 +00:00
2019-10-02 22:51:32 +00:00
eg: myusername
3. `REMOTE_PORT` (optional, default '22')
eg: '59184'
2019-10-02 22:51:32 +00:00
2. `ARGS` (optional, default '-rltgoDzvO')
2019-09-25 21:52:29 +00:00
For any initial/required rsync flags, eg: `-avzr --delete`
2019-02-09 13:17:45 +00:00
2019-10-02 22:17:19 +00:00
3. `SOURCE` (optional, default '')
2019-10-02 22:51:32 +00:00
2019-10-02 22:17:19 +00:00
The source directory, path relative to `$GITHUB_WORKSPACE` root, eg: `dist/`
2019-02-09 13:17:45 +00:00
2019-10-02 22:17:19 +00:00
4. `TARGET` (optional, default '/home/REMOTE_USER/')
2019-10-02 22:51:32 +00:00
2019-10-02 22:17:19 +00:00
The target directory
2019-02-09 13:17:45 +00:00
2019-10-02 22:51:32 +00:00
# Usage
2019-09-25 21:24:25 +00:00
2019-09-25 21:52:29 +00:00
```
2019-10-02 22:17:19 +00:00
- name: Deploy to Staging server
uses: easingthemes/ssh-deploy@v2.0.7
2019-10-02 22:17:19 +00:00
env:
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
2019-10-02 22:51:32 +00:00
ARGS: "-rltgoDzvO"
2019-10-02 22:17:19 +00:00
SOURCE: "dist/"
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
TARGET: ${{ secrets.REMOTE_TARGET }}
2019-09-25 21:52:29 +00:00
```
2019-02-09 13:17:45 +00:00
2019-10-02 22:17:19 +00:00
# Example usage in workflow
2019-02-09 13:17:45 +00:00
```
2019-09-25 21:52:29 +00:00
name: Node CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
2019-10-02 22:17:19 +00:00
- name: Install Node.js
2019-09-25 21:52:29 +00:00
uses: actions/setup-node@v1
with:
2019-10-02 22:17:19 +00:00
node-version: '10.x'
2019-09-25 21:52:29 +00:00
- name: Install npm dependencies
2019-10-02 22:17:19 +00:00
run: npm install
2019-09-25 21:52:29 +00:00
- name: Run build task
2019-10-02 22:17:19 +00:00
run: npm run build --if-present
- name: Deploy to Server
uses: easingthemes/ssh-deploy@v2.0.7
2019-10-02 22:17:19 +00:00
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 }}
2019-02-09 13:17:45 +00:00
```
## Disclaimer
2020-04-11 14:30:28 +00:00
Check your keys. Check your deployment paths. And use at your own risk.