From 0d77a6681beb37d3dcf437a1ba665dbe0c562e78 Mon Sep 17 00:00:00 2001 From: Filip Malinowski Date: Sun, 29 Dec 2019 15:36:34 +0100 Subject: [PATCH] add optional `REMOTE_PORT` env to configuration --- README.md | 14 +++++++++----- action.yml | 35 +++++++++++++++++++---------------- dist/index.js | 12 +++++++----- package-lock.json | 2 +- package.json | 2 +- src/index.js | 12 +++++++----- 6 files changed, 44 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index fe240e9..9261d19 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Deploy code with rsync over ssh, using NodeJS. NodeJS version is more than a minute `faster` than simple Docker version. -This GitHub Action deploys specific directory from `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh, using NodeJS. +This GitHub Action deploys specific directory from `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh, using NodeJS. This action would usually follow a build/test action which leaves deployable code in `GITHUB_WORKSPACE`, eg `dist`; @@ -16,14 +16,18 @@ Pass configuration with `env` vars This should be the private key part of an ssh key pair. The public key part should be added to the authorized_keys file on the server that receives the deployment. -2. `REMOTE_HOST` [required] +2. `REMOTE_HOST` [required] eg: mydomain.com -3. `REMOTE_USER` [required] +3. `REMOTE_USER` [required] eg: myusername +3. `REMOTE_PORT` (optional, default '22') + +eg: '59184' + 2. `ARGS` (optional, default '-rltgoDzvO') For any initial/required rsync flags, eg: `-avzr --delete` @@ -85,6 +89,6 @@ jobs: ## Disclaimer -If you're using GitHub Actions, you'll probably already know that it's still in limited public beta, and GitHub advise against using Actions in production. +If you're using GitHub Actions, you'll probably already know that it's still in limited public beta, and GitHub advise against using Actions in production. -So, check your keys. Check your deployment paths. And use at your own risk. \ No newline at end of file +So, check your keys. Check your deployment paths. And use at your own risk. diff --git a/action.yml b/action.yml index f6bd7dd..7979a64 100644 --- a/action.yml +++ b/action.yml @@ -1,28 +1,31 @@ -name: 'ssh deploy' -description: 'NodeJS action for FAST deployment with rsync/ssh' -author: 'easingthemes' +name: "ssh deploy" +description: "NodeJS action for FAST deployment with rsync/ssh" +author: "easingthemes" inputs: - SSH_PRIVATE_KEY: # Private Key - description: 'Private Key' + SSH_PRIVATE_KEY: # Private Key + description: "Private Key" required: true REMOTE_HOST: - description: 'Remote host' + description: "Remote host" required: true REMOTE_USER: - description: 'Remote user' + description: "Remote user" required: true + REMOTE_PORT: + description: "Remote port" + default: "22" SOURCE: - description: 'Source directory' - default: '' + description: "Source directory" + default: "" TARGET: - description: 'Target directory' - default: '/home/REMOTE_USER/' + description: "Target directory" + default: "/home/REMOTE_USER/" outputs: status: - description: 'Status' + description: "Status" runs: - using: 'node12' - main: 'dist/index.js' + using: "node12" + main: "dist/index.js" branding: - color: 'green' - icon: 'truck' \ No newline at end of file + color: "green" + icon: "truck" diff --git a/dist/index.js b/dist/index.js index cb66361..da1967b 100755 --- a/dist/index.js +++ b/dist/index.js @@ -480,16 +480,16 @@ const commandExists = __webpack_require__(677); const nodeCmd = __webpack_require__(428); const nodeRsync = __webpack_require__(250); -const { REMOTE_HOST, REMOTE_USER, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; +const { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; console.log('GITHUB_WORKSPACE', GITHUB_WORKSPACE); const sshDeploy = (() => { - const rsync = ({ privateKey, src, dest, args }) => { + const rsync = ({ privateKey, port, src, dest, args }) => { console.log(`Starting Rsync Action: ${src} to ${dest}`); try { // RSYNC COMMAND - nodeRsync({ src, dest, args, privateKey, ssh: true, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { + nodeRsync({ src, dest, args, privateKey, ssh: true, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { if (error) { console.error('⚠️ Rsync error', error.message); process.abort(); @@ -509,14 +509,15 @@ const sshDeploy = (() => { args, host = 'localhost', username, - privateKeyContent + privateKeyContent, + port }) => { validateRsync(() => { const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key'); const remoteDest = username + '@' + host + ':' + dest; - rsync({ privateKey, src, dest: remoteDest, args }); + rsync({ privateKey, port, src, dest: remoteDest, args }); }); }; @@ -616,6 +617,7 @@ const run = () => { dest: TARGET || '/home/' + REMOTE_USER + '/', args: [ARGS] || false, host: REMOTE_HOST, + port: REMOTE_PORT || '22', username: REMOTE_USER, privateKeyContent: SSH_PRIVATE_KEY, }); diff --git a/package-lock.json b/package-lock.json index 615427f..e5d3176 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ssh-deploy", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0bc8308..b0f6d59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ssh-deploy", - "version": "2.0.7", + "version": "2.1.0", "description": "This GitHub Action deploys specific directory from `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh.", "main": "src/index.js", "dependencies": { diff --git a/src/index.js b/src/index.js index fa01143..cd88f92 100644 --- a/src/index.js +++ b/src/index.js @@ -5,16 +5,16 @@ const commandExists = require('command-exists'); const nodeCmd = require('node-cmd'); const nodeRsync = require('rsyncwrapper'); -const { REMOTE_HOST, REMOTE_USER, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; +const { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; console.log('GITHUB_WORKSPACE', GITHUB_WORKSPACE); const sshDeploy = (() => { - const rsync = ({ privateKey, src, dest, args }) => { + const rsync = ({ privateKey, port, src, dest, args }) => { console.log(`Starting Rsync Action: ${src} to ${dest}`); try { // RSYNC COMMAND - nodeRsync({ src, dest, args, privateKey, ssh: true, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { + nodeRsync({ src, dest, args, privateKey, ssh: true, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { if (error) { console.error('⚠️ Rsync error', error.message); process.abort(); @@ -34,14 +34,15 @@ const sshDeploy = (() => { args, host = 'localhost', username, - privateKeyContent + privateKeyContent, + port }) => { validateRsync(() => { const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key'); const remoteDest = username + '@' + host + ':' + dest; - rsync({ privateKey, src, dest: remoteDest, args }); + rsync({ privateKey, port, src, dest: remoteDest, args }); }); }; @@ -141,6 +142,7 @@ const run = () => { dest: TARGET || '/home/' + REMOTE_USER + '/', args: [ARGS] || ['-rltgoDzvO'], host: REMOTE_HOST, + port: REMOTE_PORT || '22', username: REMOTE_USER, privateKeyContent: SSH_PRIVATE_KEY, });