From 6c6293dc440f472c7021668d6dc72865656e2492 Mon Sep 17 00:00:00 2001 From: Ronit Agarwala Date: Fri, 17 Nov 2023 16:32:29 -0500 Subject: [PATCH 1/3] Change local search server installation. Change from Elastic Search to Open Search. --- index.ts | 4 ++-- install.ts | 36 +++++++++++++++++++++++------------- package-lock.json | 3 +++ run.ts | 11 +++++------ 4 files changed, 33 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..dd36635 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,24 @@ 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 configPath = join( + extractPath, + `opensearch-${version}`, + 'config', + 'opensearch.yml' ) + await writeFile(configPath, 'plugins.security.disabled: true\n', { + flag: 'w', + }) + 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/package-lock.json b/package-lock.json index cf7aeb9..e309700 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,9 @@ "lint-staged": "^13.1.2", "npm-run-all": "^4.1.5", "prettier": "^3.0.0" + }, + "engines": { + "node": ">=18" } }, "node_modules/@esbuild/android-arm": { diff --git a/run.ts b/run.ts index d915157..9bfff29 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,6 @@ export class LocalElasticSearch { `-Epath.logs=${logsDir}`, `-Ehttp.port=${port}`, '-Ediscovery.type=single-node', - '-Expack.security.enabled=false', ] console.log('Spawning', bin, ...args) @@ -70,12 +69,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 +93,7 @@ export class LocalElasticSearch { } export async function launch( - ...args: Parameters + ...args: Parameters ) { - return await LocalElasticSearch.launch(...args) + return await LocalOpenSearch.launch(...args) } From ff4943f3398d0bfab8bc50b986281c087b2adc58 Mon Sep 17 00:00:00 2001 From: Ronit Agarwala Date: Mon, 20 Nov 2023 23:29:02 -0500 Subject: [PATCH 2/3] Remove code to disable security plugin --- install.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/install.ts b/install.ts index dd36635..2069d8b 100644 --- a/install.ts +++ b/install.ts @@ -61,15 +61,6 @@ export async function install() { 'bin', `opensearch${binExt}` ) - const configPath = join( - extractPath, - `opensearch-${version}`, - 'config', - 'opensearch.yml' - ) - await writeFile(configPath, 'plugins.security.disabled: true\n', { - flag: 'w', - }) const binPathExists = await exists(binPath) From 258a93fd71b06e6550e89b871d3d2a5fee15cb2a Mon Sep 17 00:00:00 2001 From: Ronit Agarwala Date: Tue, 21 Nov 2023 10:51:27 -0500 Subject: [PATCH 3/3] Add command line argument to disable security plugin --- run.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/run.ts b/run.ts index 9bfff29..dec69e2 100644 --- a/run.ts +++ b/run.ts @@ -55,6 +55,7 @@ export class LocalOpenSearch { `-Epath.logs=${logsDir}`, `-Ehttp.port=${port}`, '-Ediscovery.type=single-node', + '-Eplugins.security.disabled=true', ] console.log('Spawning', bin, ...args)