Skip to content

Commit

Permalink
[build] Cleanup packages task
Browse files Browse the repository at this point in the history
  • Loading branch information
jbudz committed May 27, 2016
1 parent 8f0be48 commit db5ac1e
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions tasks/build/os_packages.js
Expand Up @@ -8,19 +8,24 @@ module.exports = function (grunt) {
const packageScriptsDir = config.get('packageScriptsDir');
const servicesByName = indexBy(config.get('services'), 'name');
const packageConfig = config.get('packages');
const fpm = args => exec('fpm', args);

grunt.registerTask('_build:osPackages', function () {
config.get('platforms').forEach(({ name, buildDir }) => {
// TODO(sissel): Check if `fpm` is available
if (!(/linux-x(86|64)$/.test(name))) return;

const arch = /x64$/.test(name) ? 'x86_64' : 'i386';
const fpm = args => exec('fpm', args);

const args = [
config.get('platforms')
.filter(({ name }) => /linux-x(86|64)$/.test(name))
.map(({ name, buildDir }) => {
const architecture = /x64$/.test(name) ? 'x86_64' : 'i386';
return {
buildDir,
architecture
};
})
.forEach(({ buildDir, architecture }) => {
const baseOptions = [
'--force',
'--package', targetDir,
'-s', 'dir', // input type
'--architecture', architecture,
'--name', packageConfig.name,
'--description', packageConfig.description,
'--version', packageConfig.version,
Expand All @@ -40,27 +45,30 @@ module.exports = function (grunt) {
//uses relative path to --prefix, strip the leading /
'--exclude', `${packageConfig.path.home.slice(1)}/config`
];

const files = [
const debOptions = [
'-t', 'deb',
'--deb-priority', 'optional'
];
const rpmOptions = [
'-t', 'rpm',
'--rpm-os', 'linux'
];
const args = [
`${buildDir}/=${packageConfig.path.home}/`,
`${buildDir}/config/=${packageConfig.path.conf}/`,
`${servicesByName.sysv.outputDir}/etc/=/etc/`,
`${servicesByName.systemd.outputDir}/lib/=/lib/`
];

//Manually find flags, multiple args without assignment are not entirely parsed
var flags = grunt.option.flags().join(',');

const buildDeb = !!flags.match('deb');
const buildRpm = !!flags.match('rpm');
const noneSpecified = !buildRpm && !buildDeb;

grunt.file.mkdir(targetDir);
if (buildDeb || noneSpecified) {
fpm(args.concat('-t', 'deb', '--deb-priority', 'optional', '-a', arch, files));
const flags = grunt.option.flags().join(',');
const buildDeb = flags.includes('deb') || !flags.length;
const buildRpm = flags.includes('rpm') || !flags.length;
if (buildDeb) {
fpm([...baseOptions, ...debOptions, ...args]);
}
if (buildRpm || noneSpecified) {
fpm(args.concat('-t', 'rpm', '-a', arch, '--rpm-os', 'linux', files));
if (buildRpm) {
fpm([...baseOptions, ...rpmOptions, ...args]);
}

});
Expand Down

0 comments on commit db5ac1e

Please sign in to comment.