Merge pull request #4 from GarryOne/patch-1

Improved error handling. Added to README.md PM key generation details
This commit is contained in:
Dragan Filipović
2020-04-11 16:40:33 +02:00
committed by GitHub
4 changed files with 40 additions and 26 deletions

2
.gitignore vendored
View File

@@ -17,3 +17,5 @@ node_modules/
.env
.env.test
# jetbrains
.idea

View File

@@ -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 use this command
`ssh-keygen -m PEM -t rsa -b 4096`
2. `REMOTE_HOST` [required]

30
dist/index.js vendored
View File

@@ -492,6 +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: ', stderr);
console.log('stdout: ', stdout);
console.log('cmd: ', cmd);
process.abort();
} else {
console.log("✅ Rsync finished.", stdout);
@@ -504,14 +507,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');
@@ -596,26 +599,27 @@ 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;
});
if (validInputs.length !== inputs.length) {
if (validInputs.length !== Object.keys(inputs).length) {
process.abort();
}
};
const run = () => {
validateInputs([SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER]);
validateInputs({SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER});
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,

View File

@@ -17,6 +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: ', stderr);
console.log('stdout: ', stdout);
console.log('cmd: ', cmd);
process.abort();
} else {
console.log("✅ Rsync finished.", stdout);
@@ -29,14 +32,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');
@@ -121,21 +124,22 @@ 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;
});
if (validInputs.length !== inputs.length) {
if (validInputs.length !== Object.keys(inputs).length) {
process.abort();
}
};
const run = () => {
validateInputs([SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER]);
validateInputs({SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER});
sshDeploy.init({
src: GITHUB_WORKSPACE + '/' + SOURCE || '',