mirror of
https://github.com/easingthemes/ssh-deploy
synced 2025-04-22 00:02:18 +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
|
||||
const { sshDeploy } = require('./rsyncCli');
|
||||
const { remoteCmdBefore, remoteCmdAfter } = require('./remoteCmd');
|
||||
const { addSshKey } = require('./sshKey');
|
||||
const { addSshKey, getPrivateKeyPath } = require('./sshKey');
|
||||
const { validateRequiredInputs } = require('./helpers');
|
||||
const inputs = require('./inputs');
|
||||
|
||||
@ -16,7 +16,8 @@ const run = () => {
|
||||
// Validate required inputs
|
||||
validateRequiredInputs({ sshPrivateKey, remoteHost, remoteUser });
|
||||
// Add SSH key
|
||||
const privateKey = addSshKey(sshPrivateKey, deployKeyName);
|
||||
addSshKey(sshPrivateKey, deployKeyName);
|
||||
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
|
||||
// Check Script before
|
||||
if (scriptBefore) {
|
||||
remoteCmdBefore(scriptBefore);
|
||||
@ -31,7 +32,7 @@ const run = () => {
|
||||
/* eslint-disable object-property-newline */
|
||||
sshDeploy({
|
||||
source, rsyncServer, exclude, remotePort,
|
||||
privateKey, args, sshCmdArgs, callback
|
||||
privateKeyPath, args, sshCmdArgs, callback
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
const { exec } = require('child_process');
|
||||
|
||||
const { sshServer, githubWorkspace } = require('./inputs');
|
||||
const { privateKey, sshServer, githubWorkspace } = require('./inputs');
|
||||
const { writeToFile } = require('./helpers');
|
||||
|
||||
const remoteCmd = (content, label) => {
|
||||
@ -8,7 +8,7 @@ const remoteCmd = (content, label) => {
|
||||
try {
|
||||
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) {
|
||||
console.log('⚠️ [CMD] Remote script failed. ', err.message);
|
||||
} else {
|
||||
|
@ -3,19 +3,13 @@ const nodeRsync = require('rsyncwrapper');
|
||||
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
const validateRsync = new Promise(async (resolve, reject) => {
|
||||
let rsyncCli;
|
||||
try {
|
||||
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');
|
||||
resolve();
|
||||
return;
|
||||
} catch (e) {
|
||||
console.log('⚠️ [CLI] Rsync doesn\'t exists', e);
|
||||
}
|
||||
|
||||
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 = ({
|
||||
source, rsyncServer, exclude, remotePort,
|
||||
privateKey, args, sshCmdArgs, callback
|
||||
privateKeyPath, args, sshCmdArgs, callback
|
||||
}) => {
|
||||
console.log(`[Rsync] Starting Rsync Action: ${source} to ${rsyncServer}`);
|
||||
if (exclude) console.log(`[Rsync] excluding folders ${exclude}`);
|
||||
@ -46,7 +40,7 @@ const rsyncCli = ({
|
||||
nodeRsync({
|
||||
...defaultOptions,
|
||||
src: source, dest: rsyncServer, excludeFirst: exclude, port: remotePort,
|
||||
privateKey, args, sshCmdArgs,
|
||||
privateKey: privateKeyPath, args, sshCmdArgs
|
||||
}, (error, stdout, stderr, cmd) => {
|
||||
if (error) {
|
||||
console.error('⚠️ [Rsync] error: ', error.message);
|
||||
|
@ -1,20 +1,25 @@
|
||||
const { join } = require('path');
|
||||
|
||||
const { writeToFile } = require('./helpers');
|
||||
|
||||
const addSshKey = (content, filename) => {
|
||||
const getPrivateKeyPath = (filename) => {
|
||||
const { HOME } = process.env;
|
||||
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: '' });
|
||||
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 });
|
||||
console.log('✅ [SSH] key added to `.ssh` dir ', dir);
|
||||
|
||||
return filePath;
|
||||
console.log('✅ [SSH] key added to `.ssh` dir ', dir, filename);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getPrivateKeyPath,
|
||||
addSshKey
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user