From 15405fcd2e12d96cd070c56cdd27c49f40b48b05 Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Sun, 26 Nov 2023 23:18:41 -0500 Subject: [PATCH] Fall back to Docker for sandbox mode --- install.ts | 3 ++- run.ts | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/install.ts b/install.ts index 97758d5..0dae6ab 100644 --- a/install.ts +++ b/install.ts @@ -30,9 +30,10 @@ export async function install(engine: SandboxEngine) { entry.engine === engine && entry.arch === arch && entry.type === type )?.url if (!url) { - throw new Error( + console.warn( `No ${engine} binary is available for your OS type (${type}) and architecture (${arch}).` ) + return } const archiveFilename = posix diff --git a/run.ts b/run.ts index df3ac81..6a5d6ef 100644 --- a/run.ts +++ b/run.ts @@ -57,18 +57,42 @@ export class LocalSearch { const logsDir = join(tempDir, 'logs') await Promise.all([dataDir, logsDir].map(mkdirP)) - const args: string[] = [ - `-Epath.data=${dataDir}`, - `-Epath.logs=${logsDir}`, - `-Ehttp.port=${port}`, - '-Ediscovery.type=single-node', + let command + let args = [] + const opts = [ + `http.port=${port}`, + 'discovery.type=single-node', engine === 'elasticsearch' - ? '-Expack.security.enabled=false' - : '-Eplugins.security.disabled=true', + ? 'xpack.security.enabled=false' + : 'plugins.security.disabled=true', ] - console.log('Spawning', bin, ...args) - child = await spawn(bin, args, { + if (bin) { + command = bin + opts.push(`path.data=${dataDir}`, `path.logs=${logsDir}`) + args = opts.map((opt) => `-E${opt}`) + } else { + command = 'docker' + opts.push('path.data=/docker.data', 'path.logs=/docker.logs') + args = [ + 'run', + '--rm', + '-t', + '-p', + '127.0.0.1:${port}:${port}', + '-v', + `${dataDir}:/docker.data`, + '-v', + `${logsDir}:/docker.logs`, + ...opts.flatMap((opt) => ['-e', opt]), + engine === 'elasticsearch' + ? 'elastic/elasticsearch:8.6.2' + : 'opensearchproject/opensearch:2.11.0', + ] + } + + console.log('Spawning', command, ...args) + child = await spawn(command, args, { stdio: ['ignore', 'ignore', 'inherit'], })