Add basic GitHub Action

This commit is contained in:
2023-12-20 10:44:38 +01:00
commit 05e907702c
4 changed files with 72 additions and 0 deletions

10
Dockerfile Normal file
View File

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

29
README.md Normal file
View File

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

17
action.yml Normal file
View File

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

16
deploy.sh Executable file
View File

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