From 4a197eed1dba1d4d315c372e808e79563778e7fc Mon Sep 17 00:00:00 2001 From: lubiana Date: Thu, 12 Dec 2024 02:16:30 +0100 Subject: [PATCH] init --- Dockerfile | 10 ++++++++++ README.md | 37 +++++++++++++++++++++++++++++++++++++ action.yml | 29 +++++++++++++++++++++++++++++ entrypoint.sh | 15 +++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 action.yml create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2bf8a4a --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..85d1846 --- /dev/null +++ b/README.md @@ -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 }} +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..747438d --- /dev/null +++ b/action.yml @@ -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' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..1f3090f --- /dev/null +++ b/entrypoint.sh @@ -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