mirror of
https://github.com/easingthemes/ssh-deploy
synced 2025-04-21 15:52:12 +00:00
update helpers
This commit is contained in:
parent
1b6513031e
commit
7306f6bca0
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const { sshDeploy } = require('./rsyncCli');
|
const { sshDeploy } = require('./rsyncCli');
|
||||||
const { remoteCmdBefore, remoteCmdAfter } = require('./remoteCmd');
|
const { remoteCmdBefore, remoteCmdAfter } = require('./remoteCmd');
|
||||||
const { addSshKey } = require('./sshKey');
|
const { addSshKey, getPrivateKeyPath } = require('./sshKey');
|
||||||
const { validateRequiredInputs } = require('./helpers');
|
const { validateRequiredInputs } = require('./helpers');
|
||||||
const inputs = require('./inputs');
|
const inputs = require('./inputs');
|
||||||
|
|
||||||
@ -16,7 +16,8 @@ const run = () => {
|
|||||||
// Validate required inputs
|
// Validate required inputs
|
||||||
validateRequiredInputs({ sshPrivateKey, remoteHost, remoteUser });
|
validateRequiredInputs({ sshPrivateKey, remoteHost, remoteUser });
|
||||||
// Add SSH key
|
// Add SSH key
|
||||||
const privateKey = addSshKey(sshPrivateKey, deployKeyName);
|
addSshKey(sshPrivateKey, deployKeyName);
|
||||||
|
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
|
||||||
// Check Script before
|
// Check Script before
|
||||||
if (scriptBefore) {
|
if (scriptBefore) {
|
||||||
remoteCmdBefore(scriptBefore);
|
remoteCmdBefore(scriptBefore);
|
||||||
@ -31,7 +32,7 @@ const run = () => {
|
|||||||
/* eslint-disable object-property-newline */
|
/* eslint-disable object-property-newline */
|
||||||
sshDeploy({
|
sshDeploy({
|
||||||
source, rsyncServer, exclude, remotePort,
|
source, rsyncServer, exclude, remotePort,
|
||||||
privateKey, args, sshCmdArgs, callback
|
privateKeyPath, args, sshCmdArgs, callback
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
|
|
||||||
const { sshServer, githubWorkspace } = require('./inputs');
|
const { privateKey, sshServer, githubWorkspace } = require('./inputs');
|
||||||
const { writeToFile } = require('./helpers');
|
const { writeToFile } = require('./helpers');
|
||||||
|
|
||||||
const remoteCmd = (content, label) => {
|
const remoteCmd = (content, label) => {
|
||||||
@ -8,7 +8,7 @@ const remoteCmd = (content, label) => {
|
|||||||
try {
|
try {
|
||||||
writeToFile({ dir: githubWorkspace, filename, content });
|
writeToFile({ dir: githubWorkspace, filename, content });
|
||||||
|
|
||||||
exec(`ssh ${sshServer} 'bash -s' < ${filename}`, (err, data, stderr) => {
|
exec(`ssh -i ${privateKey} ${sshServer} 'bash -s' < ${filename}`, (err, data, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('⚠️ [CMD] Remote script failed. ', err.message);
|
console.log('⚠️ [CMD] Remote script failed. ', err.message);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,19 +3,13 @@ const nodeRsync = require('rsyncwrapper');
|
|||||||
|
|
||||||
// eslint-disable-next-line no-async-promise-executor
|
// eslint-disable-next-line no-async-promise-executor
|
||||||
const validateRsync = new Promise(async (resolve, reject) => {
|
const validateRsync = new Promise(async (resolve, reject) => {
|
||||||
let rsyncCli;
|
|
||||||
try {
|
try {
|
||||||
execSync('rsync --version', { stdio: 'inherit' });
|
execSync('rsync --version', { stdio: 'inherit' });
|
||||||
rsyncCli = true;
|
|
||||||
} catch (e) {
|
|
||||||
rsyncCli = false;
|
|
||||||
console.log('⚠️ [CLI] Rsync doesn\'t exists', e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rsyncCli) {
|
|
||||||
console.log('⚠️ [CLI] Rsync exists');
|
console.log('⚠️ [CLI] Rsync exists');
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('⚠️ [CLI] Rsync doesn\'t exists', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');
|
console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');
|
||||||
@ -30,7 +24,7 @@ const validateRsync = new Promise(async (resolve, reject) => {
|
|||||||
|
|
||||||
const rsyncCli = ({
|
const rsyncCli = ({
|
||||||
source, rsyncServer, exclude, remotePort,
|
source, rsyncServer, exclude, remotePort,
|
||||||
privateKey, args, sshCmdArgs, callback
|
privateKeyPath, args, sshCmdArgs, callback
|
||||||
}) => {
|
}) => {
|
||||||
console.log(`[Rsync] Starting Rsync Action: ${source} to ${rsyncServer}`);
|
console.log(`[Rsync] Starting Rsync Action: ${source} to ${rsyncServer}`);
|
||||||
if (exclude) console.log(`[Rsync] excluding folders ${exclude}`);
|
if (exclude) console.log(`[Rsync] excluding folders ${exclude}`);
|
||||||
@ -46,7 +40,7 @@ const rsyncCli = ({
|
|||||||
nodeRsync({
|
nodeRsync({
|
||||||
...defaultOptions,
|
...defaultOptions,
|
||||||
src: source, dest: rsyncServer, excludeFirst: exclude, port: remotePort,
|
src: source, dest: rsyncServer, excludeFirst: exclude, port: remotePort,
|
||||||
privateKey, args, sshCmdArgs,
|
privateKey: privateKeyPath, args, sshCmdArgs
|
||||||
}, (error, stdout, stderr, cmd) => {
|
}, (error, stdout, stderr, cmd) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('⚠️ [Rsync] error: ', error.message);
|
console.error('⚠️ [Rsync] error: ', error.message);
|
||||||
|
@ -1,20 +1,25 @@
|
|||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
|
|
||||||
const { writeToFile } = require('./helpers');
|
const { writeToFile } = require('./helpers');
|
||||||
|
|
||||||
const addSshKey = (content, filename) => {
|
const getPrivateKeyPath = (filename) => {
|
||||||
const { HOME } = process.env;
|
const { HOME } = process.env;
|
||||||
const dir = join(HOME || __dirname, '.ssh');
|
const dir = join(HOME || __dirname, '.ssh');
|
||||||
const filePath = join(dir, filename);
|
return {
|
||||||
|
dir,
|
||||||
|
filename,
|
||||||
|
path: join(dir, filename)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const addSshKey = (content, deployKeyName) => {
|
||||||
|
const { dir, filename } = getPrivateKeyPath(deployKeyName);
|
||||||
writeToFile({ dir, filename: 'known_hosts', content: '' });
|
writeToFile({ dir, filename: 'known_hosts', content: '' });
|
||||||
console.log('✅ [SSH] known_hosts file ensured', dir, filename, content.length);
|
console.log('✅ [SSH] known_hosts file ensured', dir);
|
||||||
writeToFile({ dir, filename, content, isRequired: true });
|
writeToFile({ dir, filename, content, isRequired: true });
|
||||||
console.log('✅ [SSH] key added to `.ssh` dir ', dir);
|
console.log('✅ [SSH] key added to `.ssh` dir ', dir, filename);
|
||||||
|
|
||||||
return filePath;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
getPrivateKeyPath,
|
||||||
addSshKey
|
addSshKey
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user