Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
307e024
Start docker cli
Ikuni17 Jun 27, 2023
eeaa4f9
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jun 28, 2023
3a1c84e
Base docker command kind of working
Ikuni17 Jun 30, 2023
623c2d6
Expand CLI options
Ikuni17 Jun 30, 2023
d4f9c38
Derive isDocker
Ikuni17 Jun 30, 2023
988fa0c
Change Docker params to single quoted string. Cleanup logging
Ikuni17 Jun 30, 2023
ee22e63
WIP default cmd setup
Ikuni17 Jul 1, 2023
e362822
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 1, 2023
558526c
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 4, 2023
f17feba
Fix console for docker. Setup consts snapshots and versions
Ikuni17 Jul 4, 2023
70762ce
Add docker cmd and img resolutions. improve logging and examples
Ikuni17 Jul 5, 2023
2da1964
WIP docker log parsing
Ikuni17 Jul 6, 2023
4960514
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 6, 2023
7efb57d
Fix stderr output
Ikuni17 Jul 6, 2023
aa557ff
Combine log files and tests.
Ikuni17 Jul 6, 2023
28bfd7f
Add non json test
Ikuni17 Jul 6, 2023
35d7ee2
Remove non-capture fn
Ikuni17 Jul 6, 2023
e880721
wip serverless commands
Ikuni17 Jul 9, 2023
8c4f2c2
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 9, 2023
249cbb3
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 10, 2023
84a9856
Add verify docker method
Ikuni17 Jul 11, 2023
ef2ceca
Restructure
Ikuni17 Jul 12, 2023
39d68d5
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 12, 2023
441caae
Add serverless command and networks setup
Ikuni17 Jul 12, 2023
a08fe58
Cleanup logging
Ikuni17 Jul 12, 2023
8a00034
Add local volume setup and clean flag
Ikuni17 Jul 12, 2023
3153036
Cleanup volume logging
Ikuni17 Jul 13, 2023
8536aad
Cleanup network logging
Ikuni17 Jul 13, 2023
2f21f90
WIP runServerlessEsNode
Ikuni17 Jul 13, 2023
679398c
Logging and param cleanup
Ikuni17 Jul 13, 2023
3625e8a
Fix es_java_opts
Ikuni17 Jul 13, 2023
923432c
Fix es_java_opts
Ikuni17 Jul 13, 2023
a240473
Enable rm. Fixed node roles
Ikuni17 Jul 13, 2023
9f919b7
Logging fixes for succ
Ikuni17 Jul 14, 2023
c170d1e
Cleanup constants, consistency between serverless and docker cli
Ikuni17 Jul 14, 2023
95684ee
Fix image resolution for both.
Ikuni17 Jul 14, 2023
da3f5ef
Cleanup
Ikuni17 Jul 14, 2023
703ae94
Restructure cluster
Ikuni17 Jul 14, 2023
23e3b38
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 14, 2023
3d1ce70
Cleanup
Ikuni17 Jul 14, 2023
99cd96f
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 14, 2023
357110b
Adjust var name
Ikuni17 Jul 14, 2023
39e6786
Prefix ports with localhost
Ikuni17 Jul 14, 2023
cdef8d2
Switch log style to file. inherit stdio
Ikuni17 Jul 14, 2023
5810b07
Combine docker run into _exec
Ikuni17 Jul 14, 2023
6a1e754
Merge branch 'feature/159260/kbn-es-docker' of github.com:Ikuni17/kib…
Ikuni17 Jul 14, 2023
144af4b
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 17, 2023
7d1e16e
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 18, 2023
d780922
Centralize and cleanup serverless logic into utils
Ikuni17 Jul 18, 2023
52b015e
Use promise.all
Ikuni17 Jul 18, 2023
e1525fb
Split docker out again
Ikuni17 Jul 18, 2023
cb1094e
Remove unused docker cli options
Ikuni17 Jul 18, 2023
70aeb45
cleanup
Ikuni17 Jul 19, 2023
639d5ae
Merge remote-tracking branch 'origin/main' into feature/159260/kbn-es…
Ikuni17 Jul 19, 2023
7966d00
Cleanup cli, reporting
Ikuni17 Jul 19, 2023
a9f6578
Comments
Ikuni17 Jul 19, 2023
87af604
Use .es dir instead of data
Ikuni17 Jul 19, 2023
e23ffd6
adjust logs cmnd
Ikuni17 Jul 19, 2023
8d7d910
Add support for overriding esargs
Ikuni17 Jul 19, 2023
039a809
Resolve esargs for docker. Support pw
Ikuni17 Jul 19, 2023
9661259
Verify image is from elastic registry
Ikuni17 Jul 19, 2023
3fd028c
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 19, 2023
33f526e
Update readme
Ikuni17 Jul 20, 2023
177a69e
Merge remote-tracking branch 'origin/main' into feature/159260/kbn-es…
Ikuni17 Jul 20, 2023
b62184a
resolve image tests
Ikuni17 Jul 21, 2023
75064ac
wip setupDocker tests
Ikuni17 Jul 21, 2023
aeb4b2e
Add test files
Ikuni17 Jul 21, 2023
16b888f
resolveEsArgs tests
Ikuni17 Jul 21, 2023
ecf2c32
setup volumes tests
Ikuni17 Jul 21, 2023
55971a7
resolveDockerCmd tests
Ikuni17 Jul 21, 2023
ba9f199
Verify docker installed tests
Ikuni17 Jul 21, 2023
79fb477
maybe create network tests
Ikuni17 Jul 21, 2023
bd8f7ea
wip run serverless node tests
Ikuni17 Jul 22, 2023
ef64ed8
fix log output for serverless node
Ikuni17 Jul 22, 2023
9667ecd
add serverless cluster tests. cleanup mockFs hooks
Ikuni17 Jul 22, 2023
b836e17
runDockercontainer tests
Ikuni17 Jul 22, 2023
733dbc0
Merge remote-tracking branch 'origin/main' into feature/159260/kbn-es…
Ikuni17 Jul 22, 2023
2a9bf11
Adjust image help text
Ikuni17 Jul 22, 2023
a87765d
cleanup
Ikuni17 Jul 22, 2023
663a1f6
Merge branch 'main' into feature/159260/kbn-es-docker
mistic Jul 22, 2023
02423f6
Merge branch 'main' into feature/159260/kbn-es-docker
mistic Jul 24, 2023
fb1e8b9
Adjust docker env variables. Fix socket issue
Ikuni17 Jul 25, 2023
7171c63
Revert parseEsDockerLog
Ikuni17 Jul 25, 2023
3407aa2
Merge remote-tracking branch 'origin/main' into feature/159260/kbn-es…
Ikuni17 Jul 25, 2023
0dc386e
Merge branch 'main' into feature/159260/kbn-es-docker
Ikuni17 Jul 25, 2023
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
14 changes: 13 additions & 1 deletion packages/kbn-es/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ date: 2022-05-24
tags: ['kibana', 'dev', 'contributor', 'operations', 'es']
---

