2019-10-03 05:52:52 +08:00
|
|
|
#!/usr/bin/env node
|
2023-01-03 04:06:33 +08:00
|
|
|
const { sshDeploy } = require('./rsyncCli');
|
|
|
|
const { remoteCmdBefore, remoteCmdAfter } = require('./remoteCmd');
|
|
|
|
const { addSshKey, getPrivateKeyPath, updateKnownHosts } = require('./sshKey');
|
|
|
|
const { validateRequiredInputs } = require('./helpers');
|
|
|
|
const inputs = require('./inputs');
|
|
|
|
|
|
|
|
const run = async () => {
|
|
|
|
const {
|
|
|
|
source, remoteUser, remoteHost, remotePort,
|
|
|
|
deployKeyName, sshPrivateKey,
|
|
|
|
args, exclude, sshCmdArgs,
|
|
|
|
scriptBefore, scriptAfter,
|
|
|
|
rsyncServer
|
|
|
|
} = inputs;
|
|
|
|
// Validate required inputs
|
|
|
|
validateRequiredInputs({ sshPrivateKey, remoteHost, remoteUser });
|
|
|
|
// Add SSH key
|
|
|
|
addSshKey(sshPrivateKey, deployKeyName);
|
|
|
|
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
|
|
|
|
// Update known hosts if ssh command is present to avoid prompt
|
|
|
|
if (scriptBefore || scriptAfter) {
|
|
|
|
updateKnownHosts(remoteHost);
|
|
|
|
}
|
|
|
|
// Check Script before
|
|
|
|
if (scriptBefore) {
|
|
|
|
await remoteCmdBefore(scriptBefore, privateKeyPath);
|
|
|
|
}
|
|
|
|
/* eslint-disable object-property-newline */
|
|
|
|
await sshDeploy({
|
|
|
|
source, rsyncServer, exclude, remotePort,
|
|
|
|
privateKeyPath, args, sshCmdArgs
|
2020-04-11 22:29:20 +08:00
|
|
|
});
|
2023-01-03 04:06:33 +08:00
|
|
|
// Check script after
|
|
|
|
if (scriptAfter) {
|
|
|
|
await remoteCmdAfter(scriptAfter, privateKeyPath);
|
|
|
|
}
|
2019-10-03 05:52:52 +08:00
|
|
|
};
|
|
|
|
|
2023-01-03 04:06:33 +08:00
|
|
|
run()
|
|
|
|
.then((data = '') => {
|
|
|
|
console.log('✅ [DONE]', data);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('❌ [ERROR]', error.message);
|
|
|
|
process.exit(1);
|
|
|
|
});
|