mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2024-11-12 05:38:05 +00:00
Merge pull request #4 from GarryOne/patch-1
Improved error handling. Added to README.md PM key generation details
This commit is contained in:
commit
1a29114d7b
2
.gitignore
vendored
2
.gitignore
vendored
@ -17,3 +17,5 @@ node_modules/
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# jetbrains
|
||||
.idea
|
||||
|
@ -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
30
dist/index.js
vendored
@ -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,
|
||||
|
28
src/index.js
28
src/index.js
@ -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 || '',
|
||||
|
Loading…
Reference in New Issue
Block a user