From 3f84fa4ae12aafd93072c4680e63edd21df9f163 Mon Sep 17 00:00:00 2001 From: Mardari Igor Date: Wed, 25 Mar 2020 04:50:26 +0200 Subject: [PATCH 01/11] Set ssh to false --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 5a5ed28..f5a007c 100644 --- a/src/index.js +++ b/src/index.js @@ -14,7 +14,7 @@ const sshDeploy = (() => { try { // RSYNC COMMAND - nodeRsync({ src, dest, args, privateKey, ssh: true, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { + nodeRsync({ src, dest, args, privateKey, ssh: false, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { if (error) { console.error('⚠️ Rsync error', error.message); process.abort(); From ff832e4e77cd163987a7b87cb0f33a28a1543487 Mon Sep 17 00:00:00 2001 From: GarryOne Date: Wed, 25 Mar 2020 05:08:01 +0200 Subject: [PATCH 02/11] Built src/index.js --- dist/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index da1967b..b6d7fc0 100755 --- a/dist/index.js +++ b/dist/index.js @@ -489,7 +489,7 @@ const sshDeploy = (() => { try { // RSYNC COMMAND - nodeRsync({ src, dest, args, privateKey, ssh: true, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { + nodeRsync({ src, dest, args, privateKey, ssh: false, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { if (error) { console.error('⚠️ Rsync error', error.message); process.abort(); @@ -615,7 +615,7 @@ const run = () => { sshDeploy.init({ src: GITHUB_WORKSPACE + '/' + SOURCE || '', dest: TARGET || '/home/' + REMOTE_USER + '/', - args: [ARGS] || false, + args: ARGS ? [ARGS] : ['-rltgoDzvO'], host: REMOTE_HOST, port: REMOTE_PORT || '22', username: REMOTE_USER, From 82ccbba7dc5e6902d8c69b6501828696c4f79265 Mon Sep 17 00:00:00 2001 From: GarryOne Date: Wed, 25 Mar 2020 05:20:29 +0200 Subject: [PATCH 03/11] Added field key to validation message --- dist/index.js | 7 ++++--- src/index.js | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index b6d7fc0..79a6875 100755 --- a/dist/index.js +++ b/dist/index.js @@ -596,9 +596,10 @@ const sshDeploy = (() => { })(); const validateInputs = (inputs) => { - const validInputs = inputs.filter(input => { + const validInputs = Object.keys(inputs).filter((key) => { + const input = inputs[key]; if (!input) { - console.error(`⚠️ ${input} is mandatory`); + console.error(`⚠️ ${key} is mandatory`); } return input; @@ -610,7 +611,7 @@ const validateInputs = (inputs) => { }; const run = () => { - validateInputs([SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER]); + validateInputs({SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER}); sshDeploy.init({ src: GITHUB_WORKSPACE + '/' + SOURCE || '', diff --git a/src/index.js b/src/index.js index f5a007c..3ad396b 100644 --- a/src/index.js +++ b/src/index.js @@ -121,9 +121,10 @@ const sshDeploy = (() => { })(); const validateInputs = (inputs) => { - const validInputs = inputs.filter(input => { + const validInputs = Object.keys(inputs).filter((key) => { + const input = inputs[key]; if (!input) { - console.error(`⚠️ ${input} is mandatory`); + console.error(`⚠️ ${key} is mandatory`); } return input; @@ -135,7 +136,7 @@ const validateInputs = (inputs) => { }; const run = () => { - validateInputs([SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER]); + validateInputs({SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER}); sshDeploy.init({ src: GITHUB_WORKSPACE + '/' + SOURCE || '', From f09a8d0277b9c38a2eaed08f87c80a9afe4205b8 Mon Sep 17 00:00:00 2001 From: GarryOne Date: Wed, 25 Mar 2020 05:28:27 +0200 Subject: [PATCH 04/11] Removed console.log() --- dist/index.js | 19 +++++++++---------- src/index.js | 19 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/dist/index.js b/dist/index.js index 79a6875..cfb540f 100755 --- a/dist/index.js +++ b/dist/index.js @@ -481,7 +481,6 @@ const nodeCmd = __webpack_require__(428); const nodeRsync = __webpack_require__(250); 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, port, src, dest, args }) => { @@ -504,14 +503,14 @@ const sshDeploy = (() => { }; const init = ({ - src, - dest, - args, - host = 'localhost', - username, - privateKeyContent, - port - }) => { + src, + dest, + args, + host = 'localhost', + username, + privateKeyContent, + port + }) => { validateRsync(() => { const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key'); @@ -605,7 +604,7 @@ const validateInputs = (inputs) => { return input; }); - if (validInputs.length !== inputs.length) { + if (validInputs.length !== Object.keys(inputs).length) { process.abort(); } }; diff --git a/src/index.js b/src/index.js index 3ad396b..8916c2b 100644 --- a/src/index.js +++ b/src/index.js @@ -6,7 +6,6 @@ const nodeCmd = require('node-cmd'); const nodeRsync = require('rsyncwrapper'); 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, port, src, dest, args }) => { @@ -29,14 +28,14 @@ const sshDeploy = (() => { }; const init = ({ - src, - dest, - args, - host = 'localhost', - username, - privateKeyContent, - port - }) => { + src, + dest, + args, + host = 'localhost', + username, + privateKeyContent, + port + }) => { validateRsync(() => { const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME ||'deploy_key'); @@ -130,7 +129,7 @@ const validateInputs = (inputs) => { return input; }); - if (validInputs.length !== inputs.length) { + if (validInputs.length !== Object.keys(inputs).length) { process.abort(); } }; From 749cc36d5d893bd4a8f572f28c7892bbafb4e8bc Mon Sep 17 00:00:00 2001 From: GarryOne Date: Wed, 25 Mar 2020 05:33:08 +0200 Subject: [PATCH 05/11] Added .idea to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ba32f0a..623377c 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ node_modules/ .env .env.test +# jetbrains +.idea From 733f9fc1538b029fa04f219176907080b88c0638 Mon Sep 17 00:00:00 2001 From: GarryOne Date: Thu, 26 Mar 2020 23:27:22 +0200 Subject: [PATCH 06/11] Added console.log(process.env) --- dist/index.js | 4 +++- src/index.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index cfb540f..d59ff27 100755 --- a/dist/index.js +++ b/dist/index.js @@ -480,7 +480,9 @@ const commandExists = __webpack_require__(677); const nodeCmd = __webpack_require__(428); const nodeRsync = __webpack_require__(250); -const { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; +const vars = { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; + +console.log(vars); const sshDeploy = (() => { const rsync = ({ privateKey, port, src, dest, args }) => { diff --git a/src/index.js b/src/index.js index 8916c2b..c5cdc5b 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,9 @@ const commandExists = require('command-exists'); const nodeCmd = require('node-cmd'); const nodeRsync = require('rsyncwrapper'); -const { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; +const vars = { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; + +console.log(vars); const sshDeploy = (() => { const rsync = ({ privateKey, port, src, dest, args }) => { From 19dbe22d4f35dbbcdce3d3fd7d2120a7a17f19a2 Mon Sep 17 00:00:00 2001 From: GarryOne Date: Thu, 26 Mar 2020 23:47:55 +0200 Subject: [PATCH 07/11] Removed console.log --- dist/index.js | 12 +++++++----- src/index.js | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index d59ff27..35fce26 100755 --- a/dist/index.js +++ b/dist/index.js @@ -480,26 +480,28 @@ const commandExists = __webpack_require__(677); const nodeCmd = __webpack_require__(428); const nodeRsync = __webpack_require__(250); -const vars = { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; - -console.log(vars); +const { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; const sshDeploy = (() => { const rsync = ({ privateKey, port, src, dest, args }) => { console.log(`Starting Rsync Action: ${src} to ${dest}`); + console.log(privateKey, port, src, dest, args); + try { // RSYNC COMMAND nodeRsync({ src, dest, args, privateKey, ssh: false, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { if (error) { - console.error('⚠️ Rsync error', error.message); + console.error('⚠️ Rsync error', error); + console.log(stderr); + console.log(stdout); process.abort(); } else { console.log("✅ Rsync finished.", stdout); } }); } catch (err) { - console.error(`⚠️ An error happened:(.`, err.message, err.stack); + console.error(`⚠️ An error happened:(.`, err); process.abort(); } }; diff --git a/src/index.js b/src/index.js index c5cdc5b..1dcc7a5 100644 --- a/src/index.js +++ b/src/index.js @@ -5,26 +5,28 @@ const commandExists = require('command-exists'); const nodeCmd = require('node-cmd'); const nodeRsync = require('rsyncwrapper'); -const vars = { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; - -console.log(vars); +const { REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, GITHUB_WORKSPACE, HOME } = process.env; const sshDeploy = (() => { const rsync = ({ privateKey, port, src, dest, args }) => { console.log(`Starting Rsync Action: ${src} to ${dest}`); + console.log(privateKey, port, src, dest, args); + try { // RSYNC COMMAND nodeRsync({ src, dest, args, privateKey, ssh: false, port, sshCmdArgs: ['-o StrictHostKeyChecking=no'], recursive: true }, (error, stdout, stderr, cmd) => { if (error) { - console.error('⚠️ Rsync error', error.message); + console.error('⚠️ Rsync error', error); + console.log(stderr); + console.log(stdout); process.abort(); } else { console.log("✅ Rsync finished.", stdout); } }); } catch (err) { - console.error(`⚠️ An error happened:(.`, err.message, err.stack); + console.error(`⚠️ An error happened:(.`, err); process.abort(); } }; From 37e21b5b6b67e1c5d07fb1bb48d6b31117041fa2 Mon Sep 17 00:00:00 2001 From: GarryOne Date: Thu, 26 Mar 2020 23:53:42 +0200 Subject: [PATCH 08/11] Added error display for rsync --- dist/index.js | 9 ++++----- src/index.js | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index 35fce26..fbbc9b8 100755 --- a/dist/index.js +++ b/dist/index.js @@ -481,18 +481,17 @@ const nodeCmd = __webpack_require__(428); const nodeRsync = __webpack_require__(250); 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, port, src, dest, args }) => { console.log(`Starting Rsync Action: ${src} to ${dest}`); - console.log(privateKey, port, src, dest, args); - try { // RSYNC COMMAND - nodeRsync({ src, dest, args, privateKey, ssh: false, port, 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); + console.error('⚠️ Rsync error', error.message); console.log(stderr); console.log(stdout); process.abort(); @@ -501,7 +500,7 @@ const sshDeploy = (() => { } }); } catch (err) { - console.error(`⚠️ An error happened:(.`, err); + console.error(`⚠️ An error happened:(.`, err.message, err.stack); process.abort(); } }; diff --git a/src/index.js b/src/index.js index 1dcc7a5..9c6df69 100644 --- a/src/index.js +++ b/src/index.js @@ -6,18 +6,17 @@ const nodeCmd = require('node-cmd'); const nodeRsync = require('rsyncwrapper'); 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, port, src, dest, args }) => { console.log(`Starting Rsync Action: ${src} to ${dest}`); - console.log(privateKey, port, src, dest, args); - try { // RSYNC COMMAND - nodeRsync({ src, dest, args, privateKey, ssh: false, port, 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); + console.error('⚠️ Rsync error', error.message); console.log(stderr); console.log(stdout); process.abort(); @@ -26,7 +25,7 @@ const sshDeploy = (() => { } }); } catch (err) { - console.error(`⚠️ An error happened:(.`, err); + console.error(`⚠️ An error happened:(.`, err.message, err.stack); process.abort(); } }; From 00e4d7e856cb9da321f1984bcf47ef0f55322a51 Mon Sep 17 00:00:00 2001 From: GarryOne Date: Fri, 27 Mar 2020 01:10:01 +0200 Subject: [PATCH 09/11] Added cmd to rsync error output --- dist/index.js | 5 +++-- src/index.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index fbbc9b8..858600f 100755 --- a/dist/index.js +++ b/dist/index.js @@ -492,8 +492,9 @@ const sshDeploy = (() => { 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); - console.log(stderr); - console.log(stdout); + console.log('stderr: ', stderr); + console.log('stdout: ', stdout); + console.log('cmd: ', cmd); process.abort(); } else { console.log("✅ Rsync finished.", stdout); diff --git a/src/index.js b/src/index.js index 9c6df69..216db25 100644 --- a/src/index.js +++ b/src/index.js @@ -17,8 +17,9 @@ const sshDeploy = (() => { 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); - console.log(stderr); - console.log(stdout); + console.log('stderr: ', stderr); + console.log('stdout: ', stdout); + console.log('cmd: ', cmd); process.abort(); } else { console.log("✅ Rsync finished.", stdout); From 140e959df8e54b8075b4b0bfd62d0ecb4223400e Mon Sep 17 00:00:00 2001 From: GarryOne Date: Fri, 27 Mar 2020 01:17:37 +0200 Subject: [PATCH 10/11] Added key generation details to README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b60bebe..ed23927 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,11 @@ Pass configuration with `env` vars 1. `SSH_PRIVATE_KEY` [required] -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. +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. + +The keys should be generated using the PEM format. You can us this command +`ssh-keygen -m PEM -t rsa -b 4096` 2. `REMOTE_HOST` [required] From 53c00dce2b503a96d5fc862d16ff10d70e854329 Mon Sep 17 00:00:00 2001 From: Mardari Igor Date: Sat, 11 Apr 2020 13:11:34 +0300 Subject: [PATCH 11/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed23927..11db068 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ 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. -The keys should be generated using the PEM format. You can us this command +The keys should be generated using the PEM format. You can use this command `ssh-keygen -m PEM -t rsa -b 4096` 2. `REMOTE_HOST` [required]