ssh-deploy/src/index.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-10-02 23:52:52 +02:00
#!/usr/bin/env node
const { sshDeploy } = require('./rsyncCli');
const { remoteCmdBefore, remoteCmdAfter } = require('./remoteCmd');
2023-01-02 11:41:31 +01:00
const { addSshKey, getPrivateKeyPath } = require('./sshKey');
const { validateRequiredInputs } = require('./helpers');
const inputs = require('./inputs');
2019-10-02 23:52:52 +02:00
2023-01-02 12:57:35 +01:00
const run = async () => {
const {
source, remoteUser, remoteHost, remotePort,
deployKeyName, sshPrivateKey,
2023-01-02 01:33:48 +01:00
args, exclude, sshCmdArgs,
scriptBefore, scriptAfter,
2023-01-02 02:13:02 +01:00
rsyncServer
} = inputs;
// Validate required inputs
validateRequiredInputs({ sshPrivateKey, remoteHost, remoteUser });
// Add SSH key
2023-01-02 11:41:31 +01:00
addSshKey(sshPrivateKey, deployKeyName);
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
// Check Script before
if (scriptBefore) {
2023-01-02 12:57:35 +01:00
await remoteCmdBefore(scriptBefore);
}
2023-01-02 12:57:35 +01:00
/* eslint-disable object-property-newline */
2023-01-02 12:57:35 +01:00
await sshDeploy({
2023-01-02 02:13:02 +01:00
source, rsyncServer, exclude, remotePort,
2023-01-02 12:57:35 +01:00
privateKeyPath, args, sshCmdArgs
});
2023-01-02 12:57:35 +01:00
// Check script after
if (scriptAfter) {
await remoteCmdAfter(scriptAfter);
}
2019-10-02 23:52:52 +02:00
};
2023-01-02 12:57:35 +01:00
run()
.then(() => {
console.log('DONE');
})
.catch(() => {
console.error('ERROR');
});