https://github.com/up9cloud/action-rsync
Github action - rsync
https://github.com/up9cloud/action-rsync
Last synced: 11 months ago
JSON representation
Github action - rsync
- Host: GitHub
- URL: https://github.com/up9cloud/action-rsync
- Owner: up9cloud
- License: mit
- Created: 2020-07-11T03:13:15.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-25T06:28:04.000Z (about 1 year ago)
- Last Synced: 2025-06-09T12:16:13.329Z (about 1 year ago)
- Language: Shell
- Homepage:
- Size: 44.9 KB
- Stars: 36
- Watchers: 1
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# action-rsync  [](https://hub.docker.com/repository/docker/sstc/action-rsync)
- Small: Alpine based image with pre-installed rsync, see [sstc/rsync](https://hub.docker.com/r/sstc/rsync).
- Hooks: Basic pre and post scripts support.
- Pure 😊: No github specific inputs, outputs, it can be used on other platform!
## Quick start
> Github Action (`.github/workflows/*.yml`)
```yml
on: [push]
jobs:
rsync:
runs-on: ubuntu-latest
steps:
# Must checkout first, otherwise it would show empty folder, see https://github.com/actions/checkout
- uses: actions/checkout@v4
# Modify `master` to a valid version, see https://github.com/marketplace/actions/action-rsync
- uses: up9cloud/action-rsync@master
env:
HOST: target.example.com
KEY: ${{secrets.DEPLOY_SSH_KEY}}
TARGET: /app/
```
> Drone CI (`.drone.yml`)
```yml
kind: pipeline
type: docker
name: default
steps:
- name: deploy
when:
branch:
- master
event: [push]
image: sstc/action-rsync
settings:
# lowercase attributes, see https://readme.drone.io/plugins/overview/#plugin-inputs
key:
from_secret: deploy_ssh_key
host: target.example.com
target: /app/
```
> Docker Container
```bash
docker run -it --rm \
-v $(pwd):/app \
-w /app \
-e HOST="target.example.com" \
-e KEY="$(cat ~/.ssh/id_rsa)"
-e TARGET="/app/" \
sstc/action-rsync
```
## ENVs
||Default Value|Description|
|---|---|---|
|**`HOST`**||Remote server ssh hostname or ip address
**Required if** **`MODE`** is `push` or `pull`|
|**`REMOTE_HOSTS`**||Multiple remote hosts
Could be comma separate items style, e.q. 1.2.3.4,8.8.4.4
or one line one item style, e.q. 8.8.8.8\n111.111.111.111
It will execute pre & post scripts on every host
**Required if** **`MODE`** is `push` or `pull`|
|**`USER`**|`root`|Remote server ssh user
It's useless when **`MODE`** is `local`|
|**`PORT`**|`22`|Remote server ssh port
It's useless when **`MODE`** is `local`|
|**`KEY`**||The ssh private key
**Required if** **`PASSWORD`** is not provided and **`MODE`** is `push` or `pull`|
|**`PASSWORD`**||The ssh password
**Required if** **`KEY`** is not provided and **`MODE`** is `push` or `pull`|
|**`SOURCE`**|`./`|Source path for folder or file|
|**`TARGET`**||Target path for folder or file
**Required**|
|**`MODE`**|`push`|Must be one of:
`push`: local (SOURCE) to remote (TARGET)
`pull`: remote (SOURCE) to local (TARGET)
`local`: local (SOURCE) to local (TARGET)|
|**`VERBOSE`**|`false`|Set it to `true` when you need some tips|
|**`ARGS`**|`-avz --delete --exclude=/.git/ --exclude=/.github/`|Arguments for rsync|
|**`ARGS_MORE`**||More rsync arguments. Append more args for rsync, it means the final rsync arguments will be: `$ARGS $ARGS_MORE`.
For example, if you set ARGS_MORE to be `--no-o --no-g` and keep ARGS as default, then the final args will be: `-avz --delete --exclude=/.git/ --exclude=/.github/ --no-o --no-g`|
|**`SSH_ARGS`**|`-p 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet`|Arguments for ssh. The value of `-p` is dynamic, depends on what value you set for `PORT`, but what if you set SSH_ARGS, the PORT would be ignored|
|**`RUN_SCRIPT_ON`**|`target`|Must be one of:
`target`: When **`MODE`** is `push`, run pre and post scripts on remote (because the target is on remote). When **`MODE`** is others, run on local.
`source`: When **`MODE`** is `push`, run pre and post scripts on local. When **`MODE`** is others, run on remote.
`local`: Always run scripts on local.
`remote`: Always run scripts on remote.|
|**`PRE_SCRIPT`**||The script runs before rsync.
The target system of RUN_SCRIPT_ON must support `mktemp` command|
|**`POST_SCRIPT`**||The script runs after rsync.
The target system of RUN_SCRIPT_ON must support `mktemp` command|
### Example
```yml
on: [push]
jobs:
rsync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy to my ❤️
uses: up9cloud/action-rsync@master
env:
HOST: example.com
KEY: ${{secrets.DEPLOY_SSH_KEY}}
# PASSWORD: ${{secrets.DEPLOY_SSH_PASSWORD}} # it's less secure, using KEY instead
TARGET: /app/hello-service/
VERBOSE: true
USER: ubuntu
# PORT: 2222 # no need to set this, because of $SSH_ARGS
ARGS: -az --exclude=/.git/
SSH_ARGS: '-p 2222 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
SOURCE: ./public/
PRE_SCRIPT: |
echo start at:
date -u
POST_SCRIPT: "echo done at: && date -u"
```
See also: [.github/workflows/main.yml](https://github.com/up9cloud/action-rsync/blob/master/.github/workflows/main.yml)
## TODO
- [ ] test ssh connection before executing
- [ ] benchmark, compare with other actions based on js
- [ ] lock the version of docker image
- [ ] let variable names more meaningful, e.q. HOST to REMOTE_HOST