This commit is contained in:
Jonas 2024-12-12 02:16:30 +01:00
commit 4a197eed1d
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
4 changed files with 91 additions and 0 deletions

10
Dockerfile Normal file
View file

@ -0,0 +1,10 @@
FROM alpine:latest
RUN apk add --no-cache \
openssh \
rsync
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoints.sh
ENTRYPOINT ["/entrypoint.sh"]

37
README.md Normal file
View file

@ -0,0 +1,37 @@
# Simple rsync Action
this actions uses rsync to syncronize a folder via ssh to another server
## Parameters:
- `rsync_parameters`* - For the required rsync parameters, example: `-avz --delete`
- `path` - local path, if not specified the current workdir is used
- `remote_path`* - the path on the remote server
- `remote_user`* - the username to be used for ssh
- `remote_host`* - the server to deploy to
- `remote_key`* - the ssh key to use for authentication
## Example Usage:
```yml
name: DEPLOY
on:
push:
branches:
- master
jobs:
deploy:
runs-on: docker
steps:
- uses: actions/checkout@v4
- name: rsync
uses: https://git.hannover.ccc.de/c3h/actions-rsync-deployment@v1
with:
switches: -avz --delete
path: public/
remote_path: /home/web/public
remote_host: example.com
remote_user: i_use_arch_btw
remote_key: ${{ secrets.SSH_PRIVATE_KEY }}
```

29
action.yml Normal file
View file

@ -0,0 +1,29 @@
name: 'Rsync Deployment Action'
despriction: 'Forgejo Action for deploying code with rsync over ssh'
inputs:
rsync_parameters:
description: 'parameters to be passed to the rsync command'
required: true
path:
description: 'the local path'
required: false
default: ''
remote_path:
description: 'the remote path'
required: true
remote_host:
description: 'the remote host'
required: true
remote_port:
description: 'the remote port'
required: false
default: 22
remote_user:
description: 'The remote user'
required: true
remote_key:
description: 'The remote key'
required: true
runs:
using: 'docker'
image: 'Dockerfile'

15
entrypoint.sh Normal file
View file

@ -0,0 +1,15 @@
mkdir -p ~/.ssh/
# Print the SSH key, replacing newline characters with actual new lines
echo "$INPUT_REMOTE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
# Set appropriate permissions for the SSH key
chmod 600 ~/.ssh/id_rsa
# Add the remote host's key to the known_hosts file to avoid authenticity confirmation
ssh-keyscan -H $INPUT_REMOTE_HOST >> ~/.ssh/known_hosts
# SCP files to the remote host
rsync ${INPUT_RSYNC_PARAMETERS} public/ ${INPUT_REMOTE_USER}@${INPUT_REMOTE_HOST}:${INPUT_REMOTE_PATH}
exit 0