This repository has been archived by the owner on Mar 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We can now use promo download urls in allowedValues.json
- patches the install bash script through `npm run build` - the build validates these short links point to a debian package - also validate they point to the right version of the deb package to prevent copy pasta errors. - gulp tasks are now in separate files
- Loading branch information
Showing
8 changed files
with
253 additions
and
144 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 |
---|---|---|
@@ -1,137 +1 @@ | ||
var gulp = require("gulp"); | ||
var eclint = require("eclint"); | ||
var jsonlint = require("gulp-jsonlint"); | ||
var zip = require("gulp-zip"); | ||
var dateFormat = require("dateformat"); | ||
var jsonfile = require('jsonfile'); | ||
var _ = require('lodash'); | ||
var addsrc = require('gulp-add-src'); | ||
|
||
var phantomjs = require('phantomjs-prebuilt') | ||
var casperJs = require('gulp-casperjs'); | ||
|
||
jsonfile.spaces = 2; | ||
process.env["PHANTOMJS_EXECUTABLE"] = phantomjs.path; | ||
console.log(process.env["PHANTOMJS_EXECUTABLE"]) | ||
|
||
gulp.task("patch", function(cb) { | ||
jsonfile.readFile("../src/allowedValues.json", function(err, obj) { | ||
var versions = _.keys(obj.versions); | ||
var esToKibanaMapping = _.mapValues(obj.versions, function(v) { | ||
return v.kibana; | ||
}); | ||
var vmSizes = obj.vmSizes; | ||
var dataNodeValues = _.range(1, obj.numberOfDataNodes + 1) | ||
.filter(function(i) { return i <= 12 || (i % 5) == 0; }) | ||
.map(function (i) { return { "label" : i + "", value : i }}); | ||
var clientNodeValues = _.range(1, obj.numberOfClientNodes + 1) | ||
.filter(function(i) { return i <= 12 || (i % 5) == 0; }) | ||
.map(function (i) { return { "label" : i + "", value : i }}); | ||
|
||
var mainTemplate = "../src/mainTemplate.json"; | ||
var uiTemplate = "../src/createUiDefinition.json"; | ||
|
||
jsonfile.readFile(mainTemplate, function(err, obj) { | ||
|
||
var dataSkus = _.keys(obj.variables.dataSkuSettings); | ||
var difference = _.difference(vmSizes, dataSkus); | ||
|
||
if (difference.length > 0) { | ||
console.error("Not all vm sizes are property mapped as dataSku's: [" + difference.join(",") + "]"); | ||
process.exit(1); | ||
} | ||
|
||
obj.variables.esToKibanaMapping = esToKibanaMapping; | ||
obj.parameters.esVersion.allowedValues = versions; | ||
obj.parameters.esVersion.defaultValue = _.last(versions); | ||
obj.parameters.vmSizeDataNodes.allowedValues = vmSizes; | ||
obj.parameters.vmSizeMasterNodes.allowedValues = vmSizes; | ||
obj.parameters.vmSizeClientNodes.allowedValues = vmSizes; | ||
obj.parameters.vmSizeKibana.allowedValues = vmSizes; | ||
jsonfile.writeFile(mainTemplate, obj, function (err) { | ||
jsonfile.readFile(uiTemplate, function(err, obj) { | ||
|
||
//patch allowed versions on the cluster step | ||
var clusterStep = _.find(obj.parameters.steps, function (step) { | ||
return step.name == "clusterSettingsStep"; | ||
}); | ||
var versionControl = _.find(clusterStep.elements, function (el) { | ||
return el.name == "esVersion"; | ||
}); | ||
versionControl.constraints.allowedValues = _.map(versions, function(v) { | ||
return { label: "v" + v, value : v}; | ||
}); | ||
versionControl.defaultValue = "v" + _.last(versions); | ||
|
||
//patch allowedVMSizes on the nodesStep | ||
var nodesStep = _.find(obj.parameters.steps, function (step) { return step.name == "nodesStep"; }); | ||
var externalAccessStep = _.find(obj.parameters.steps, function (step) { return step.name == "externalAccessStep"; }); | ||
|
||
var masterSizeControl = _.find(nodesStep.elements, function (el) { return el.name == "vmSizeMasterNodes"; }); | ||
var dataSizeControl = _.find(nodesStep.elements, function (el) { return el.name == "vmSizeDataNodes"; }); | ||
var clientSizeControl = _.find(nodesStep.elements, function (el) { return el.name == "vmSizeClientNodes"; }); | ||
var kibanaSizeControl = _.find(externalAccessStep.elements, function (el) { return el.name == "vmSizeKibana"; }); | ||
var patchVmSizes = function(control) { control.constraints.allowedValues = vmSizes; } | ||
patchVmSizes(masterSizeControl); | ||
patchVmSizes(dataSizeControl); | ||
patchVmSizes(clientSizeControl); | ||
patchVmSizes(kibanaSizeControl); | ||
|
||
var dataNodeCountControl = _.find(nodesStep.elements, function (el) { return el.name == "vmDataNodeCount"; }); | ||
dataNodeCountControl.constraints.allowedValues = dataNodeValues; | ||
var clientNodeCountControl = _.find(nodesStep.elements, function (el) { return el.name == "vmDataNodeCount"; }); | ||
clientNodeCountControl.constraints.allowedValues = clientNodeValues; | ||
|
||
jsonfile.writeFile(uiTemplate, obj, function (err) { | ||
cb(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
var spawn = require('child_process').spawn; | ||
var gutil = require('gulp-util'); | ||
|
||
gulp.task("headless", function () { | ||
var tests = ['../build/ui-tests/runner.js']; | ||
var casperChild = spawn('../node_modules/casperjs/bin/casperjs.exe', tests); | ||
|
||
casperChild.stderr.on('data', function (data) { | ||
gutil.log('CasperJS:', data.toString().slice(0, -1)); | ||
}); | ||
casperChild.stdout.on('data', function (data) { | ||
gutil.log('CasperJS:', data.toString().slice(0, -1)); | ||
}); | ||
|
||
casperChild.on('close', function (code) { | ||
var success = code === 0; // Will be 1 in the event of failure | ||
|
||
// Do something with success here | ||
}); | ||
}); | ||
|
||
|
||
|
||
gulp.task("default", ["patch"], function() { | ||
var stream = gulp.src([ | ||
"../src/**/*.json" | ||
]) | ||
.pipe(jsonlint()) | ||
.pipe(jsonlint.reporter()) | ||
.pipe(eclint.check({ | ||
reporter: function(file, message) { | ||
//var relativePath = path.relative(".", file.path); | ||
console.error(file.path + ":", message); | ||
} | ||
})) | ||
.pipe(jsonlint.failAfterError()) | ||
.pipe(addsrc.append(["../src/**/*.sh"])) | ||
.pipe(zip("elasticsearch-marketplace" + dateFormat(new Date(), "-yyyymmdd-HHMMss-Z").replace("+","-") +".zip")) | ||
.pipe(gulp.dest("../dist")); | ||
; | ||
stream.on("finish", function() { | ||
}); | ||
return stream; | ||
}); | ||
require('requiredir')('tasks', { recurse: true }) |
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,26 @@ | ||
var gulp = require("gulp"); | ||
var eclint = require("eclint"); | ||
var jsonlint = require("gulp-jsonlint"); | ||
var zip = require("gulp-zip"); | ||
var dateFormat = require("dateformat"); | ||
var addsrc = require('gulp-add-src'); | ||
|
||
gulp.task("default", ["patch"], function() { | ||
var stream = gulp.src(["../src/**/*.json"]) | ||
.pipe(jsonlint()) | ||
.pipe(jsonlint.reporter()) | ||
.pipe(eclint.check({ | ||
reporter: function(file, message) { | ||
//var relativePath = path.relative(".", file.path); | ||
console.error(file.path + ":", message); | ||
} | ||
})) | ||
.pipe(jsonlint.failAfterError()) | ||
.pipe(addsrc.append(["../src/**/*.sh"])) | ||
.pipe(zip("elasticsearch-marketplace" + dateFormat(new Date(), "-yyyymmdd-HHMMss-Z").replace("+","-") +".zip")) | ||
.pipe(gulp.dest("../dist")) | ||
|
||
stream.on("finish", function() {}); | ||
|
||
return stream; | ||
}); |
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,27 @@ | ||
var gulp = require("gulp"); | ||
var phantomjs = require('phantomjs-prebuilt') | ||
var casperJs = require('gulp-casperjs'); | ||
var spawn = require('child_process').spawn; | ||
var gutil = require('gulp-util'); | ||
|
||
process.env["PHANTOMJS_EXECUTABLE"] = phantomjs.path; | ||
console.log(process.env["PHANTOMJS_EXECUTABLE"]) | ||
|
||
|
||
gulp.task("headless", function () { | ||
var tests = ['../build/ui-tests/runner.js']; | ||
var casperChild = spawn('../node_modules/casperjs/bin/casperjs.exe', tests); | ||
|
||
casperChild.stderr.on('data', function (data) { | ||
gutil.log('CasperJS:', data.toString().slice(0, -1)); | ||
}); | ||
casperChild.stdout.on('data', function (data) { | ||
gutil.log('CasperJS:', data.toString().slice(0, -1)); | ||
}); | ||
|
||
casperChild.on('close', function (code) { | ||
var success = code === 0; // Will be 1 in the event of failure | ||
|
||
// Do something with success here | ||
}); | ||
}); |
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,78 @@ | ||
var gulp = require("gulp"); | ||
var gutil = require('gulp-util'); | ||
var jsonfile = require('jsonfile'); | ||
var _ = require('lodash'); | ||
var replace = require('gulp-replace'); | ||
var request = require('request'); | ||
|
||
jsonfile.spaces = 2; | ||
|
||
var mainTemplate = "../src/mainTemplate.json"; | ||
var uiTemplate = "../src/createUiDefinition.json"; | ||
var installElasticsearchBash = "../src/scripts/elasticsearch-ubuntu-install.sh"; | ||
|
||
var allowedValues = require('../allowedValues.json'); | ||
|
||
function expandUrl(shortUrl, cb) { | ||
request( { method: "HEAD", url: shortUrl, followAllRedirects: true }, | ||
function (error, response) { | ||
cb(response.request.href); | ||
}); | ||
} | ||
|
||
gulp.task('link-checker', function (cb) { | ||
var urls = _.keys(allowedValues.versions) | ||
.map(function(k) { return { version: k, url: allowedValues.versions[k].downloadUrl } }) | ||
.filter(function(v) { return !!v.url }) | ||
|
||
var called = urls.length; | ||
var urlsCallback = function(error) { called--; if (called == 0 || error) cb(error); }; | ||
var expandUrl = function (shortUrl, v) { | ||
request( { method: "HEAD", url: shortUrl, followAllRedirects: true }, | ||
function (error, response) { | ||
if (error) | ||
{ | ||
var error = "downloadUrl: " + shortUrl + "returned error:" + error; | ||
urlsCallback(new gutil.PluginError('test', error, {showStack: false})); | ||
process.exit(1); | ||
return; | ||
} | ||
var expandedUrl = response.request.href | ||
var matches = expandedUrl.match(/org\/elasticsearch\/distribution\/deb\/elasticsearch\/(.+)\/elasticsearch-(.+)\.deb/); | ||
if (!matches.length) | ||
{ | ||
console.error("downloadUrl: " + shortUrl + " does not expand to a debian package but:" + expandedUrl); | ||
urlsCallback(); | ||
process.exit(1); | ||
return; | ||
} | ||
if (matches[1] != v.version) | ||
{ | ||
var error = "downloadUrl: " + shortUrl + " expands to a debian package but not to expected version:"+ v.version+" instead we saw:" + expandedUrl; | ||
urlsCallback(new gutil.PluginError('test', error, {showStack: false})); | ||
process.exit(1); | ||
return; | ||
} | ||
urlsCallback(); | ||
}); | ||
}; | ||
urls.forEach(function (v) { expandUrl(v.url, v)}); | ||
|
||
}); | ||
|
||
gulp.task('bash-patch', [ "link-checker" ], function(cb){ | ||
var elifs = 0; | ||
var branches = _.keys(allowedValues.versions) | ||
.filter(function(k) { return !!allowedValues.versions[k].downloadUrl }) | ||
.map(function (k) { | ||
var v = allowedValues.versions[k]; | ||
var command = (elifs == 0) ? "if" : "elif"; | ||
elifs++; | ||
return " " + command +" [[ \"${ES_VERSION}\" == \"" + k + "\"]]; then\r\n DOWNLOAD_URL=\"" +v.downloadUrl+ "\"\r\n"; | ||
}); | ||
var ifStatements = branches.join("") | ||
|
||
return gulp.src([installElasticsearchBash]) | ||
.pipe(replace(/(\#begin telemetry.*)[\s\S]+(\#end telemetry.*)/g, "$1\r\n" + ifStatements + " $2")) | ||
.pipe(gulp.dest("../src/scripts/", { overwrite: true })); | ||
}); |
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,99 @@ | ||
var gulp = require("gulp"); | ||
var jsonfile = require('jsonfile'); | ||
var _ = require('lodash'); | ||
var replace = require('gulp-replace'); | ||
|
||
jsonfile.spaces = 2; | ||
|
||
var mainTemplate = "../src/mainTemplate.json"; | ||
var uiTemplate = "../src/createUiDefinition.json"; | ||
var installElasticsearchBash = "../src/scripts/elasticsearch-ubuntu-install.sh"; | ||
|
||
var allowedValues = require('../allowedValues.json'); | ||
var versions = _.keys(allowedValues.versions); | ||
var esToKibanaMapping = _.mapValues(allowedValues.versions, function(v) { return v.kibana; }); | ||
var vmSizes = allowedValues.vmSizes; | ||
var dataNodeValues = _.range(1, allowedValues.numberOfDataNodes + 1) | ||
.filter(function(i) { return i <= 12 || (i % 5) == 0; }) | ||
.map(function (i) { return { "label" : i + "", value : i }}); | ||
var clientNodeValues = _.range(1, allowedValues.numberOfClientNodes + 1) | ||
.filter(function(i) { return i <= 12 || (i % 5) == 0; }) | ||
.map(function (i) { return { "label" : i + "", value : i }}); | ||
|
||
gulp.task('bash-patch', function(){ | ||
var elifs = 0; | ||
var branches = _.keys(allowedValues.versions) | ||
.filter(function(k) { return !!allowedValues.versions[k].downloadUrl }) | ||
.map(function (k) { | ||
var v = allowedValues.versions[k]; | ||
var command = (elifs == 0) ? "if" : "elif"; | ||
elifs++; | ||
return " " + command +" [[ \"${ES_VERSION}\" == \"" + k + "\"]]; then\r\n DOWNLOAD_URL=\"" +v.downloadUrl+ "\"\r\n"; | ||
}); | ||
var ifStatements = branches.join("") | ||
|
||
return gulp.src([installElasticsearchBash]) | ||
.pipe(replace(/(\#begin telemetry.*)[\s\S]+(\#end telemetry.*)/g, "$1\r\n" + ifStatements + " $2")) | ||
.pipe(gulp.dest("../src/scripts/", { overwrite: true })); | ||
}); | ||
|
||
gulp.task("patch", ['link-checker', 'bash-patch'], function(cb) { | ||
|
||
jsonfile.readFile(mainTemplate, function(err, obj) { | ||
|
||
var dataSkus = _.keys(obj.variables.dataSkuSettings); | ||
var difference = _.difference(vmSizes, dataSkus); | ||
|
||
if (difference.length > 0) { | ||
console.error("Not all vm sizes are property mapped as dataSku's: [" + difference.join(",") + "]"); | ||
process.exit(1); | ||
} | ||
|
||
obj.variables.esToKibanaMapping = esToKibanaMapping; | ||
obj.parameters.esVersion.allowedValues = versions; | ||
obj.parameters.esVersion.defaultValue = _.last(versions); | ||
obj.parameters.vmSizeDataNodes.allowedValues = vmSizes; | ||
obj.parameters.vmSizeMasterNodes.allowedValues = vmSizes; | ||
obj.parameters.vmSizeClientNodes.allowedValues = vmSizes; | ||
obj.parameters.vmSizeKibana.allowedValues = vmSizes; | ||
jsonfile.writeFile(mainTemplate, obj, function (err) { | ||
jsonfile.readFile(uiTemplate, function(err, obj) { | ||
|
||
//patch allowed versions on the cluster step | ||
var clusterStep = _.find(obj.parameters.steps, function (step) { | ||
return step.name == "clusterSettingsStep"; | ||
}); | ||
var versionControl = _.find(clusterStep.elements, function (el) { | ||
return el.name == "esVersion"; | ||
}); | ||
versionControl.constraints.allowedValues = _.map(versions, function(v) { | ||
return { label: "v" + v, value : v}; | ||
}); | ||
versionControl.defaultValue = "v" + _.last(versions); | ||
|
||
//patch allowedVMSizes on the nodesStep | ||
var nodesStep = _.find(obj.parameters.steps, function (step) { return step.name == "nodesStep"; }); | ||
var externalAccessStep = _.find(obj.parameters.steps, function (step) { return step.name == "externalAccessStep"; }); | ||
|
||
var masterSizeControl = _.find(nodesStep.elements, function (el) { return el.name == "vmSizeMasterNodes"; }); | ||
var dataSizeControl = _.find(nodesStep.elements, function (el) { return el.name == "vmSizeDataNodes"; }); | ||
var clientSizeControl = _.find(nodesStep.elements, function (el) { return el.name == "vmSizeClientNodes"; }); | ||
var kibanaSizeControl = _.find(externalAccessStep.elements, function (el) { return el.name == "vmSizeKibana"; }); | ||
var patchVmSizes = function(control) { control.constraints.allowedValues = vmSizes; } | ||
patchVmSizes(masterSizeControl); | ||
patchVmSizes(dataSizeControl); | ||
patchVmSizes(clientSizeControl); | ||
patchVmSizes(kibanaSizeControl); | ||
|
||
var dataNodeCountControl = _.find(nodesStep.elements, function (el) { return el.name == "vmDataNodeCount"; }); | ||
dataNodeCountControl.constraints.allowedValues = dataNodeValues; | ||
var clientNodeCountControl = _.find(nodesStep.elements, function (el) { return el.name == "vmDataNodeCount"; }); | ||
clientNodeCountControl.constraints.allowedValues = clientNodeValues; | ||
|
||
jsonfile.writeFile(uiTemplate, obj, function (err) { | ||
cb(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.