UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

51 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const spawner_base_1 = require("./spawner-base"); const gnu_spawner_1 = require("./gnu-spawner"); const docker_spawner_1 = require("./docker-spawner"); const resolve_posix_path_1 = require("../util/resolve-posix-path"); const constants_1 = require("../constants"); const path_1 = require("path"); function SshDockerSpawner(config) { const resolvePath = resolve_posix_path_1.ResolvePosixPath(docker_spawner_1.APP_DIR); return gnu_spawner_1.GnuSpawner(Object.assign({ resolvePath }, spawner_base_1.SpawnerBase(translate))); function translate(cmd) { const exe = 'ssh'; const sshArgs = ['-i', constants_1.PRIVATE_KEY_FILE_PATH]; const expandablePath = path_1.posix.isAbsolute(config.path) ? config.path : `~/${config.path}`; const dockerArgs = [ 'docker', 'run', '--rm', '--privileged', '--interactive', '--network=host', '--volume', '/dev:/dev', '--volume', `${expandablePath}:${docker_spawner_1.APP_DIR}`, ]; if (cmd.tty) { sshArgs.push('-t'); dockerArgs.push('--tty'); } if (cmd.expose5000) { sshArgs.push('-L', '5000:0.0.0.0:5000'); } sshArgs.push(config.hostname); dockerArgs.push('--workdir', resolvePath(cmd.cwd), docker_spawner_1.IMAGE_NAME, cmd.exe); if (cmd.args) { dockerArgs.push(...cmd.args); } const translated = { exe, args: [...sshArgs, ...dockerArgs], input: cmd.input, }; return translated; } } exports.SshDockerSpawner = SshDockerSpawner; //# sourceMappingURL=ssh-docker-spawner.js.map