cli/src/build/repository/deployment/ssh.ts

49 lines
1.1 KiB
TypeScript

import fs from 'fs-extra';
import path from 'path';
import { execute } from '../../execute';
/**
* Deploy using ssh and rsync
* @param outDir Repoistory output
* @param sshconf ssh deployment configuration
*/
export 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) =>
val === 'repository.json'
|| val.endsWith('.tgz')
|| val.endsWith('schema.json')
).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!');
}