2017-12-05 20:26:45 +00:00
|
|
|
var gruntfile_cfg = {};
|
2017-07-12 09:28:51 +00:00
|
|
|
var loadGruntTasks = require('load-grunt-tasks');
|
2017-10-25 06:56:57 +00:00
|
|
|
var os = require('os');
|
|
|
|
var arch = os.arch();
|
2018-12-02 23:10:55 +00:00
|
|
|
if (arch === 'x64') arch = 'amd64';
|
2017-07-04 12:30:23 +00:00
|
|
|
|
2018-12-02 23:10:55 +00:00
|
|
|
module.exports = function(grunt) {
|
2016-12-30 23:20:38 +00:00
|
|
|
|
2017-10-18 15:46:56 +00:00
|
|
|
loadGruntTasks(grunt, {
|
|
|
|
pattern: ['grunt-*', 'gruntify-*']
|
|
|
|
});
|
2017-07-12 09:28:51 +00:00
|
|
|
|
2017-05-04 08:17:55 +00:00
|
|
|
grunt.registerTask('default', ['eslint', 'build']);
|
2017-07-11 07:30:25 +00:00
|
|
|
grunt.registerTask('before-copy', [
|
2018-03-14 00:24:00 +00:00
|
|
|
'vendor',
|
2017-05-23 13:33:40 +00:00
|
|
|
'html2js',
|
|
|
|
'useminPrepare:release',
|
|
|
|
'concat',
|
|
|
|
'clean:tmpl',
|
|
|
|
'replace',
|
2018-03-13 11:09:02 +00:00
|
|
|
'postcss:build',
|
2017-07-11 07:30:25 +00:00
|
|
|
'uglify'
|
2017-05-23 13:33:40 +00:00
|
|
|
]);
|
2017-07-11 07:30:25 +00:00
|
|
|
grunt.registerTask('after-copy', [
|
2016-12-30 23:20:38 +00:00
|
|
|
'filerev',
|
|
|
|
'usemin',
|
2017-07-12 07:51:51 +00:00
|
|
|
'clean:tmp'
|
2016-12-30 23:20:38 +00:00
|
|
|
]);
|
2017-07-11 07:30:25 +00:00
|
|
|
grunt.registerTask('build-webapp', [
|
2017-05-19 15:48:03 +00:00
|
|
|
'config:prod',
|
2017-01-02 18:47:12 +00:00
|
|
|
'clean:all',
|
2017-07-11 07:30:25 +00:00
|
|
|
'before-copy',
|
2017-05-20 08:27:55 +00:00
|
|
|
'copy:assets',
|
2017-07-11 07:30:25 +00:00
|
|
|
'after-copy'
|
2017-07-12 07:51:51 +00:00
|
|
|
]);
|
2017-07-11 07:30:25 +00:00
|
|
|
grunt.registerTask('build', [
|
|
|
|
'config:dev',
|
|
|
|
'clean:app',
|
2017-10-25 06:56:57 +00:00
|
|
|
'shell:buildBinary:linux:' + arch,
|
|
|
|
'shell:downloadDockerBinary:linux:' + arch,
|
2018-03-14 00:24:00 +00:00
|
|
|
'vendor',
|
2017-05-20 08:02:18 +00:00
|
|
|
'html2js',
|
2017-07-11 07:30:25 +00:00
|
|
|
'useminPrepare:dev',
|
2017-05-20 08:02:18 +00:00
|
|
|
'concat',
|
|
|
|
'clean:tmpl',
|
|
|
|
'replace',
|
|
|
|
'copy',
|
2017-07-11 07:30:25 +00:00
|
|
|
'after-copy'
|
2017-05-20 08:02:18 +00:00
|
|
|
]);
|
2017-07-11 07:30:25 +00:00
|
|
|
grunt.task.registerTask('release', 'release:<platform>:<arch>', function(p, a) {
|
2018-12-02 23:10:55 +00:00
|
|
|
grunt.task.run(['config:prod', 'clean:all', 'shell:buildBinary:' + p + ':' + a, 'shell:downloadDockerBinary:' + p + ':' + a, 'before-copy', 'copy:assets', 'after-copy']);
|
2017-07-12 07:51:51 +00:00
|
|
|
});
|
2018-12-09 03:08:36 +00:00
|
|
|
|
2019-01-30 22:37:16 +00:00
|
|
|
grunt.task.registerTask('devopsbuild', 'devopsbuild:<platform>:<arch>', function(p, a) {
|
|
|
|
grunt.task.run(['config:prod', 'clean:all', 'shell:buildBinaryOnDevOps:' + p + ':' + a, 'shell:downloadDockerBinary:' + p + ':' + a, 'before-copy', 'copy:assets', 'after-copy']);
|
|
|
|
});
|
|
|
|
|
2017-05-04 08:17:55 +00:00
|
|
|
grunt.registerTask('lint', ['eslint']);
|
2019-02-06 23:00:47 +00:00
|
|
|
grunt.registerTask('run-dev', ['build', 'shell:run', 'watch:build']);
|
2016-12-30 23:20:38 +00:00
|
|
|
grunt.registerTask('clear', ['clean:app']);
|
|
|
|
|
2017-11-20 09:09:11 +00:00
|
|
|
// Load content of `vendor.yml` to src.jsVendor, src.cssVendor and src.angularVendor
|
2018-03-14 00:24:00 +00:00
|
|
|
grunt.registerTask('vendor', function() {
|
2018-12-02 23:10:55 +00:00
|
|
|
var vendorFile = grunt.file.readYAML('vendor.yml');
|
|
|
|
for (var filelist in vendorFile) {
|
|
|
|
if (vendorFile.hasOwnProperty(filelist)) {
|
|
|
|
var list = vendorFile[filelist];
|
|
|
|
// Check if any of the files is missing
|
|
|
|
for (var itemIndex in list) {
|
|
|
|
if (list.hasOwnProperty(itemIndex)) {
|
|
|
|
var item = 'node_modules/' + list[itemIndex];
|
|
|
|
if (!grunt.file.exists(item)) {
|
|
|
|
grunt.fail.warn('Dependency file ' + item + ' not found.');
|
|
|
|
}
|
|
|
|
list[itemIndex] = item;
|
2017-11-20 09:09:11 +00:00
|
|
|
}
|
2018-12-02 23:10:55 +00:00
|
|
|
}
|
|
|
|
// If none is missing, save the list
|
|
|
|
grunt.config('src.' + filelist + 'Vendor', list);
|
2017-11-20 09:09:11 +00:00
|
|
|
}
|
2018-12-02 23:10:55 +00:00
|
|
|
}
|
2017-11-20 09:09:11 +00:00
|
|
|
});
|
|
|
|
|
2016-12-30 23:20:38 +00:00
|
|
|
// Project configuration.
|
|
|
|
grunt.initConfig({
|
2018-07-03 18:31:02 +00:00
|
|
|
root: 'dist',
|
2017-10-26 09:17:45 +00:00
|
|
|
distdir: 'dist/public',
|
2018-12-02 23:10:55 +00:00
|
|
|
shippedDockerVersion: '18.09.0',
|
2018-07-28 14:12:24 +00:00
|
|
|
shippedDockerVersionWindows: '17.09.0-ce',
|
2016-12-30 23:20:38 +00:00
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
2017-12-05 20:26:45 +00:00
|
|
|
config: gruntfile_cfg.config,
|
|
|
|
src: gruntfile_cfg.src,
|
|
|
|
clean: gruntfile_cfg.clean,
|
|
|
|
useminPrepare: gruntfile_cfg.useminPrepare,
|
2018-12-02 23:10:55 +00:00
|
|
|
filerev: { files: { src: ['<%= distdir %>/js/*.js', '<%= distdir %>/css/*.css'] } },
|
2017-07-12 09:28:51 +00:00
|
|
|
usemin: { html: ['<%= distdir %>/index.html'] },
|
2017-12-05 20:26:45 +00:00
|
|
|
copy: gruntfile_cfg.copy,
|
|
|
|
eslint: gruntfile_cfg.eslint,
|
|
|
|
html2js: gruntfile_cfg.html2js,
|
|
|
|
concat: gruntfile_cfg.concat,
|
|
|
|
uglify: gruntfile_cfg.uglify,
|
|
|
|
postcss: gruntfile_cfg.postcss,
|
|
|
|
watch: gruntfile_cfg.watch,
|
|
|
|
shell: gruntfile_cfg.shell,
|
|
|
|
replace: gruntfile_cfg.replace
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
|
|
|
var autoprefixer = require('autoprefixer');
|
|
|
|
var cssnano = require('cssnano');
|
|
|
|
|
|
|
|
gruntfile_cfg.config = {
|
2018-12-02 23:10:55 +00:00
|
|
|
dev: { options: { variables: { 'environment': 'development' } } },
|
|
|
|
prod: { options: { variables: { 'environment': 'production' } } }
|
2017-12-05 20:26:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.src = {
|
|
|
|
js: ['app/**/__module.js', 'app/**/*.js', '!app/**/*.spec.js'],
|
|
|
|
jsTpl: ['<%= distdir %>/templates/**/*.js'],
|
|
|
|
html: ['index.html'],
|
2018-02-01 12:27:52 +00:00
|
|
|
tpl: ['app/**/*.html'],
|
2017-12-06 11:04:02 +00:00
|
|
|
css: ['assets/css/app.css', 'app/**/*.css']
|
2017-12-05 20:26:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.clean = {
|
2018-07-28 14:12:24 +00:00
|
|
|
all: ['<%= root %>/*'],
|
2017-12-05 20:26:45 +00:00
|
|
|
app: ['<%= distdir %>/*', '!<%= distdir %>/../portainer*', '!<%= distdir %>/../docker*'],
|
|
|
|
tmpl: ['<%= distdir %>/templates'],
|
|
|
|
tmp: ['<%= distdir %>/js/*', '!<%= distdir %>/js/app.*.js', '<%= distdir %>/css/*', '!<%= distdir %>/css/app.*.css']
|
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.useminPrepare = {
|
|
|
|
dev: {
|
|
|
|
src: '<%= src.html %>',
|
|
|
|
options: {
|
|
|
|
root: '<%= distdir %>',
|
|
|
|
flow: {
|
|
|
|
steps: {
|
|
|
|
js: ['concat'],
|
|
|
|
css: ['concat']
|
2017-07-12 09:28:51 +00:00
|
|
|
}
|
2016-12-30 23:20:38 +00:00
|
|
|
}
|
2017-12-05 20:26:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
release: {
|
|
|
|
src: '<%= src.html %>',
|
|
|
|
options: {
|
|
|
|
root: '<%= distdir %>',
|
|
|
|
dest: '<%= distdir %>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.copy = {
|
|
|
|
bundle: {
|
|
|
|
files: [
|
2018-12-02 23:10:55 +00:00
|
|
|
{ dest: '<%= distdir %>/js/', src: ['app.js'], expand: true, cwd: '.tmp/concat/js/' },
|
|
|
|
{ dest: '<%= distdir %>/css/', src: ['app.css'], expand: true, cwd: '.tmp/concat/css/' }
|
2017-12-05 20:26:45 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
assets: {
|
|
|
|
files: [
|
2018-12-02 23:10:55 +00:00
|
|
|
{ dest: '<%= distdir %>/fonts/', src: '*.{ttf,woff,woff2,eof,svg}', expand: true, cwd: 'node_modules/bootstrap/fonts/' },
|
|
|
|
{ dest: '<%= distdir %>/fonts/', src: '*.{ttf,woff,woff2,eof,eot,svg}', expand: true, cwd: 'node_modules/@fortawesome/fontawesome-free-webfonts/webfonts/' },
|
|
|
|
{ dest: '<%= distdir %>/fonts/', src: '*.{ttf,woff,woff2,eof,svg}', expand: true, cwd: 'node_modules/rdash-ui/dist/fonts/' },
|
|
|
|
{ dest: '<%= distdir %>/images/', src: '**', expand: true, cwd: 'assets/images/' },
|
|
|
|
{ dest: '<%= distdir %>/ico', src: '**', expand: true, cwd: 'assets/ico' },
|
|
|
|
{ dest: '<%= root %>/', src: 'templates.json', cwd: '' }
|
2018-07-03 18:31:02 +00:00
|
|
|
]
|
2017-12-05 20:26:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.eslint = {
|
|
|
|
src: ['gruntfile.js', '<%= src.js %>'],
|
|
|
|
options: { configFile: '.eslintrc.yml' }
|
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.html2js = {
|
|
|
|
app: {
|
|
|
|
options: { base: '.' },
|
|
|
|
src: ['<%= src.tpl %>'],
|
|
|
|
dest: '<%= distdir %>/templates/app.js',
|
|
|
|
module: '<%= pkg.name %>.templates'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.concat = {
|
|
|
|
vendor: {
|
|
|
|
files: {
|
|
|
|
'<%= distdir %>/css/<%= pkg.name %>.css': ['<%= src.cssVendor %>', '<%= src.css %>'],
|
|
|
|
'<%= distdir %>/js/vendor.js': ['<%= src.jsVendor %>'],
|
|
|
|
'<%= distdir %>/js/angular.js': ['<%= src.angularVendor %>']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
dist: {
|
|
|
|
options: { process: true },
|
|
|
|
files: {
|
|
|
|
'<%= distdir %>/js/<%= pkg.name %>.js': ['<%= src.js %>', '<%= src.jsTpl %>'],
|
|
|
|
'<%= distdir %>/index.html': ['index.html']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.uglify = {
|
|
|
|
dist: {
|
|
|
|
files: { '<%= distdir %>/js/<%= pkg.name %>.js': ['<%= src.js %>', '<%= src.jsTpl %>'] }
|
|
|
|
},
|
|
|
|
vendor: {
|
|
|
|
options: { preserveComments: 'some' }, // Preserve license comments
|
2018-12-02 23:10:55 +00:00
|
|
|
files: {
|
|
|
|
'<%= distdir %>/js/vendor.js': ['<%= src.jsVendor %>'],
|
|
|
|
'<%= distdir %>/js/angular.js': ['<%= src.angularVendor %>']
|
2017-12-05 20:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.postcss = {
|
|
|
|
build: {
|
|
|
|
options: {
|
|
|
|
processors: [
|
2018-12-02 23:10:55 +00:00
|
|
|
autoprefixer({ browsers: 'last 2 versions' }), // add vendor prefixes
|
2017-12-05 20:26:45 +00:00
|
|
|
cssnano() // minify the result
|
|
|
|
]
|
2016-12-30 23:20:38 +00:00
|
|
|
},
|
2018-03-13 11:09:02 +00:00
|
|
|
src: '.tmp/concat/css/app.css',
|
2017-12-05 20:26:45 +00:00
|
|
|
dest: '<%= distdir %>/css/app.css'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.watch = {
|
|
|
|
build: {
|
|
|
|
files: ['<%= src.js %>', '<%= src.css %>', '<%= src.tpl %>', '<%= src.html %>'],
|
|
|
|
tasks: ['build']
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gruntfile_cfg.replace = {
|
|
|
|
concat: {
|
|
|
|
options: {
|
|
|
|
patterns: [
|
2018-12-02 23:10:55 +00:00
|
|
|
{ match: 'ENVIRONMENT', replacement: '<%= grunt.config.get("environment") %>' },
|
2018-03-13 05:36:53 +00:00
|
|
|
{ match: 'CONFIG_GA_ID', replacement: '<%= pkg.config.GA_ID %>' },
|
2018-12-02 23:10:55 +00:00
|
|
|
{ match: /..\/webfonts\//g, replacement: '../fonts/' }
|
2017-12-05 20:26:45 +00:00
|
|
|
]
|
2017-02-13 22:39:26 +00:00
|
|
|
},
|
2017-12-05 20:26:45 +00:00
|
|
|
files: [
|
|
|
|
{
|
|
|
|
expand: true,
|
|
|
|
flatten: true,
|
|
|
|
src: ['.tmp/concat/js/app.js'],
|
|
|
|
dest: '.tmp/concat/js'
|
2018-03-13 05:36:53 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
expand: true,
|
|
|
|
flatten: true,
|
|
|
|
src: ['.tmp/concat/css/app.css'],
|
|
|
|
dest: '.tmp/concat/css'
|
2017-02-13 22:39:26 +00:00
|
|
|
}
|
2017-12-05 20:26:45 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function shell_buildBinary(p, a) {
|
2019-02-06 23:00:47 +00:00
|
|
|
var binfile = 'dist/portainer';
|
2019-01-30 22:37:16 +00:00
|
|
|
if (p === 'linux') {
|
|
|
|
return [
|
|
|
|
'if [ -f ' + (binfile) + ' ]; then',
|
|
|
|
'echo "Portainer binary exists";',
|
|
|
|
'else',
|
|
|
|
'build/build_binary.sh ' + p + ' ' + a + ';',
|
|
|
|
'fi'
|
|
|
|
].join(' ');
|
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
'powershell -Command "& {if (Get-Item -Path ' + binfile + '.exe -ErrorAction:SilentlyContinue) {',
|
|
|
|
'Write-Host "Portainer binary exists"',
|
|
|
|
'} else {',
|
|
|
|
'& ".\\build\\build_binary.ps1" -platform ' + p + ' -arch ' + a + '',
|
|
|
|
'}}"'
|
|
|
|
].join(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function shell_buildBinaryOnDevOps(p, a) {
|
|
|
|
if (p === 'linux') {
|
2019-01-30 22:38:27 +00:00
|
|
|
return 'build/build_binary_devops.sh ' + p + ' ' + a + ';';
|
2019-01-30 22:37:16 +00:00
|
|
|
} else {
|
2019-01-30 22:38:27 +00:00
|
|
|
return 'powershell -Command ".\\build\\build_binary_devops.ps1 -platform ' + p + ' -arch ' + a + '"';
|
2019-01-30 22:37:16 +00:00
|
|
|
}
|
2018-12-09 03:08:36 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 23:00:47 +00:00
|
|
|
function shell_run() {
|
2017-12-05 20:26:45 +00:00
|
|
|
return [
|
|
|
|
'docker rm -f portainer',
|
2019-02-06 23:00:47 +00:00
|
|
|
'docker run -d -p 9000:9000 -v $(pwd)/dist:/app -v /tmp/portainer:/data -v /var/run/docker.sock:/var/run/docker.sock:z --name portainer portainer/base /app/portainer --no-analytics --template-file /app/templates.json'
|
2017-12-05 20:26:45 +00:00
|
|
|
].join(';');
|
|
|
|
}
|
|
|
|
|
|
|
|
function shell_downloadDockerBinary(p, a) {
|
|
|
|
var ps = { 'windows': 'win', 'darwin': 'mac' };
|
|
|
|
var as = { 'amd64': 'x86_64', 'arm': 'armhf', 'arm64': 'aarch64' };
|
|
|
|
var ip = ((ps[p] === undefined) ? p : ps[p]);
|
|
|
|
var ia = ((as[a] === undefined) ? a : as[a]);
|
2018-12-09 03:08:36 +00:00
|
|
|
var binaryVersion = ((p === 'windows' ? '<%= shippedDockerVersionWindows %>' : '<%= shippedDockerVersion %>'));
|
2019-01-30 22:37:16 +00:00
|
|
|
if (p === 'linux') {
|
|
|
|
return [
|
|
|
|
'if [ -f dist/docker ]; then',
|
|
|
|
'echo "Docker binary exists";',
|
|
|
|
'else',
|
|
|
|
'build/download_docker_binary.sh ' + ip + ' ' + ia + ' ' + binaryVersion + ';',
|
|
|
|
'fi'
|
|
|
|
].join(' ');
|
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
'powershell -Command "& {if (Get-Item -Path dist/docker.exe -ErrorAction:SilentlyContinue) {',
|
|
|
|
'Write-Host "Docker binary exists"',
|
|
|
|
'} else {',
|
|
|
|
'& ".\\build\\download_docker_binary.ps1" -docker_version ' + binaryVersion + '',
|
|
|
|
'}}"'
|
|
|
|
].join(' ');
|
|
|
|
}
|
2017-12-05 20:26:45 +00:00
|
|
|
}
|
2017-07-12 09:28:51 +00:00
|
|
|
|
2017-12-05 20:26:45 +00:00
|
|
|
gruntfile_cfg.shell = {
|
|
|
|
buildBinary: { command: shell_buildBinary },
|
2019-01-30 22:37:16 +00:00
|
|
|
buildBinaryOnDevOps: { command: shell_buildBinaryOnDevOps },
|
2017-12-05 20:26:45 +00:00
|
|
|
run: { command: shell_run },
|
|
|
|
downloadDockerBinary: { command: shell_downloadDockerBinary }
|
2019-01-30 22:38:27 +00:00
|
|
|
};
|