Transfer files using rsync

This commit is contained in:
L3D 2023-05-11 22:41:39 +02:00
parent da7be50183
commit 0ae435d08b
No known key found for this signature in database
GPG key ID: AD65B920933B4B20
3 changed files with 99 additions and 0 deletions

23
Dockerfile Normal file
View file

@ -0,0 +1,23 @@
# hadolint ignore=DL3007
FROM debian:stable
LABEL "maintainer"="L3D <l3d@c3woc.de>"
# 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"]

41
action.yml Normal file
View file

@ -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 <l3d@c3woc.de>
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'

35
rsync-docker.sh Executable file
View file

@ -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