Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove writeFile import in install.ts #22

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -58,7 +58,7 @@ export const deploy = {
},
}

let local: LocalElasticSearch
let local: LocalOpenSearch

export const sandbox = {
async start({
Expand Down
26 changes: 13 additions & 13 deletions install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,34 @@
import { Extract as unzip } from 'unzip-stream'
import { x as untar } from 'tar'
import { cache, exists, mkdirP } from './paths.js'

Check warning on line 16 in install.ts

View workflow job for this annotation

GitHub Actions / build / build (20, ubuntu-latest)

'writeFile' is defined but never used

Check warning on line 16 in install.ts

View workflow job for this annotation

GitHub Actions / build / build (18, ubuntu-latest)

'writeFile' is defined but never used

Check warning on line 16 in install.ts

View workflow job for this annotation

GitHub Actions / build / build (20, ubuntu-latest)

'writeFile' is defined but never used

Check warning on line 16 in install.ts

View workflow job for this annotation

GitHub Actions / build / build (18, ubuntu-latest)

'writeFile' is defined but never used
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) {
Expand All @@ -57,14 +56,15 @@
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
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -94,7 +94,7 @@ export class LocalElasticSearch {
}

export async function launch(
...args: Parameters<typeof LocalElasticSearch.launch>
...args: Parameters<typeof LocalOpenSearch.launch>
) {
return await LocalElasticSearch.launch(...args)
return await LocalOpenSearch.launch(...args)
}
Loading