From 05e907702c9e18a7ecd040cc6a970aac313b1fd0 Mon Sep 17 00:00:00 2001 From: Roy Nilsson Date: Wed, 20 Dec 2023 10:44:38 +0100 Subject: [PATCH] Add basic GitHub Action --- Dockerfile | 10 ++++++++++ README.md | 29 +++++++++++++++++++++++++++++ action.yml | 17 +++++++++++++++++ deploy.sh | 16 ++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 action.yml create mode 100755 deploy.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..219d67c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:3.19 + +RUN apk add --no-cache --upgrade \ + openssh \ + rsync + +ADD deploy.sh / +RUN chmod +x /deploy.sh + +ENTRYPOINT ["/deploy.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..6892553 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# rsync deploy action + +Example usage: + +```yaml +name: 'Build and deploy' +run-name: 'Build and Deploy' + +on: + push: + branches: + - main + +jobs: + deploy-blog: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout + - name: Deploy files + uses: https://git.roy.lv/actions/rsync-deploy-action # Full URL is Gitea Actions specific + env: + SSH_KEY: ${{ secrets.SSH_KEY }} + RSYNC_SOURCE: ./* + RSYNC_DESTINATION: /path/to/rsync/to/ + RSYNC_USERHOST: user@example.host + with: + rsync-arguments: --archive --compress --delete --verbose +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..bbe941f --- /dev/null +++ b/action.yml @@ -0,0 +1,17 @@ +name: Deploy to server with rsync +description: An action to build and deploy to a server with rsync over SSH +branding: + icon: upload-cloud + color: blue + +inputs: + rsync-arguments: + description: Rsync arguments + required: false + default: --archive --compress --delete --verbose + +runs: + using: docker + image: Dockerfile + args: + - ${{ inputs.rsync-arguments }} diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..e162fef --- /dev/null +++ b/deploy.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -euo pipefail + +options="$1" +SSH_HOME="${HOME}/.ssh" +SSH_KEYPATH="${SSH_HOME}/deploy_key" + +mkdir -p "$SSH_HOME" +echo "$SSH_KEY" > "$SSH_KEYPATH" +chmod 600 "$SSH_KEYPATH" + +echo "Deploying..." +rsync $options \ + -e "ssh -i $SSH_KEYPATH -o StrictHostKeyChecking=no" \ + "$RSYNC_SOURCE" "$RSYNC_USERHOST":"$RSYNC_DESTINATION"