Skip to content

Commit d1eaf29

Browse files
committed
Updated build commands, set the revision based on the date of the latest commit and set the dependencies based on the variables of the provisioning files
1 parent cf12096 commit d1eaf29

File tree

4 files changed

+71
-13
lines changed

4 files changed

+71
-13
lines changed

Gruntfile.js

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ module.exports = function (grunt) {
2424
var gypCompileCmd = "node-gyp configure build";
2525
var gypCleanCmd = "node-gyp clean";
2626
var pkgdata = require('./package.json');
27+
var yaml = require('js-yaml');
28+
var fs = require('fs');
29+
var varfile = [];
30+
31+
try {
32+
varfile = yaml.safeLoad(fs.readFileSync('provisioning/vars.yml', 'utf8'));
33+
} catch (e) {
34+
grunt.log.error(e);
35+
}
36+
2737
var currentArch = (function() {
2838
if (process.arch == 'ia32')
2939
return 'i386';
@@ -33,6 +43,44 @@ module.exports = function (grunt) {
3343
return "noarch";
3444
})();
3545

46+
function getDate () {
47+
var execSync = require("child_process").execSync;
48+
var rawtimestamp;
49+
try {
50+
rawtimestamp = execSync("git show -s --format=%ct HEAD");
51+
} catch (e) {
52+
grunt.log.write(e.message);
53+
rawtimestamp = 0;
54+
}
55+
var date = new Date(Number(rawtimestamp) * 1000);
56+
var dateFields = {
57+
year: date.getUTCFullYear(),
58+
month: date.getUTCMonth() + 1, // months are zero based by default
59+
day: date.getUTCDate(),
60+
hours: date.getUTCHours(),
61+
minutes: date.getUTCMinutes(),
62+
seconds: date.getUTCSeconds()
63+
}
64+
return String(dateFields.year) +
65+
padStr(dateFields.month) +
66+
padStr(dateFields.day) +
67+
padStr(dateFields.hours) +
68+
padStr(dateFields.minutes) +
69+
padStr(dateFields.seconds);
70+
}
71+
function padStr (num) {
72+
return ('00' + num).slice(-2)
73+
}
74+
function getDepends (list) {
75+
var auxlist = [];
76+
auxlist.push("nodejs >= 4.4.0");
77+
auxlist.push("python-httplib2");
78+
for (var i = 0; i < list.length; i++) {
79+
if (!list[i].match(/.*-devel/g))
80+
auxlist.push(list[i]);
81+
}
82+
return auxlist;
83+
}
3684
function nodeGypShell(cmd, cwd) {
3785
return {
3886
options: {
@@ -94,11 +142,16 @@ module.exports = function (grunt) {
94142
"sudo rm -f -r /var/lib/gpii"
95143
].join("&&")
96144
},
97-
prepareRpmEnv: {
98-
command: "dnf install -y nodejs-grunt-cli npm alsa-lib-devel json-glib-devel PackageKit-glib-devel libXrandr-devel libgnome-keyring-devel sudo @development-tools rpmdevtools"
99-
},
100145
buildRpmDocker: {
101-
command: "docker run --rm -i -v $(pwd):/sync fedora /bin/bash -c 'dnf install -y nodejs-grunt-cli; cp -r /sync /packages; cd /packages; grunt build-rpm; cp -r /packages/bin /sync'"
146+
command: "docker run --rm -i -v $(pwd):/sync fedora:23 /bin/bash -c '" +
147+
"dnf install -y ansible python2-dnf git sudo fedora-packager @development-tools;" +
148+
"cp -r /sync /packages; cd /packages;" +
149+
"ansible-galaxy install -fr /packages/provisioning/requirements.yml;" +
150+
"ansible-playbook /packages/provisioning/playbook.yml --tags=\"install\";" +
151+
"npm install; grunt build-rpm; cp -r /packages/bin /sync'"
152+
},
153+
npmInstall: {
154+
command: "npm install"
102155
},
103156
runAcceptanceTests: {
104157
command: "vagrant ssh -c 'DISPLAY=:0 node /home/vagrant/sync/tests/AcceptanceTests.js'"
@@ -109,18 +162,15 @@ module.exports = function (grunt) {
109162
},
110163
easy_rpm: {
111164
options: {
112-
release: 1,
165+
release: getDate(),
113166
summary: pkgdata.description,
114167
rpmDestination: "bin",
115168
tempDir: "bin/tmp",
116169
keepTemp: true,
117-
license: pkgdata.licenses[0].type,
170+
license: pkgdata.licenses,
118171
url: pkgdata.homepage,
119172
buildArch: currentArch,
120-
requires: [
121-
"nodejs >= 0.10.42",
122-
"python-httplib2"
123-
]
173+
requires: getDepends(varfile["nodejs_app_rpm_packages"]),
124174
},
125175
release: {
126176
files: [
@@ -191,7 +241,7 @@ module.exports = function (grunt) {
191241
grunt.task.run("shell:buildRpmDocker");
192242
});
193243
grunt.registerTask("build-rpm", "Build GPII Linux and RPM package", function () {
194-
grunt.task.run("shell:prepareRpmEnv");
244+
grunt.task.run("shell:npmInstall");
195245
grunt.task.run("build");
196246
grunt.task.run("easy_rpm");
197247
});

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ To build a RPM package run the following command at the root of the git reposito
6161
you will get the rpm package and the source files of the package in the ``bin``
6262
directory.
6363

64+
This command has been tested in a linux environment, to ensure that this process
65+
runs fine, exec it inside a linux box with Docker support.
66+
67+
_Note: It should work in the new Docker for Windows/OSX, because it use a third
68+
directory to build the application and the rpm, and finally copy the package to
69+
the directory of the repository, but it hasn't been tested jet._
70+
6471
# Setting Up a Virtual Machine
6572

6673
This repository contains content that will allow you to automatically provision a development VM. A [Vagrantfile](http://docs.vagrantup.com/v2/vagrantfile/) is provided that downloads a [Fedora Vagrant box](https://github.com/idi-ops/packer-fedora), starts a VM, and deploys the GPII Framework on it.

Vagrantfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Vagrant.configure(2) do |config|
5959
end
6060

6161
config.vm.provision "shell", inline: <<-SHELL
62-
sudo ansible-galaxy install -fr /home/vagrant/sync/provisioning/requirements.yml
63-
sudo PYTHONUNBUFFERED=1 ansible-playbook /home/vagrant/sync/provisioning/playbook.yml --tags="install,configure"
62+
sudo ansible-galaxy install -fr /home/vagrant/sync/provisioning/requirements.yml
63+
sudo PYTHONUNBUFFERED=1 ansible-playbook /home/vagrant/sync/provisioning/playbook.yml --tags="install,configure"
6464
SHELL
6565

6666
# Using config.vm.hostname to set the hostname on Fedora VMs seems to remove the string

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"grunt-contrib-jshint": "~0.9.0",
1313
"grunt-jsonlint": "1.0.4",
1414
"grunt-gpii": "git://github.com/GPII/grunt-gpii.git#ec8412064e107febb120f0b7437d403453b40d2d",
15+
"js-yaml": "~3.6.1",
1516
"nan": "^2.1.0"
1617
},
1718
"license" : "BSD-3-Clause",

0 commit comments

Comments
 (0)