Skip to content
Snippets Groups Projects
Commit 0d5bb6da authored by Jan Mach's avatar Jan Mach
Browse files

Polishing of Gruntfile for better readability.

(Redmine issue: #3387)
parent ae6231f0
No related branches found
No related tags found
No related merge requests found
......@@ -23,14 +23,14 @@ module.exports = function(grunt) {
pkg: grunt.file.readJSON('package.json'),
meta: grunt.file.readJSON('meta.json'),
// Project paths to important directories
// Project paths to important directories.
project_paths: {
'deploy_dir': 'deploy/',
'package_dir': 'deploy/package/',
'control_dir': 'deploy/ctrl/',
'archive_dir': 'deploy/archive/'
},
// Paths related to DEB packages
// Paths related to DEB packages.
paths_deb: {
'bin_dir': 'usr/local/bin/',
'etc_dir': 'etc/mentat/',
......@@ -40,7 +40,7 @@ module.exports = function(grunt) {
},
// ---------------------------------------------------------------------
// Cleanup various destinations
// Cleanup various locations.
clean: {
// Cleanup package directory
build: {
......@@ -51,67 +51,71 @@ module.exports = function(grunt) {
},
// ---------------------------------------------------------------------
// Running shel commands
// Running shell commands.
shell: {
// Update NodeJS packages (Grunt, grunt plugins...)
npm: {
// Update NodeJS packages (Grunt and grunt plugins)
npm_update: {
command: 'npm update'
},
// Calculate directory size
// Calculate directory size, willbe used in DEB package metadata.
dir_size: {
command: '/usr/bin/du -k -s <%= project_paths.package_dir %> | /usr/bin/cut -f 1',
options: {
callback: cbk_dir_size
}
},
// Archive debian packages
archive_deb: {
// Archive previously built DEB packages from build directory.
deb_archive: {
command: 'if [[ -n $(find <%= project_paths.deploy_dir %> -maxdepth 1 -name *.deb) ]]; then mv -f <%= project_paths.deploy_dir %>*.deb <%= project_paths.archive_dir %>; fi;'
},
// Build debian package
build_deb: {
// Build DEB package.
deb_build: {
command: '/usr/bin/fakeroot /usr/bin/dpkg-deb --build <%= project_paths.package_dir %> <%= project_paths.deploy_dir %>' + deb_package_filename()
},
// Duplicate package from deb_package_filename() to deb_package_latest_filename()
duplicate_deb: {
// Duplicate package from deb_package_filename() to deb_package_latest_filename().
deb_duplicate: {
command: 'cp -f <%= project_paths.deploy_dir %>' + deb_package_filename() + ' <%= project_paths.deploy_dir %>' + deb_package_latest_filename()
},
// FTP deployment
ftp_deploy: {
command: 'lftp -f .lftp'
},
// SCP deployment
scp_deploy: {
// SCP deployment - upload built DEB packages to repository server.
deb_scp_upload_repo: {
command: '/usr/bin/scp <%= project_paths.deploy_dir %>' + deb_package_filename() + ' <%= meta.pkg_server %>:<%= meta.pkg_location %>/stable'
},
// SCP deployment to devel server
scp_deploy_dev: {
// SCP deployment - upload built DEB packages to development server.
deb_scp_upload_dev: {
command: '/usr/bin/scp <%= project_paths.deploy_dir %>' + deb_package_latest_filename() + ' <%= meta.dev_server %>:<%= meta.dev_location %>'
},
// DEB repo refresh
// SCP deployment - upload built DEB packages to demo server.
deb_scp_upload_demo: {
command: '/usr/bin/scp <%= project_paths.deploy_dir %>' + deb_package_latest_filename() + ' <%= meta.demo_server %>:<%= meta.demo_location %>'
},
// Refresh DEB repository metadata on repository server.
repo_refresh: {
command: '/usr/bin/ssh mach@<%= meta.pkg_server %> apt-update mentat'
},
// SSH install
ssh_apt_update: {
// Install latest package via APT on production server - step 1.
ssh_apt_update_prod: {
command: '/usr/bin/ssh root@<%= meta.dep_server %> aptitude update'
},
ssh_apt_upgrade: {
command: '/usr/bin/ssh root@<%= meta.dep_server %> aptitude upgrade'
},
ssh_apt_install: {
// Install latest package via APT on production server - step 2.
ssh_apt_install_prod: {
command: '/usr/bin/ssh root@<%= meta.dep_server %> aptitude install mentat-ng'
},
dpkg_install: {
// Install latest package via DPKG on local system.
dpkg_install_local: {
command: 'sudo dpkg -i <%= project_paths.deploy_dir %>' + deb_package_filename()
},
// Install latest package via DPKG on development server.
dpkg_install_dev: {
command: '/usr/bin/ssh root@<%= meta.dev_server %> dpkg -i <%= meta.dev_location %>/' + deb_package_latest_filename()
},
// Install latest package via DPKG on demo server.
dpkg_install_demo: {
command: '/usr/bin/ssh root@<%= meta.demo_server %> dpkg -i <%= meta.demo_location %>/' + deb_package_latest_filename()
},
},
// ---------------------------------------------------------------------
// Fill in certain template files
// Fill in certain template files.
template: {
'deb-control': {
'options': {
......@@ -129,12 +133,12 @@ module.exports = function(grunt) {
},
// ---------------------------------------------------------------------
// Copy certain files to appropriate locations
// Copy certain files to appropriate locations.
copy: {
// Copy components for DEB package
// Copy components for DEB package.
deb: {
files: [
// ----- Copy binaries to package location
// ----- Copy binaries to appropriate package location.
{
expand: true,
flatten: true,
......@@ -142,14 +146,14 @@ module.exports = function(grunt) {
src: './mentat-*.py',
dest: '<%= project_paths.package_dir %><%= paths_deb.bin_dir %>'
},
// ----- Copy libraries to package location
// ----- Copy libraries to appropriate package location.
{
expand: true,
cwd: 'lib/',
src: './**',
dest: '<%= project_paths.package_dir %><%= paths_deb.lib_dir %>'
},
// ----- Copy Debian package meta files to package location
// ----- Copy Debian package meta files to appropriate package location.
{
src: '<%= project_paths.control_dir %>conffiles',
dest: '<%= project_paths.package_dir %>DEBIAN/conffiles'
......@@ -162,21 +166,21 @@ module.exports = function(grunt) {
src: '<%= project_paths.control_dir %>postinst',
dest: '<%= project_paths.package_dir %>DEBIAN/postinst'
},
// ----- Copy scripts to package location
// ----- Copy scripts to appropriate package location.
{
expand: true,
cwd: 'scripts/',
src: './**',
dest: '<%= project_paths.package_dir %><%= paths_deb.scr_dir %>'
},
// ----- Copy configurations to package location
// ----- Copy configurations to appropriate package location.
{
expand: true,
cwd: 'conf/',
src: './**',
dest: '<%= project_paths.package_dir %><%= paths_deb.etc_dir %>'
},
// ----- Copy additional files
// ----- Copy additional files to appropriate package locations.
{
expand: true,
flatten: true,
......@@ -196,7 +200,7 @@ module.exports = function(grunt) {
},
// ---------------------------------------------------------------------
// Make sure all files have necessary file permissions
// Make sure all files have necessary file permissions.
chmod: {
options: {
mode: '755'
......@@ -218,10 +222,12 @@ module.exports = function(grunt) {
});
// ---------------------------------------------------------------------
// Load grunt modules
// Load grunt modules.
require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });
require('time-grunt')(grunt);
// Subtask for incrementing current version number. There should never be
// need to launch this task manually.
grunt.registerTask('inc-version', function() {
v = grunt.config.get('meta.version_minor');
grunt.config.set('meta.version_minor', v + 1);
......@@ -229,6 +235,7 @@ module.exports = function(grunt) {
grunt.config.set('template.deb-control.options.data.package_version', grunt.template.process(version()));
});
// Save current state of metadata.
grunt.registerTask('save-meta', function() {
try {
obj = JSON.parse(JSON.stringify(grunt.config.get('meta')));
......@@ -241,11 +248,42 @@ module.exports = function(grunt) {
// ---------------------------------------------------------------------
// Setup custom task(s).
grunt.registerTask('deb-build', ['clean:build', 'shell:archive_deb', 'copy:deb', 'chmod', 'shell:dir_size', 'inc-version', 'save-meta', 'template:deb-control', 'shell:build_deb', 'clean:build', 'shell:duplicate_deb']);
//grunt.registerTask('scp-deploy', ['shell:scp_deploy', 'shell:repo_refresh', 'shell:ssh_apt_update', 'shell:ssh_apt_install']);
grunt.registerTask('scp-deploy', ['shell:scp_deploy', 'shell:scp_deploy_dev', 'shell:repo_refresh']);
grunt.registerTask('deb-deploy', ['deb-build', 'scp-deploy', 'shell:dpkg_install_dev', 'shell:dpkg_install']);
grunt.registerTask('deb-local-deploy', ['deb-build', 'shell:dpkg_install']);
grunt.registerTask('update', ['shell:npm']);
grunt.registerTask('default', ['build-app']);
// ---------------------------------------------------------------------
grunt.registerTask('deb-build',
'(RUN) Build Debian packages for Mentat-ng system.',
['clean:build', 'shell:deb_archive', 'copy:deb', 'chmod', 'shell:dir_size', 'inc-version', 'save-meta', 'template:deb-control', 'shell:deb_build', 'clean:build', 'shell:deb_duplicate']
);
grunt.registerTask('deb-scp-upload',
'(RUN) Upload latest Debian packages to repository server, development server and demo server.',
['shell:deb_scp_upload_repo', 'shell:repo_refresh', 'shell:deb_scp_upload_dev', 'shell:deb_scp_upload_demo']
);
grunt.registerTask('deb-ssh-install',
'(RUN) Install latest Debian packages on local system and development and demo servers.',
['shell:dpkg_install_local', 'shell:dpkg_install_dev', 'shell:dpkg_install_demo']
);
grunt.registerTask('deb-deploy',
'(RUN) Build Debian packages for Mentat-ng system, upload them to repository, development and demo servers and install them.',
['deb-build', 'deb-scp-upload', 'deb-ssh-install']
);
grunt.registerTask('deb-deploy-local',
'(RUN) Build Debian packages for Mentat-ng system and install them on local system.',
['deb-build', 'shell:dpkg_install_local']
);
grunt.registerTask('deb-deploy-dev',
'(RUN) Build Debian packages for Mentat-ng system and upload and install them on development server.',
['deb-build', 'shell:deb_scp_upload_dev', 'shell:dpkg_install_dev']
);
grunt.registerTask('deb-deploy-demo',
'(RUN) Build Debian packages for Mentat-ng system and upload and install them on demo server.',
['deb-build', 'shell:deb_scp_upload_demo', 'shell:dpkg_install_demo']
);
grunt.registerTask('update',
'(RUN) Update internal NPM packages for build suite.',
['shell:npm_update']
);
grunt.registerTask('default',
'(RUN) Alias for deb-build, only build Debian packages.',
['deb-build']
);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment