From 720a7efbb2fe355300bd4dddbd17df6958e94f16 Mon Sep 17 00:00:00 2001 From: Court Ewing Date: Fri, 22 Jul 2016 14:26:37 -0400 Subject: [PATCH] Backport PR #7317 --------- **Commit 1:** Apply -snapshot suffix during build task The default behavior of the build task is to now apply the -snapshot suffix dynamically rather than us manually hardcoding and managing it within the source code itself. The `--release` flag will drop the -snapshot suffix on a build, which should be used for any release candidate. The default behavior of the build task has also changed to create rpm/deb packages as well. Since we've only confirmed that this works on linux, you can override that behavior by passing `skip-os-packages`. If you do not want to create any zip or tar.gz archives, you can pass `--skip-archives`. * Original sha: 834f56392ed08b14e1c7bde43320f88633087de9 * Authored by Court Ewing on 2016-05-27T20:40:57Z --- CONTRIBUTING.md | 4 ++-- Gruntfile.js | 5 ++++- README.md | 2 +- package.json | 3 +-- tasks/build/getProps.js | 7 ------ tasks/build/index.js | 7 +++--- tasks/build/osPackages.js | 42 ++++++++++++++++++----------------- tasks/build/packageJson.js | 7 +++--- tasks/build/shasums.js | 3 +++ tasks/build/versionedLinks.js | 5 +---- tasks/config/build.js | 15 +++++++++++++ tasks/config/packages.js | 2 +- tasks/config/platforms.js | 2 +- 13 files changed, 58 insertions(+), 46 deletions(-) delete mode 100644 tasks/build/getProps.js create mode 100644 tasks/config/build.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e858f2e20c21b..00a4abb440b3d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -139,12 +139,12 @@ Packages are built using fpm, pleaserun, dpkg, and rpm. fpm and pleaserun can b apt-get install ruby-dev rpm gem install fpm -v 1.5.0 gem install pleaserun -v 0.0.24 -npm run build:ospackages +npm run build -- --skip-archives ``` To specify a package to build you can add `rpm` or `deb` as an argument. ```sh -npm run build:ospackages -- --rpm +npm run build -- --rpm ``` Distributable packages can be found in `target/` after the build completes. diff --git a/Gruntfile.js b/Gruntfile.js index 568917fa74200..d04aded254600 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -8,7 +8,7 @@ module.exports = function (grunt) { pkg: grunt.file.readJSON('package.json'), root: __dirname, src: __dirname + '/src', - build: __dirname + '/build', // temporary build directory + buildDir: __dirname + '/build', // temporary build directory plugins: __dirname + '/src/plugins', server: __dirname + '/src/server', target: __dirname + '/target', // location of the compressed build targets @@ -65,6 +65,9 @@ module.exports = function (grunt) { grunt.config.merge(config); + // must run before even services/platforms + grunt.config.set('build', require('./tasks/config/build')(grunt)); + config.packageScriptsDir = __dirname + '/tasks/build/package_scripts'; // ensure that these run first, other configs need them config.services = require('./tasks/config/services')(grunt); diff --git a/README.md b/README.md index 1111d4d207427..3d3105b86203b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Kibana 4.6.0-snapshot +# Kibana 4.6.0 [![Build Status](https://travis-ci.org/elastic/kibana.svg?branch=master)](https://travis-ci.org/elastic/kibana?branch=master) diff --git a/package.json b/package.json index b019ae1508b6e..97dd9c8f50d4e 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dashboarding" ], "private": false, - "version": "4.6.0-snapshot", + "version": "4.6.0", "build": { "number": 8467, "sha": "6cb7fec4e154faa0a4a3fee4b33dfef91b9870d9" @@ -49,7 +49,6 @@ "test:server": "grunt test:server", "test:coverage": "grunt test:coverage", "build": "grunt build", - "build:ospackages": "grunt build --os-packages", "start": "./bin/kibana --dev", "precommit": "grunt precommit", "karma": "karma start", diff --git a/tasks/build/getProps.js b/tasks/build/getProps.js deleted file mode 100644 index 458139b7df9d8..0000000000000 --- a/tasks/build/getProps.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = function (grunt) { - var exec = require('child_process').execSync; - grunt.registerTask('_build:getProps', function () { - grunt.config.set('buildSha', String(exec('git rev-parse HEAD')).trim()); - grunt.config.set('buildNum', parseFloat(String(exec('git log --format="%h" | wc -l')).trim())); - }); -}; diff --git a/tasks/build/index.js b/tasks/build/index.js index 1930f60c69012..60b11508fac48 100644 --- a/tasks/build/index.js +++ b/tasks/build/index.js @@ -3,7 +3,6 @@ module.exports = function (grunt) { grunt.registerTask('build', 'Build packages', function () { grunt.task.run(flatten([ - '_build:getProps', 'clean:build', 'clean:target', '_build:downloadNodeBuilds:start', @@ -24,11 +23,11 @@ module.exports = function (grunt) { 'stop:optimizeBuild', '_build:downloadNodeBuilds:finish', '_build:versionedLinks', - '_build:archives', - grunt.option('os-packages') ? [ + grunt.option('skip-archives') ? [] : ['_build:archives'], + grunt.option('skip-os-packages') ? [] : [ '_build:pleaseRun', '_build:osPackages', - ] : [], + ], '_build:shasums' ])); }); diff --git a/tasks/build/osPackages.js b/tasks/build/osPackages.js index fa79a8331ed3d..55fe5880d44cd 100644 --- a/tasks/build/osPackages.js +++ b/tasks/build/osPackages.js @@ -3,16 +3,18 @@ import { indexBy } from 'lodash'; import exec from '../utils/exec'; export default (grunt) => { - const targetDir = grunt.config.get('target'); + const { config } = grunt; + const exec = require('../utils/exec'); + const targetDir = config.get('target'); const packageScriptsDir = grunt.config.get('packageScriptsDir'); - const servicesByName = indexBy(grunt.config.get('services'), 'name'); - const config = grunt.config.get('packages'); + const servicesByName = indexBy(config.get('services'), 'name'); + const packages = config.get('packages'); const fpm = args => exec('fpm', args); grunt.registerTask('_build:osPackages', function () { grunt.file.mkdir(targetDir); - grunt.config.get('platforms') + config.get('platforms') .filter(({ name }) => /linux-x(86|64)$/.test(name)) .map(({ name, buildDir }) => { const architecture = /x64$/.test(name) ? 'x86_64' : 'i386'; @@ -27,25 +29,25 @@ export default (grunt) => { '--package', targetDir, '-s', 'dir', // input type '--architecture', architecture, - '--name', config.name, - '--description', config.description, - '--version', config.version, - '--url', config.site, - '--vendor', config.vendor, - '--maintainer', config.maintainer, - '--license', config.license, + '--name', packages.name, + '--description', packages.description, + '--version', packages.version, + '--url', packages.site, + '--vendor', packages.vendor, + '--maintainer', packages.maintainer, + '--license', packages.license, '--after-install', resolve(packageScriptsDir, 'post_install.sh'), '--before-install', resolve(packageScriptsDir, 'pre_install.sh'), '--before-remove', resolve(packageScriptsDir, 'pre_remove.sh'), '--after-remove', resolve(packageScriptsDir, 'post_remove.sh'), - '--config-files', config.path.kibanaConfig, - '--template-value', `user=${config.user}`, - '--template-value', `group=${config.group}`, - '--template-value', `optimizeDir=${config.path.home}/optimize`, - '--template-value', `pluginsDir=${config.path.plugins}`, - '--template-value', `dataDir=${config.path.data}`, + '--config-files', packages.path.kibanaConfig, + '--template-value', `user=${packages.user}`, + '--template-value', `group=${packages.group}`, + '--template-value', `optimizeDir=${packages.path.home}/optimize`, + '--template-value', `pluginsDir=${packages.path.plugins}`, + '--template-value', `dataDir=${packages.path.data}`, //uses relative path to --prefix, strip the leading / - '--exclude', `${config.path.home.slice(1)}/data` + '--exclude', `${packages.path.home.slice(1)}/data` ]; const debOptions = [ '-t', 'deb', @@ -56,8 +58,8 @@ export default (grunt) => { '--rpm-os', 'linux' ]; const args = [ - `${buildDir}/=${config.path.home}/`, - `${buildDir}/data/=${config.path.data}/`, + `${buildDir}/=${packages.path.home}/`, + `${buildDir}/data/=${packages.path.data}/`, `${servicesByName.sysv.outputDir}/etc/=/etc/`, `${servicesByName.systemd.outputDir}/etc/=/etc/` ]; diff --git a/tasks/build/packageJson.js b/tasks/build/packageJson.js index 3f61e724033d6..a9038a2dd6d5b 100644 --- a/tasks/build/packageJson.js +++ b/tasks/build/packageJson.js @@ -5,6 +5,7 @@ module.exports = function (grunt) { let deepModules = grunt.config.get('deepModules'); grunt.registerTask('_build:packageJson', function () { + const { sha, number, version } = grunt.config.get('build'); grunt.file.write( 'build/kibana/package.json', @@ -12,10 +13,10 @@ module.exports = function (grunt) { name: pkg.name, description: pkg.description, keywords: pkg.keywords, - version: pkg.version, + version, build: { - number: grunt.config.get('buildNum'), - sha: grunt.config.get('buildSha') + number, + sha }, repository: pkg.repository, engines: { diff --git a/tasks/build/shasums.js b/tasks/build/shasums.js index 7071c3e1f1d79..edc22edd3a21a 100644 --- a/tasks/build/shasums.js +++ b/tasks/build/shasums.js @@ -6,6 +6,9 @@ module.exports = function (grunt) { grunt.registerTask('_build:shasums', function () { var targetDir = grunt.config.get('target'); + // for when shasums is run but archives and ospackages was not + grunt.file.mkdir(targetDir); + readdir(targetDir) .map(function (archive) { // only sha the archives and packages diff --git a/tasks/build/versionedLinks.js b/tasks/build/versionedLinks.js index 449321bd009ad..876c977fe2132 100644 --- a/tasks/build/versionedLinks.js +++ b/tasks/build/versionedLinks.js @@ -12,10 +12,7 @@ module.exports = function (grunt) { return resolve(rootPath, file); }); - //We don't want to build os packages with symlinks - let transferFiles = (source, link) => grunt.option('os-packages') - ? exec('cp', ['-r', source, link]) - : exec('ln', ['-s', source, link]); + let transferFiles = (source, link) => exec('cp', ['-r', source, link]); grunt.config.get('platforms').forEach(function (platform) { grunt.file.mkdir(platform.buildDir); diff --git a/tasks/config/build.js b/tasks/config/build.js new file mode 100644 index 0000000000000..c1778cd4dbf8e --- /dev/null +++ b/tasks/config/build.js @@ -0,0 +1,15 @@ +import { execSync as exec } from 'child_process'; + +export default (grunt) => { + const pkgVersion = grunt.config.get('pkg.version'); + + const sha = String(exec('git rev-parse HEAD')).trim(); + const number = parseFloat(String(exec('git log --format="%h" | wc -l')).trim()); + const version = buildVersion(grunt.option('release'), pkgVersion); + + return { sha, number, version }; +}; + +function buildVersion(isRelease, version) { + return isRelease ? version : `${version}-snapshot`; +} diff --git a/tasks/config/packages.js b/tasks/config/packages.js index 2aa45957ec4cc..9501f9d829b88 100644 --- a/tasks/config/packages.js +++ b/tasks/config/packages.js @@ -1,5 +1,5 @@ export default (grunt) => { - const VERSION = grunt.config.get('pkg.version'); + const VERSION = grunt.config.get('build.version'); const FOLDER_STAGING = `kibana/staging/${VERSION.match(/\d\.\d\.\d/)[0]}-XXXXXXX/repos/${VERSION.match(/\d\./)[0]}x`; const FOLDER_PRODUCTION = `kibana/${VERSION.match(/\d\./)[0]}x`; diff --git a/tasks/config/platforms.js b/tasks/config/platforms.js index 4a39f1b7dcc32..2874f0d894957 100644 --- a/tasks/config/platforms.js +++ b/tasks/config/platforms.js @@ -1,7 +1,7 @@ module.exports = function (grunt) { let { resolve } = require('path'); - let version = grunt.config.get('pkg.version'); + let { version } = grunt.config.get('build'); let nodeVersion = grunt.config.get('nodeVersion'); let rootPath = grunt.config.get('root'); let baseUri = `https://nodejs.org/dist/v${nodeVersion}`;