From 8442cb984f3e4d2ab4c2560ad1f0ee628556dbbb Mon Sep 17 00:00:00 2001 From: ronitagarwala01 <34790361+ronitagarwala01@users.noreply.github.com> Date: Tue, 21 Nov 2023 11:36:27 -0500 Subject: [PATCH] Change local search engine installation. (#18) Fixes #16. --- index.ts | 4 ++-- install.ts | 27 ++++++++++++++------------- run.ts | 12 ++++++------ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/index.ts b/index.ts index 82e6eed..21e6043 100644 --- a/index.ts +++ b/index.ts @@ -7,7 +7,7 @@ */ import { launch } from './run.js' -import type { LocalElasticSearch } from './run.js' +import type { LocalOpenSearch } from './run.js' import { populate } from './data.js' import { cloudformationResources as serverlessCloudformationResources, @@ -58,7 +58,7 @@ export const deploy = { }, } -let local: LocalElasticSearch +let local: LocalOpenSearch export const sandbox = { async start({ diff --git a/install.ts b/install.ts index b919556..2069d8b 100644 --- a/install.ts +++ b/install.ts @@ -13,35 +13,35 @@ import fetch from 'make-fetch-happen' import { Extract as unzip } from 'unzip-stream' import { x as untar } from 'tar' import { cache, exists, mkdirP } from './paths.js' +import { writeFile } from 'fs/promises' -const version = '8.6.2' +const version = '2.11.0' const types = new Map([ ['Linux', ['linux', 'tar.gz']], - ['Darwin', ['darwin', 'tar.gz']], ['Windows_NT', ['windows', 'zip']], ]) -const archs = new Map([ - ['x64', 'x86_64'], - ['arm64', 'aarch64'], -]) +const archs = ['x64', 'arm64'] function getFilename() { const os_type = os.type() const os_arch = os.arch() const typeInfo = types.get(os_type) - const arch = archs.get(os_arch) - if (!typeInfo || !arch) { + if ( + !typeInfo || + !archs.includes(os_arch) || + (os_type === 'Windows_NT' && os_arch === 'arm64') + ) { throw new Error( - `No ElasticSearch binary is available for your OS type (${os_type}) and architecture (${os_arch}). For supported operating systems, see https://www.elastic.co/downloads/elasticsearch.` + `No OpenSearch binary is available for your OS type (${os_type}) and architecture (${os_arch}). For supported operating systems, see https://opensearch.org/versions/opensearch-2-11-0.html.` ) } const [type, ext] = typeInfo - return { name: `elasticsearch-${version}-${type}-${arch}`, ext } + return { name: `opensearch-${version}-${type}-${os_arch}`, ext } } async function download(url: string) { @@ -57,14 +57,15 @@ export async function install() { const binExt = os.type() === 'Windows_NT' ? '.bat' : '' const binPath = join( extractPath, - `elasticsearch-${version}`, + `opensearch-${version}`, 'bin', - `elasticsearch${binExt}` + `opensearch${binExt}` ) + const binPathExists = await exists(binPath) if (!binPathExists) { - const url = `https://artifacts.elastic.co/downloads/elasticsearch/${name}.${ext}` + const url = `https://artifacts.opensearch.org/releases/bundle/opensearch/${version}/${name}.${ext}` const stream = await download(url) let extract diff --git a/run.ts b/run.ts index d915157..dec69e2 100644 --- a/run.ts +++ b/run.ts @@ -21,7 +21,7 @@ import { import { pipeline } from 'stream/promises' import { createReadStream } from 'fs' -export class LocalElasticSearch { +export class LocalOpenSearch { private readonly child!: ChildProcess private readonly tempDir!: string readonly port!: number @@ -55,7 +55,7 @@ export class LocalElasticSearch { `-Epath.logs=${logsDir}`, `-Ehttp.port=${port}`, '-Ediscovery.type=single-node', - '-Expack.security.enabled=false', + '-Eplugins.security.disabled=true', ] console.log('Spawning', bin, ...args) @@ -70,12 +70,12 @@ export class LocalElasticSearch { ]) } catch (e) { await pipeline( - createReadStream(join(logsDir, 'elasticsearch.log')), + createReadStream(join(logsDir, 'opensearch.log')), process.stderr ) throw e } - console.log('ElasticSearch is ready at', url) + console.log('OpenSearch is ready at', url) } catch (e) { await rimraf(tempDir) throw e @@ -94,7 +94,7 @@ export class LocalElasticSearch { } export async function launch( - ...args: Parameters + ...args: Parameters ) { - return await LocalElasticSearch.launch(...args) + return await LocalOpenSearch.launch(...args) }