diff --git a/Dockerfile b/Dockerfile index 5f6e8e2..004b90b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,5 +6,4 @@ RUN chmod +x /entrypoint.sh && \ apk update && \ apk add git openssh rsync - ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/LICENSE b/LICENSE index a089eed..c7bbab4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Sebastian Rueda +Copyright (c) 2024 temper.tv Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index f7b53a4..7c99c73 100644 --- a/README.md +++ b/README.md @@ -1,78 +1,42 @@ -# SCP ACTION +# Rsync Action ***By `temper`*** -Original by `SRUEDA99` however I've made this work for hugo projects +Based off `SRUEDA99` scp-action due to the simplicity of that project ## Overview -This action to copy the files from your repository to a remote server using **SCP** (Secure Copy Protocol). -## How to use it -You must give: -- The `host` which is the public address or the public DNS of the destination server. -- The `username` that will be used in the remote server. -- The `destination` folder, where the content will be copied. -- The `password` for the user or the private `key` in case the connection is based on SSH keys. +This Github action uses Rsync to copy files over ssh + +## Input Parameters + +Required Parameters + +* `host` IP/Hostname of target. +* `username` on the target IP/host that is used to copy files to. +* `source` - Source file or folder to copy +* `destination` - the folder where the content will be copied. +* `key` - the private key used to secure the connection to the target. + +Optional Parameters: -Optional: -- The `origin` folder is set by default as __"./*"__ but you can also specify it. - The `port` is set as **22** by default, you can also specify another one. -- The `passphrase` if necessary. -**IMPORTANT** -``` -Use Github secrets to give these parameters. -``` +## Secrets + +It is recommended to pass all sensitive values through `secrets` ## Examples -**With password** -``` -name: copy using password -uses: srueda99/scp-action@v12 -with: - port: 22 - host: ${{ secrets.SERVER_ADDRESS }} - destination: "/home/${{ secrets.SERVER_USERNAME }}/" - username: ${{ secrets.SERVER_USERNAME }} - password: ${{ secrets.SERVER_PASSWORD }} -``` -**With key** -``` -name: copy using key -uses: srueda99/scp-action@v12 +```yaml +name: Copy single file +uses: tempersama/rsync-action@1.4 with: - port: 22 - host: ${{ secrets.SERVER_ADDRESS }} - destination: "/home/${{ secrets.SERVER_USERNAME }}/" - username: ${{ secrets.SERVER_USERNAME }} + host: ${{ secrets.host }} + source: html/ + destination: /opt/nginx/website.com + username: ${{ secrets.username }} key: ${{ secrets.SERVER_KEY }} + port: 2222 ``` -**With origin folder** -``` -name: copy using password -uses: srueda99/scp-action@v12 -with: - port: 22 - host: ${{ secrets.SERVER_ADDRESS }} - origin: "./*" - destination: "/home/${{ secrets.SERVER_USERNAME }}/" - username: ${{ secrets.SERVER_USERNAME }} - password: ${{ secrets.SERVER_PASSWORD }} -``` - -**With passphrase** -``` -name: copy using key -uses: srueda99/scp-action@v12 -with: - port: 22 - host: ${{ secrets.SERVER_ADDRESS }} - destination: "/home/${{ secrets.SERVER_USERNAME }}/" - username: ${{ secrets.SERVER_USERNAME }} - key: ${{ secrets.SERVER_KEY }} - passphrase: ${{ secrets.SERVER_PASSPHRASE }} -``` - -_Enjoy it!_ diff --git a/action.yml b/action.yml index 1733a17..bb9a41d 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ -name: 'Recursive SCP Deployment' -description: 'Recusively copies the files from your repository to a remote host using SCP' +name: 'Rsync Action' +description: 'Copies the files from your repository to a remote host using rsync' author: 'temper' inputs: # $1 @@ -10,7 +10,7 @@ inputs: host: description: 'IP Address or DNS of your target host' # $3 - origin: + source: description: 'Source route folder' default: "./*" # $4 @@ -19,18 +19,9 @@ inputs: # $5 username: description: 'User for remote connection' - # $6 - password: - description: 'Password for the user' # $7 key: description: 'Private SSH key' - # $8 - passphrase: - description: 'Passphrase for SSH key' -outputs: - time: - description: 'Returns the time when the script ran' runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 0a6a836..b9ac9a9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,18 +1,24 @@ -#!/bin/sh -l +#!/bin/sh -l -e -set -e +# Quick checks for missing parameters +rc=0 +empty() { echo ERROR: $1 is empty } -# Checking if the key input is not empty -if [[ "$INPUT_KEY" ]]; then - # If it is not empty, it uses the key for the rsync command - echo -e "${INPUT_KEY}" > key # Creates a file with the key content - chmod 400 key # Set the key as Read-Only +[[ "$INPUT_HOST" ]] && empty host +[[ "$INPUT_SOURCE" ]] && empty source +[[ "$INPUT_DESTINATION" ]] && empty destination +[[ "$INPUT_USERNME" ]] && empty username +[[ "$INPUT_KEY" ]] && empty key - rsync -a -v --stats -e "ssh -p $INPUT_PORT -o StrictHostKeyChecking=no -i key" \ - "$INPUT_ORIGIN" \ - "$INPUT_USERNAME"@"$INPUT_HOST":"$INPUT_DESTINATION" -fi -time=$(date) -echo "-----------------------------" -echo "| Files copied successfully |" -echo "-----------------------------" + + +echo -e "${INPUT_KEY}" > key +chmod 400 key + +# TODO: make sure we are not just blindly using StrictHostKeyChecking=no +rsync \ + -a -v \ --stats \ + -e "ssh -o StrictHostKeyChecking=no -i key" \ + --port $INPUT_PORT \ + "$INPUT_SOURCE" \ + "$INPUT_USERNAME"@"$INPUT_HOST":"$INPUT_DESTINATION"