feat(action): Create action to deploy with scp command

This commit is contained in:
Fabricio Nogueira 2020-06-01 23:48:15 -03:00
parent da262dad45
commit 4aef88179f
4 changed files with 93 additions and 13 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.history
.vscode

View file

@ -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 <some@name>
```
## 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 }}
```

View file

@ -1,12 +1,29 @@
name: 'Container Action Template' name: 'scp-deploy'
description: 'Get started with Container actions' description: 'Action to send dist files to a remote server with scp command'
author: 'GitHub' author: 'Fabricio Nogueira'
inputs: inputs:
myInput: src:
description: 'Input to use' description: 'Sorce dir to deploy'
default: 'world' 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: runs:
using: 'docker' using: 'docker'
image: 'Dockerfile' image: 'Dockerfile'
args: branding:
- ${{ inputs.myInput }} icon: 'upload-cloud'
color: 'blue'

View file

@ -1,3 +1,7 @@
#!/bin/sh -l #!/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}"