-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #40.
- Loading branch information
Showing
4 changed files
with
81 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*! | ||
* Copyright © 2023 United States Government as represented by the | ||
* Administrator of the National Aeronautics and Space Administration. | ||
* All Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import Dockerode from 'dockerode' | ||
|
||
const [, , command, jsonifiedArgs] = process.argv | ||
|
||
if (command === 'launch-docker-subprocess') { | ||
const dockerContainer = await launchDockerSearch() | ||
|
||
const signals = ['message', 'SIGTERM', 'SIGINT'] | ||
signals.forEach((signal) => { | ||
process.on(signal, async () => { | ||
await dockerContainer.kill() | ||
}) | ||
}) | ||
|
||
await dockerContainer.wait() | ||
} | ||
|
||
async function launchDockerSearch() { | ||
const { dataDir, logsDir, engine, port, options } = JSON.parse(jsonifiedArgs) | ||
const Image = | ||
engine === 'elasticsearch' | ||
? 'elastic/elasticsearch:8.6.2' | ||
: 'opensearchproject/opensearch:2.11.0' | ||
console.log('Launching Docker container', Image) | ||
const docker = new Dockerode() | ||
|
||
const container = await docker.createContainer({ | ||
Env: [...options, 'path.data=/var/lib/search', 'path.logs=/var/log/search'], | ||
HostConfig: { | ||
AutoRemove: true, | ||
Mounts: [ | ||
{ Source: dataDir, Target: '/var/lib/search', Type: 'bind' }, | ||
{ Source: logsDir, Target: '/var/log/search', Type: 'bind' }, | ||
], | ||
PortBindings: { | ||
[`${port}/tcp`]: [{ HostIP: '127.0.0.1', HostPort: `${port}` }], | ||
}, | ||
}, | ||
Image, | ||
}) | ||
const stream = await container.attach({ stream: true, stderr: true }) | ||
stream.pipe(process.stderr) | ||
await container.start() | ||
return container | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"extends": "@tsconfig/node14/tsconfig.json", | ||
"compilerOptions": { | ||
"resolveJsonModule": true | ||
"resolveJsonModule": true, | ||
"module": "esnext", | ||
"target": "es2022" | ||
} | ||
} |