2019-10-02 23:52:52 +02:00
|
|
|
#!/usr/bin/env node
|
2023-01-02 21:06:33 +01: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,
|
2023-04-18 17:24:01 -04:00
|
|
|
scriptBefore, scriptBeforeRequired,
|
|
|
|
scriptAfter, scriptAfterRequired,
|
2023-01-02 21:06:33 +01:00
|
|
|
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) {
|
2023-02-10 18:55:53 +01:00
|
|
|
updateKnownHosts(remoteHost, remotePort);
|
2023-01-02 21:06:33 +01:00
|
|
|
}
|
|
|
|
// Check Script before
|
|
|
|
if (scriptBefore) {
|
2023-04-18 17:24:01 -04:00
|
|
|
await remoteCmdBefore(scriptBefore, privateKeyPath, scriptBeforeRequired);
|
2023-01-02 21:06:33 +01:00
|
|
|
}
|
|
|
|
/* eslint-disable object-property-newline */
|
|
|
|
await sshDeploy({
|
|
|
|
source, rsyncServer, exclude, remotePort,
|
|
|
|
privateKeyPath, args, sshCmdArgs
|
2020-04-11 16:29:20 +02:00
|
|
|
});
|
2023-01-02 21:06:33 +01:00
|
|
|
// Check script after
|
|
|
|
if (scriptAfter) {
|
2023-04-18 17:24:01 -04:00
|
|
|
await remoteCmdAfter(scriptAfter, privateKeyPath, scriptAfterRequired);
|
2023-01-02 21:06:33 +01:00
|
|
|
}
|
2019-10-02 23:52:52 +02:00
|
|
|
};
|
|
|
|
|
2023-01-02 21:06:33 +01:00
|
|
|
run()
|
|
|
|
.then((data = '') => {
|
|
|
|
console.log('✅ [DONE]', data);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('❌ [ERROR]', error.message);
|
|
|
|
process.exit(1);
|
|
|
|
});
|