Skip to content
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"makelogs": "makelogs",
"mocha": "mocha",
"mocha:debug": "mocha --debug-brk",
"sterilize": "grunt sterilize"
"sterilize": "grunt sterilize",
"es-start": "grunt es-start"
},
"repository": {
"type": "git",
Expand Down
82 changes: 82 additions & 0 deletions tasks/es-start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import childProcess from 'child_process';
import bluebird from 'bluebird';

const runCommand = bluebird.promisify(childProcess.exec);
const runFile = bluebird.promisify(childProcess.execFile);
const esRepo = `../elasticsearch/`;
const esDest = `${esRepo}distribution/tar/build/distributions/`;

/**
* EXPERIMENTAL
*
* Build ES from source and startup. It ensures Kibana and Elasticsearch share the same major branch.
*
* The setup requires Kibana and Elasticsearch are on the same directory level
*
* Limitations:
* - *NIX only.
* - X-plugins not yet supported
*
* @param grunt
*/
module.exports = function (grunt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export default


grunt.registerTask('es-start', async function () {

const taskDone = this.async();
const currentLocation = await runCommand('pwd');

try {
const kibanaTags = await runCommand('git tag');
const elasticTags = await runCommand(`cd ${esRepo} && git tag`);
const kibanaMajor = getMajorVersion(kibanaTags[0]);
const elasticsearchMajor = getMajorVersion(elasticTags[0]);

console.log('Ensuring major branches are the same.');
if (kibanaMajor !== elasticsearchMajor) {
const message = `Kibana and Elasticsearch must be on
the same major branch: Kibana=${kibanaMajor}, Elasticsearch=${elasticsearchMajor}`;
throw new Error(message);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on whether it should also do a git pull from the upstream repo?


if (kibanaMajor < 5) {
throw new Error('Must at least be at version 5');
}


console.log('Building Elasticsearch. This may take a while if this is the first time.');
try {
await runCommand('cd ../elasticsearch && gradle assemble -x test');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want gradle clean assemble here, which I believe will clean up old builds that may exist there from past build of previous snapshot versions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only plan to build and run we can also use gradle run

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command will build the docs as well, which takes a long time and isn't really needed. It will also build the zip distribution, which isn't used in this scirpt. Maybe change to:

gradle clean :distribution:tar:assemble

That will skip running the tests as well, which it looks like you want to do

} catch (e) {
throw new Error('Could not build ElasticSearch');
}

const distrib = await runCommand(`find ${esRepo}distribution/tar/build/distributions/elasticsearch*.tar.gz`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use ${esDest} here

const zipFile = distrib[0].trim();
console.log('Unpacking ES');
await runCommand(`tar -xzvf ${zipFile} -C ${esDest}`);


let esDistro = await runCommand(`find ${esDest} -name 'elasticsearch*' -type d`);
esDistro = esDistro[0].trim();
console.log('Starting ES');
await runFile(`${esDistro}/bin/elasticsearch`);
} catch (e) {
console.error('Cannot start Elasticsearch.');
console.error(e);
} finally {
console.log('Tearing down process');
await runCommand(`cd ${currentLocation}`);
taskDone(false);
}


});

};

function getMajorVersion(gitResponse) {
const lines = gitResponse.split('\n').filter(s => s.startsWith('v'));
const lastTag = lines[lines.length - 1].trim();
return parseInt(lastTag.substr(1, 1));
}