From 4aef88179f847db97d8fdece3ad15f22e94f90a5 Mon Sep 17 00:00:00 2001 From: Fabricio Nogueira Date: Mon, 1 Jun 2020 23:48:15 -0300 Subject: [PATCH] feat(action): Create action to deploy with scp command --- .gitignore | 2 ++ README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++--- action.yml | 35 ++++++++++++++++++++-------- entrypoint.sh | 6 ++++- 4 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c36090 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.history +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 25842b5..6c58c7c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,62 @@ -# Container Action Template +# SCP Deploy action -To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/). +Action to send dist files to a remote server with scp command -For info on how to build your first Container action, see the [toolkit docs folder](https://github.com/actions/toolkit/blob/master/docs/container-action.md). +## Required params + +- `src`: Sorce dir to deploy +- `host`: SSH address +- `remote`: Remote dir path +- `port`: SSH Port +- `user`: SSH User name +- `key`: Private key + + +### To publish + +You must generate the ssh key and publish the public pair on your host. On git secrets, publish your private key + +Ex.: + +```bash +ssh-keygen -t rsa -b 4096 -f ssh_publish -C +``` + +## Example + +This is a nuxt universal application + +```yml +name: MasterCI + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + name: Build and Deploy + + steps: + - uses: actions/checkout@master + + - name: Bucket actions + uses: actions/setup-node@v1 + with: + node-version: 8 + - run: npm i + - run: npm run test + - run: npm run generate + + - name: Publish + uses: nogsantos/scp-deploy@master + with: + src: ./dist/* + host: ${{ secrets.SSH_HOST }} + remote: ${{ secrets.SSH_DIR }} + port: ${{ secrets.SSH_PORT }} + user: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_KEY }} +``` \ No newline at end of file diff --git a/action.yml b/action.yml index 4353abb..9b9ab20 100644 --- a/action.yml +++ b/action.yml @@ -1,12 +1,29 @@ -name: 'Container Action Template' -description: 'Get started with Container actions' -author: 'GitHub' -inputs: - myInput: - description: 'Input to use' - default: 'world' +name: 'scp-deploy' +description: 'Action to send dist files to a remote server with scp command' +author: 'Fabricio Nogueira' +inputs: + src: + description: 'Sorce dir to deploy' + required: true + host: + description: 'SSH address' + required: true + remote: + description: 'Remote dir path' + required: true + port: + description: 'SSH Port' + required: false + default: 22 + user: + description: 'SSH User name' + required: true + key: + description: 'Private key' + required: true runs: using: 'docker' image: 'Dockerfile' - args: - - ${{ inputs.myInput }} +branding: + icon: 'upload-cloud' + color: 'blue' \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 3b8cd2d..cc1f436 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,3 +1,7 @@ #!/bin/sh -l -echo "hello $1" +echo -e "${INPUT_KEY}" >__TEMP_INPUT_KEY_FILE + +chmod 600 __TEMP_INPUT_KEY_FILE + +scp -o StrictHostKeyChecking=no -v -i __TEMP_INPUT_KEY_FILE -P "${INPUT_PORT}" -r ${INPUT_SRC} "${INPUT_USER}"@"${INPUT_HOST}":"${INPUT_REMOTE}"