diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index f7d44b0..f946f78 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -13,7 +13,7 @@ jobs: uses: srueda99/scp-action@v1 with: port: 22 - host: - target: "/home" - username: - key: \ No newline at end of file + host: ${{ secrets.SERVER_ADDRESS }} + destination: "/home/${{ secrets.SERVER_USERNAME }}/" + username: ${{ secrets.SERVER_USERNAME }} + key: ${{ secrets.SERVER_KEY }} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7600dd4 --- /dev/null +++ b/README.md @@ -0,0 +1,73 @@ +# SCP ACTION +## By SRUEDA99 + +## 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. +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. +``` + +## Examples +**With password** +``` +name: Copy using password +uses: srueda99/scp-action@v1 +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@v1 +with: + port: 22 + host: ${{ secrets.SERVER_ADDRESS }} + destination: "/home/${{ secrets.SERVER_USERNAME }}/" + username: ${{ secrets.SERVER_USERNAME }} + key: ${{ secrets.SERVER_KEY }} +``` + +**With origin folder** +``` +name: Copy using password +uses: srueda99/scp-action@v1 +with: + port: 22 + host: ${{ secrets.SERVER_ADDRESS }} + origin: "/home/*" + destination: "/home/${{ secrets.SERVER_USERNAME }}/" + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} +``` + +**With passphrase** +``` +name: Copy using key +uses: srueda99/scp-action@v1 +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!! \ No newline at end of file diff --git a/action.yml b/action.yml index 473a1a7..94edd78 100644 --- a/action.yml +++ b/action.yml @@ -10,18 +10,22 @@ inputs: host: description: 'IP Address or DNS of your target host' # $3 - target: - description: 'Destination route folder' + origin: + description: 'Source route folder' + default: "./*" # $4 + destination: + description: 'Destination route folder' + # $5 username: description: 'User for remote connection' - # $5 + # $6 password: description: 'Password for the user' - # $6 + # $7 key: description: 'Private SSH key' - # $7 + # $8 passphrase: description: 'Passphrase for SSH key' outputs: @@ -30,11 +34,12 @@ outputs: runs: using: 'docker' image: 'Dockerfile' - args: - - ${{ inputs.port }} - - ${{ inputs.host }} - - ${{ inputs.target }} - - ${{ inputs.username }} - - ${{ inputs.password }} - - ${{ inputs.key }} - - ${{ inputs.passphrase }} \ No newline at end of file + # args: + # - ${{ inputs.port }} + # - ${{ inputs.host }} + # - ${{ inputs.origin }} + # - ${{ inputs.destination }} + # - ${{ inputs.username }} + # - ${{ inputs.password }} + # - ${{ inputs.key }} + # - ${{ inputs.passphrase }} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 7b163a8..542cfb7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,2 +1,12 @@ #!/bin/sh -l +if [[ "$INPUT_KEY" ]]; then + echo -e "${INPUT_KEY}" > key + chmod 400 key + echo "Trying SCP process with SSH key" + scp -P $INPUT_PORT -o StrictHostKeyChecking=no -i key $INPUT_ORIGIN "$INPUT_USERNAME"@"$INPUT_HOST":"$INPUT_DESTINATION" +else + echo "Trying SCP process with password" + sshpass -p $INPUT_PASSWORD scp -P $INPUT_PORT -o StrictHostKeyChecking=no $INPUT_ORIGIN "$INPUT_USERNAME"@"$INPUT_HOST":"$INPUT_DESTINATION" +fi +echo "Files successfully copied" \ No newline at end of file diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..8a5412b --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +This is a test file, you should be able to read this in your target server. \ No newline at end of file