Skip to content

Commit

Permalink
Fall back to Docker for sandbox mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Nov 27, 2023
1 parent 1518385 commit ee70c14
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
3 changes: 2 additions & 1 deletion install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 33 additions & 9 deletions run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'-it',
'-p',
`${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'],
})

Expand Down

0 comments on commit ee70c14

Please sign in to comment.