> A command line utility for running elasticsearch from snapshot, source, archive or even building snapshot artifacts.
> A command line utility for running elasticsearch from snapshot, source, archive, docker, serverless or even building snapshot artifacts.

## Getting started
If running elasticsearch from source, elasticsearch needs to be cloned to a sibling directory of Kibana.

If running elasticsearch serverless or a docker container, docker is required to be installed locally. Installation instructions can be found [here](https://www.docker.com/).

To run, go to the Kibana root and run `node scripts/es --help` to get the latest command line options.

The script attempts to preserve the existing interfaces used by Elasticsearch CLI. This includes passing through options with the `-E` argument and the `ES_JAVA_OPTS` environment variable for Java options.
Expand All @@ -28,6 +30,16 @@ Run from source with a configured data directory
node scripts/es source --Epath.data=/home/me/es_data
```

Run serverless with a specific image tag
```
node scripts/es serverless --tag git-fec36430fba2-x86_64
```

Run an official Docker release
```
node scripts/es docker --tag 8.8.2
```

## API

### run
Expand Down
67 changes: 67 additions & 0 deletions packages/kbn-es/src/cli_commands/docker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import dedent from 'dedent';
import getopts from 'getopts';
import { ToolingLog } from '@kbn/tooling-log';
import { getTimeReporter } from '@kbn/ci-stats-reporter';

import { Cluster } from '../cluster';
import { DOCKER_IMG, DOCKER_REPO, DOCKER_TAG } from '../utils';
import { Command } from './types';

export const docker: Command = {
description: 'Run an Elasticsearch Docker image',
usage: 'es docker [<args>]',
help: (defaults: Record<string, any> = {}) => {
const { password } = defaults;

return dedent`
Options:

--tag Image tag of ES to run from ${DOCKER_REPO} [default: ${DOCKER_TAG}]
--image Full path to image of ES to run, has precedence over tag. [default: ${DOCKER_IMG}]
--password Sets password for elastic user [default: ${password}]
-E Additional key=value settings to pass to Elasticsearch
-D Override Docker command

Examples:

es docker --tag master-SNAPSHOT-amd64
es docker --image docker.elastic.co/repo:tag
es docker -D 'start es01'
`;
},
run: async (defaults = {}) => {
const runStartTime = Date.now();
const log = new ToolingLog({
level: 'info',
writeTo: process.stdout,
});
const reportTime = getTimeReporter(log, 'scripts/es docker');

const argv = process.argv.slice(2);
const options = getopts(argv, {
alias: {
esArgs: 'E',
dockerCmd: 'D',
},

string: ['tag', 'image', 'D'],

default: defaults,
});

const cluster = new Cluster();
await cluster.runDocker({
reportTime,
startTime: runStartTime,
...options,
});
},
};
4 changes: 4 additions & 0 deletions packages/kbn-es/src/cli_commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import { snapshot } from './snapshot';
import { source } from './source';
import { archive } from './archive';
import { buildSnapshots } from './build_snapshots';
import { docker } from './docker';
import { serverless } from './serverless';

export const commands = {
snapshot,
source,
archive,
build_snapshots: buildSnapshots,
docker,
serverless,
};
64 changes: 64 additions & 0 deletions packages/kbn-es/src/cli_commands/serverless.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import dedent from 'dedent';
import getopts from 'getopts';
import { ToolingLog } from '@kbn/tooling-log';
import { getTimeReporter } from '@kbn/ci-stats-reporter';

import { Cluster } from '../cluster';
import { SERVERLESS_REPO, SERVERLESS_TAG, SERVERLESS_IMG } from '../utils';
import { Command } from './types';

export const serverless: Command = {
description: 'Run Serverless Elasticsearch through Docker',
usage: 'es serverless [<args>]',
help: (defaults: Record<string, any> = {}) => {
return dedent`
Options:

--tag Image tag of ES Serverless to run from ${SERVERLESS_REPO} [default: ${SERVERLESS_TAG}]
--image Full path of ES Serverless image to run, has precedence over tag. [default: ${SERVERLESS_IMG}]
--clean Remove existing file system object store before running
-E Additional key=value settings to pass to Elasticsearch

Examples:

es serverless --tag git-fec36430fba2-x86_64
es serverless --image docker.elastic.co/repo:tag
`;
},
run: async (defaults = {}) => {
const runStartTime = Date.now();
const log = new ToolingLog({
level: 'info',
writeTo: process.stdout,
});
const reportTime = getTimeReporter(log, 'scripts/es serverless');

const argv = process.argv.slice(2);
const options = getopts(argv, {
alias: {
basePath: 'base-path',
esArgs: 'E',
},

string: ['tag', 'image'],
boolean: ['clean'],

default: defaults,
});

const cluster = new Cluster();
await cluster.runServerless({
reportTime,
startTime: runStartTime,
...options,
});
},
};
34 changes: 32 additions & 2 deletions packages/kbn-es/src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const {
extractConfigFiles,
NativeRealm,
parseTimeoutToMs,
runServerlessCluster,
runDockerContainer,
} = require('./utils');
const { createCliError } = require('./errors');
const { promisify } = require('util');
Expand All @@ -31,6 +33,8 @@ const { CA_CERT_PATH, ES_NOPASSWORD_P12_PATH, extract } = require('@kbn/dev-util
const DEFAULT_READY_TIMEOUT = parseTimeoutToMs('1m');

/** @typedef {import('./cluster_exec_options').EsClusterExecOptions} ExecOptions */
/** @typedef {import('./utils').DockerOptions} DockerOptions */
/** @typedef {import('./utils').ServerlessOptions}ServerlessrOptions */

// listen to data on stream until map returns anything but undefined
const first = (stream, map) =>
Expand Down Expand Up @@ -467,7 +471,7 @@ exports.Cluster = class Cluster {
if (stdioTarget) {
stdioTarget.write(chunk);
} else {
this._log.error(chalk.red());
this._log.error(chalk.red(chunk.trim()));
}
});

Expand All @@ -483,7 +487,7 @@ exports.Cluster = class Cluster {
});
}

// observe the exit code of the process and reflect in _outcome promies
// observe the exit code of the process and reflect in _outcome promises
const exitCode = new Promise((resolve) => this._process.once('exit', resolve));
this._outcome = exitCode.then((code) => {
if (this._stopCalled) {
Expand Down Expand Up @@ -558,4 +562,30 @@ exports.Cluster = class Cluster {
}
return esJavaOpts.trim();
}

/**
* Run an Elasticsearch Serverless Docker cluster
*
* @param {ServerlessOptions} options
*/
async runServerless(options = {}) {
if (this._process || this._outcome) {
throw new Error('ES has already been started');
}

await runServerlessCluster(this._log, options);
}

/**
* Run an Elasticsearch Docker container
*
* @param {DockerOptions} options
*/
async runDocker(options = {}) {
if (this._process || this._outcome) {
throw new Error('ES has already been started');
}

this._process = await runDockerContainer(this._log, options);
}
};
2 changes: 1 addition & 1 deletion packages/kbn-es/src/cluster_exec_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface EsClusterExecOptions {
skipNativeRealmSetup?: boolean;
reportTime?: (...args: any[]) => void;
startTime?: number;
esArgs?: string[];
esArgs?: string[] | string;
esJavaOpts?: string;
password?: string;
skipReadyCheck?: boolean;
Expand Down
Loading