Composite Forgejo/GitHub Action that deploys files to a remote server over SSH using rsync. Supports configurable host, port, username, key, source directory, target path, and extra rsync args.
68 lines
1.5 KiB
Markdown
68 lines
1.5 KiB
Markdown
# SSH Deploy Action
|
|
|
|
A Forgejo/GitHub Action to deploy files to a remote server via SSH and rsync.
|
|
|
|
## Inputs
|
|
|
|
| Input | Description | Required | Default |
|
|
|-------|-------------|----------|---------|
|
|
| `host` | SSH server address | Yes | |
|
|
| `port` | SSH port | No | `22` |
|
|
| `username` | SSH login user | Yes | |
|
|
| `key` | Private SSH key content | Yes | |
|
|
| `source` | Local directory to deploy | No | `.` |
|
|
| `target` | Remote path on the server | Yes | |
|
|
| `args` | Extra rsync flags (e.g. `--delete`) | No | |
|
|
|
|
## Usage
|
|
|
|
```yaml
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Build
|
|
run: npm run build
|
|
|
|
- name: Deploy
|
|
uses: fmartingr/ssh-deploy-action@v1
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USER }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
source: dist/
|
|
target: ${{ secrets.SSH_PATH }}
|
|
```
|
|
|
|
### With extra rsync flags
|
|
|
|
```yaml
|
|
- name: Deploy
|
|
uses: fmartingr/ssh-deploy-action@v1
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USER }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
source: dist/
|
|
target: ${{ secrets.SSH_PATH }}
|
|
args: --delete --exclude='.env'
|
|
```
|
|
|
|
## SSH Key Setup
|
|
|
|
1. Generate a dedicated deploy key:
|
|
|
|
```bash
|
|
ssh-keygen -t ed25519 -C "deploy" -f deploy_key -N ""
|
|
```
|
|
|
|
2. Add the **public** key to the server:
|
|
|
|
```bash
|
|
cat deploy_key.pub >> ~/.ssh/authorized_keys
|
|
```
|
|
|
|
3. Add the **private** key content as a secret (e.g. `SSH_PRIVATE_KEY`) in your Forgejo/GitHub repository settings.
|
|
|
|
## License
|
|
|
|
MIT
|