From 7ff5c96cfc6ccf5085e93a4fda9bc4c5ce36e4ae 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 --- data.ts | 3 ++- install.ts | 3 ++- run.ts | 42 +++++++++++++++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/data.ts b/data.ts index 3e6bcfb..544cc43 100644 --- a/data.ts +++ b/data.ts @@ -48,7 +48,8 @@ export async function populate(path: string, opts: ClientOptions) { const batch_size = 10 const batches = chunk(data, batch_size) for (const batch of batches) { - await client.bulk({ body: batch }) + const result = await client.bulk({ body: batch }) + console.log(result) } } } 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..ebc547f 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', + '-i', + '-p', + `${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'], })