From 0ae435d08bc6d93ef93e26da6f3248b736dbc4cf Mon Sep 17 00:00:00 2001 From: L3D Date: Thu, 11 May 2023 22:41:39 +0200 Subject: [PATCH] Transfer files using rsync --- Dockerfile | 23 +++++++++++++++++++++++ action.yml | 41 +++++++++++++++++++++++++++++++++++++++++ rsync-docker.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 Dockerfile create mode 100644 action.yml create mode 100755 rsync-docker.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..96f6109 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# hadolint ignore=DL3007 +FROM debian:stable + +LABEL "maintainer"="L3D " + +# hadolint ignore=DL3008,DL3013 +RUN apt-get update -y && apt-get install -y --no-install-recommends \ + apt-utils \ + openssh-client \ + software-properties-common \ + build-essential \ + locales \ + rsync \ + keychain \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + + +# Fix potential UTF-8 errors +RUN locale-gen en_US.UTF-8 + +COPY rsync-docker.sh /rsync-docker.sh +ENTRYPOINT ["/rsync-docker.sh"] diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..923b44b --- /dev/null +++ b/action.yml @@ -0,0 +1,41 @@ +--- +name: Deploy Files to Webserver using rsync +description: Deploy files using rsync and ssh with the debian:stable docker container +author: L3D + +inputs: + source: + description: | + Which file, files or folders should be transfered? + Enter the filepath. + required: true + destionation: + description: | + Where does the files go? + Destination filepath on webserver. + required: true + host: + description: | + Destination Server. + IP or FQDN please. + required: true + user: + description: | + Destination User + required: true + sshkey: + description: | + SSH Private Key (ED25519) + required: true +runs: + using: docker + image: Dockerfile + env: + SOURCE: ${{ inputs.source }} + DESTINATION: ${{ inputs.destionation }} + HOST: ${{ inputs.host }} + USER: ${{ inputs.user }} + SSHKEY: ${{ inputs.sshkey }} +branding: + icon: 'upload-cloud' + color: 'yellow' diff --git a/rsync-docker.sh b/rsync-docker.sh new file mode 100755 index 0000000..91c67ed --- /dev/null +++ b/rsync-docker.sh @@ -0,0 +1,35 @@ +#! /usr/bin/env bash + +set -Eeuo pipefail +set -x + +# Generates client. +# env: +# SOURCE: ${{ inputs.source }} +# DESTINATION: ${{ inputs.destionation }} +# HOST: ${{ inputs.host }} +# USER: ${{ inputs.user }} +# SSHKEY: ${{ inputs.sshkey }} + +rsync::ssh() { + : "${SSHKEY?Please provide a SSH Private Key (ED25519).}" + : "${GITHUB_WORKSPACE?GITHUB_WORKSPACE has to be set. Did you use the actions/checkout action?}" + pushd "${GITHUB_WORKSPACE}" + mkdir ~/.ssh + chmod 700 ~/.ssh + echo "${SSHKEY}" | tee ~/.ssh/id_ed25519 > /dev/null + chmod 400 ~/.ssh/id_ed25519 + eval $(keychain --eval --quiet id_ed25519) +} + +rsync::transfer() { + : "${GITHUB_WORKSPACE?GITHUB_WORKSPACE has to be set. Did you use the actions/checkout action?}" + : "${SOURCE?Define File to copy.}" + : "${DESTINATION?Define File destination.}" + : "${HOSTS?Destination Server}" + : "${USER?Destination User}" + pushd "${GITHUB_WORKSPACE}" + rsync --progress ${SOURCE} ${USER}@${HOSTS}:${DESTINATION} +} + +rsync::ssh