[kbn/es] add --download
flag to snapshot command to warm the cache (#25830)
In order to pre-fetch Elasticsearch snapshots and avoid timeouts during download in images, this adds a `--download` option to the `es snapshot` command.
This commit is contained in:
parent
354d7cc431
commit
df8514fa09
|
@ -35,6 +35,7 @@ exports.help = (defaults = {}) => {
|
|||
--install-path Installation path, defaults to 'source' within base-path
|
||||
--password Sets password for elastic user [default: ${password}]
|
||||
-E Additional key=value settings to pass to Elasticsearch
|
||||
--download-only Download the snapshot but don't actually start it
|
||||
|
||||
Example:
|
||||
|
||||
|
@ -51,10 +52,16 @@ exports.run = async (defaults = {}) => {
|
|||
esArgs: 'E',
|
||||
},
|
||||
|
||||
boolean: ['download-only'],
|
||||
|
||||
default: defaults,
|
||||
});
|
||||
|
||||
const cluster = new Cluster();
|
||||
const { installPath } = await cluster.installSnapshot(options);
|
||||
await cluster.run(installPath, { esArgs: options.esArgs });
|
||||
if (options['download-only']) {
|
||||
await cluster.downloadSnapshot(options);
|
||||
} else {
|
||||
const { installPath } = await cluster.installSnapshot(options);
|
||||
await cluster.run(installPath, { esArgs: options.esArgs });
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
const execa = require('execa');
|
||||
const chalk = require('chalk');
|
||||
const { installSnapshot, installSource, installArchive } = require('./install');
|
||||
const { downloadSnapshot, installSnapshot, installSource, installArchive } = require('./install');
|
||||
const { ES_BIN } = require('./paths');
|
||||
const { log: defaultLog, parseEsLog, extractConfigFiles } = require('./utils');
|
||||
const { createCliError } = require('./errors');
|
||||
|
@ -50,6 +50,28 @@ exports.Cluster = class Cluster {
|
|||
return { installPath };
|
||||
}
|
||||
|
||||
/**
|
||||
* Download ES from a snapshot
|
||||
*
|
||||
* @param {Object} options
|
||||
* @property {Array} options.installPath
|
||||
* @property {Array} options.sourcePath
|
||||
* @returns {Promise<{installPath}>}
|
||||
*/
|
||||
async downloadSnapshot(options = {}) {
|
||||
this._log.info(chalk.bold('Downloading snapshot'));
|
||||
this._log.indent(4);
|
||||
|
||||
const { installPath } = await downloadSnapshot({
|
||||
log: this._log,
|
||||
...options,
|
||||
});
|
||||
|
||||
this._log.indent(-4);
|
||||
|
||||
return { installPath };
|
||||
}
|
||||
|
||||
/**
|
||||
* Download and installs ES from a snapshot
|
||||
*
|
||||
|
|
|
@ -19,4 +19,5 @@
|
|||
|
||||
exports.installArchive = require('./archive').installArchive;
|
||||
exports.installSnapshot = require('./snapshot').installSnapshot;
|
||||
exports.downloadSnapshot = require('./snapshot').downloadSnapshot;
|
||||
exports.installSource = require('./source').installSource;
|
||||
|
|
|
@ -27,6 +27,39 @@ const { BASE_PATH } = require('../paths');
|
|||
const { installArchive } = require('./archive');
|
||||
const { log: defaultLog, cache } = require('../utils');
|
||||
|
||||
/**
|
||||
* Download an ES snapshot
|
||||
*
|
||||
* @param {Object} options
|
||||
* @property {('oss'|'basic'|'trial')} options.license
|
||||
* @property {String} options.version
|
||||
* @property {String} options.basePath
|
||||
* @property {String} options.installPath
|
||||
* @property {ToolingLog} options.log
|
||||
*/
|
||||
exports.downloadSnapshot = async function installSnapshot({
|
||||
license = 'basic',
|
||||
version,
|
||||
basePath = BASE_PATH,
|
||||
installPath = path.resolve(basePath, version),
|
||||
log = defaultLog,
|
||||
}) {
|
||||
// TODO: remove -alpha1 once elastic/elasticsearch#35172 has been merged
|
||||
const fileName = getFilename(license, version + '-alpha1');
|
||||
const url = `https://snapshots.elastic.co/downloads/elasticsearch/${fileName}`;
|
||||
const dest = path.resolve(basePath, 'cache', fileName);
|
||||
|
||||
log.info('version: %s', chalk.bold(version));
|
||||
log.info('install path: %s', chalk.bold(installPath));
|
||||
log.info('license: %s', chalk.bold(license));
|
||||
|
||||
await downloadFile(url, dest, log);
|
||||
|
||||
return {
|
||||
downloadPath: dest,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Installs ES from snapshot
|
||||
*
|
||||
|
@ -46,17 +79,15 @@ exports.installSnapshot = async function installSnapshot({
|
|||
installPath = path.resolve(basePath, version),
|
||||
log = defaultLog,
|
||||
}) {
|
||||
// TODO: remove -alpha1 once elastic/elasticsearch#35172 has been merged
|
||||
const fileName = getFilename(license, version + '-alpha1');
|
||||
const url = `https://snapshots.elastic.co/downloads/elasticsearch/${fileName}`;
|
||||
const dest = path.resolve(basePath, 'cache', fileName);
|
||||
const { downloadPath } = await exports.downloadSnapshot({
|
||||
license,
|
||||
version,
|
||||
basePath,
|
||||
installPath,
|
||||
log,
|
||||
});
|
||||
|
||||
log.info('version: %s', chalk.bold(version));
|
||||
log.info('install path: %s', chalk.bold(installPath));
|
||||
log.info('license: %s', chalk.bold(license));
|
||||
|
||||
await downloadFile(url, dest, log);
|
||||
return await installArchive(dest, {
|
||||
return await installArchive(downloadPath, {
|
||||
license,
|
||||
password,
|
||||
basePath,
|
||||
|
|
Loading…
Reference in a new issue