ssh rsync deployment

This commit is contained in:
Evert Prants 2020-12-13 12:48:48 +02:00
parent 7bccb06f60
commit 7554048339
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 49 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@squeebot/cli", "name": "@squeebot/cli",
"version": "3.0.1", "version": "3.0.2",
"description": "Squeebot v3 runtime, environments and configuration", "description": "Squeebot v3 runtime, environments and configuration",
"main": "dist/squeebot.js", "main": "dist/squeebot.js",
"bin": { "bin": {
@ -29,7 +29,7 @@
"typescript": "^4.0.5" "typescript": "^4.0.5"
}, },
"dependencies": { "dependencies": {
"@squeebot/core": "^3.0.1", "@squeebot/core": "^3.1.0",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"node-watch": "^0.7.0", "node-watch": "^0.7.0",
"tar": "^6.0.5", "tar": "^6.0.5",

View File

@ -44,9 +44,11 @@ function execute(cmd: any[], loc: string): Promise<void> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const cproc = child_process.spawn(cmd[0], cmd.slice(1), { const cproc = child_process.spawn(cmd[0], cmd.slice(1), {
cwd: loc, cwd: loc,
stdio: 'pipe',
}); });
cproc.stdout.pipe(process.stdout);
cproc.stderr.pipe(process.stderr);
cproc.on('exit', (code: number) => { cproc.on('exit', (code: number) => {
if (code !== 0) { if (code !== 0) {
return reject(new Error('Build failed!')); return reject(new Error('Build failed!'));
@ -135,6 +137,43 @@ async function newRepository(
console.log('\nDone! Your repository "%s" lives at:', name, location); console.log('\nDone! Your repository "%s" lives at:', name, location);
} }
async function sshDeploy(
outDir: string,
sshconf: any): Promise<void> {
const key = sshconf.key;
const host = sshconf.host;
const username = sshconf.user;
const port = sshconf.port || 22;
const target = sshconf.target;
const args = sshconf.args || '-rltgoDzvO';
if (!key || !host || !username || !target) {
console.error('SSH deployment requires more arguments.');
return;
}
console.log('Deploying to %s@%s:%d%s', username, host, port, target);
const fileList = (await fs.readdir(outDir)).filter((val) => {
return val === 'repository.json' || val.match('.tgz$');
}).map((x) => path.join(outDir, x));
const pargs = [
'rsync',
args,
'-e',
`ssh -i ${key} -p ${port}`,
...fileList,
`${username}@${host}:${target}`,
];
console.log(pargs.join(' '));
await execute(pargs, outDir);
console.log('Done!');
}
async function deploy( async function deploy(
name: string, name: string,
location: string, location: string,
@ -182,6 +221,13 @@ async function deploy(
console.log('Done!'); console.log('Done!');
} }
if (deployment in meta) {
const dpl = meta[deployment];
if (dpl.ssh) {
await sshDeploy(outDir, dpl);
}
}
} }
async function buildRepository( async function buildRepository(