diff --git a/README.md b/README.md index ef2b72c..5f1b54c 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Rsync files from a GitHub repo to a destination server over SSH | `SSH_PRIVATE_KEY` | The private key part of an SSH key pair. The public key part should be added to the `authorized_keys` on the destination server. | | `SSH_USERNAME` | The username to use when connecting to the destination server | | `SSH_HOSTNAME` | The hostname of the destination server | +| `SSH_PORT` | The port number of the destination server (default: 22) | ## Required arguments diff --git a/entrypoint.sh b/entrypoint.sh index 2806743..d55a996 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,5 +8,14 @@ mkdir -p "$SSH_PATH" echo "$SSH_PRIVATE_KEY" > "$SSH_PATH/deploy_key" chmod 600 "$SSH_PATH/deploy_key" +# Create SSH config file +touch "$SSH_PATH/config" +echo "Host rsync_target" >> "$SSH_PATH/config" +echo " HostName $SSH_HOSTNAME" >> "$SSH_PATH/config" +echo " User $SSH_USERNAME" >> "$SSH_PATH/config" +echo " IdentityFile $SSH_PATH/deploy_key" >> "$SSH_PATH/config" +echo " Port ${SSH_PORT:-22}" >> "$SSH_PATH/config" +echo " StrictHostKeyChecking no" >> "$SSH_PATH/config" + # Do deployment -sh -c "rsync ${INPUT_RSYNC_OPTIONS} -e 'ssh -i $SSH_PATH/deploy_key -o StrictHostKeyChecking=no' ${GITHUB_WORKSPACE}${INPUT_RSYNC_SOURCE} ${SSH_USERNAME}@${SSH_HOSTNAME}:${INPUT_RSYNC_TARGET}" +sh -c "rsync -e 'ssh -F \"$SSH_PATH/config\"' ${INPUT_RSYNC_OPTIONS} ${GITHUB_WORKSPACE}${INPUT_RSYNC_SOURCE} rsync_target:${INPUT_RSYNC_TARGET}"