chore(build): clean gruntfile (#5411)

pull/5913/head
Chaim Lev-Ari 2021-10-15 09:17:05 +03:00 committed by GitHub
parent 41999e149f
commit ba1f0f4018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 152 deletions

View File

@ -1,14 +1,13 @@
var os = require('os'); const os = require('os');
var loadGruntTasks = require('load-grunt-tasks'); const loadGruntTasks = require('load-grunt-tasks');
const webpackDevConfig = require('./webpack/webpack.develop'); const webpackDevConfig = require('./webpack/webpack.develop');
const webpackProdConfig = require('./webpack/webpack.production'); const webpackProdConfig = require('./webpack/webpack.production');
const webpackTestingConfig = require('./webpack/webpack.testing'); const webpackTestingConfig = require('./webpack/webpack.testing');
var arch = os.arch(); let arch = os.arch();
if (arch === 'x64') arch = 'amd64'; if (arch === 'x64') {
arch = 'amd64';
var portainer_data = '${PORTAINER_DATA:-/tmp/portainer}'; }
var portainer_root = process.env.PORTAINER_PROJECT ? process.env.PORTAINER_PROJECT : process.env.PWD;
module.exports = function (grunt) { module.exports = function (grunt) {
loadGruntTasks(grunt, { loadGruntTasks(grunt, {
@ -28,78 +27,53 @@ module.exports = function (grunt) {
komposeVersion: 'v1.22.0', komposeVersion: 'v1.22.0',
kubectlVersion: 'v1.18.0', kubectlVersion: 'v1.18.0',
}, },
config: gruntfile_cfg.config, env: gruntConfig.env,
env: gruntfile_cfg.env, clean: gruntConfig.clean,
src: gruntfile_cfg.src, shell: gruntConfig.shell,
clean: gruntfile_cfg.clean, webpack: gruntConfig.webpack,
eslint: gruntfile_cfg.eslint,
shell: gruntfile_cfg.shell,
copy: gruntfile_cfg.copy,
webpack: gruntfile_cfg.webpack,
}); });
grunt.registerTask('lint', ['eslint']); grunt.registerTask('lint', ['eslint']);
grunt.registerTask('build:server', [ grunt.registerTask('build:server', [`shell:build_binary:linux:${arch}`, `download_binaries:linux:${arch}`]);
'shell:build_binary:linux:' + arch,
'shell:download_docker_binary:linux:' + arch,
'shell:download_docker_compose_binary:linux:' + arch,
'shell:download_helm_binary:linux:' + arch,
'shell:download_kompose_binary:linux:' + arch,
'shell:download_kubectl_binary:linux:' + arch,
]);
grunt.registerTask('build:client', ['config:dev', 'env:dev', 'webpack:dev']); grunt.registerTask('build:client', ['webpack:dev']);
grunt.registerTask('build', ['build:server', 'build:client', 'copy:assets']); grunt.registerTask('build', ['build:server', 'build:client']);
grunt.registerTask('start:server', ['build:server', 'copy:assets', 'shell:run_container']); grunt.registerTask('start:server', ['build:server', 'shell:run_container']);
grunt.registerTask('start:localserver', ['shell:build_binary:linux:' + arch, 'shell:run_localserver']); grunt.registerTask('start:localserver', [`shell:build_binary:linux:${arch}`, 'shell:run_localserver']);
grunt.registerTask('start:client', ['shell:install_yarndeps', 'config:dev', 'env:dev', 'webpack:devWatch']); grunt.registerTask('start:client', ['shell:install_yarndeps', 'webpack:devWatch']);
grunt.registerTask('start', ['start:server', 'start:client']); grunt.registerTask('start', ['start:server', 'start:client']);
grunt.registerTask('start:toolkit', ['start:localserver', 'start:client']); grunt.registerTask('start:toolkit', ['start:localserver', 'start:client']);
grunt.task.registerTask('release', 'release:<platform>:<arch>', function (p = 'linux', a = arch) { grunt.task.registerTask('release', 'release:<platform>:<arch>', function (platform = 'linux', a = arch) {
grunt.task.run([ grunt.task.run(['env:prod', 'clean:all', `shell:build_binary:${platform}:${a}`, `download_binaries:${platform}:${a}`, 'webpack:prod']);
'config:prod',
'env:prod',
'clean:all',
'copy:assets',
'shell:build_binary:' + p + ':' + a,
'shell:download_docker_binary:' + p + ':' + a,
'shell:download_docker_compose_binary:' + p + ':' + a,
'shell:download_helm_binary:' + p + ':' + a,
'shell:download_kompose_binary:' + p + ':' + a,
'shell:download_kubectl_binary:' + p + ':' + a,
'webpack:prod',
]);
}); });
grunt.task.registerTask('devopsbuild', 'devopsbuild:<platform>:<arch>:<env>', function (p, a, env = 'prod') { grunt.task.registerTask('devopsbuild', 'devopsbuild:<platform>:<arch>:<env>', function (platform, a = arch, env = 'prod') {
grunt.task.run([`env:${env}`, 'clean:all', `shell:build_binary_azuredevops:${platform}:${a}`, `download_binaries:${platform}:${a}`, `webpack:${env}`]);
});
grunt.task.registerTask('download_binaries', 'download_binaries:<platform>:<arch>', function (platform = 'linux', a = arch) {
grunt.task.run([ grunt.task.run([
'config:prod', `shell:download_docker_binary:${platform}:${a}`,
`env:${env}`, `shell:download_docker_compose_binary:${platform}:${a}`,
'clean:all', `shell:download_helm_binary:${platform}:${arch}`,
'copy:assets', `shell:download_kompose_binary:${platform}:${a}`,
'shell:build_binary_azuredevops:' + p + ':' + a, `shell:download_kubectl_binary:${platform}:${a}`,
'shell:download_docker_binary:' + p + ':' + a,
'shell:download_docker_compose_binary:' + p + ':' + a,
'shell:download_helm_binary:' + p + ':' + a,
'shell:download_kompose_binary:' + p + ':' + a,
'shell:download_kubectl_binary:' + p + ':' + a,
`webpack:${env}`,
]); ]);
}); });
}; };
/***/ /***/
var gruntfile_cfg = {}; const gruntConfig = {};
gruntfile_cfg.env = { gruntConfig.env = {
dev: { dev: {
NODE_ENV: 'development', NODE_ENV: 'development',
}, },
@ -111,44 +85,20 @@ gruntfile_cfg.env = {
}, },
}; };
gruntfile_cfg.webpack = { gruntConfig.webpack = {
dev: webpackDevConfig, dev: webpackDevConfig,
devWatch: Object.assign({ watch: true }, webpackDevConfig), devWatch: Object.assign({ watch: true }, webpackDevConfig),
prod: webpackProdConfig, prod: webpackProdConfig,
testing: webpackTestingConfig, testing: webpackTestingConfig,
}; };
gruntfile_cfg.config = { gruntConfig.clean = {
dev: { options: { variables: { environment: 'development' } } },
prod: { options: { variables: { environment: 'production' } } },
};
gruntfile_cfg.src = {
js: ['app/**/__module.js', 'app/**/*.js', '!app/**/*.spec.js'],
jsTpl: ['<%= distdir %>/templates/**/*.js'],
html: ['index.html'],
tpl: ['app/**/*.html'],
css: ['assets/css/app.css', 'app/**/*.css'],
};
gruntfile_cfg.clean = {
server: ['<%= root %>/portainer'], server: ['<%= root %>/portainer'],
client: ['<%= distdir %>/*'], client: ['<%= distdir %>/*'],
all: ['<%= root %>/*'], all: ['<%= root %>/*'],
}; };
gruntfile_cfg.eslint = { gruntConfig.shell = {
src: ['gruntfile.js', '<%= src.js %>'],
options: { configFile: '.eslintrc.yml' },
};
gruntfile_cfg.copy = {
assets: {
files: [],
},
};
gruntfile_cfg.shell = {
build_binary: { command: shell_build_binary }, build_binary: { command: shell_build_binary },
build_binary_azuredevops: { command: shell_build_binary_azuredevops }, build_binary_azuredevops: { command: shell_build_binary_azuredevops },
download_docker_binary: { command: shell_download_docker_binary }, download_docker_binary: { command: shell_download_docker_binary },
@ -161,34 +111,51 @@ gruntfile_cfg.shell = {
install_yarndeps: { command: shell_install_yarndeps }, install_yarndeps: { command: shell_install_yarndeps },
}; };
function shell_build_binary(p, a) { function shell_build_binary(platform, arch) {
var binfile = 'dist/portainer'; const binfile = 'dist/portainer';
if (p === 'linux') { if (platform === 'linux') {
return ['if [ -f ' + binfile + ' ]; then', 'echo "Portainer binary exists";', 'else', 'build/build_binary.sh ' + p + ' ' + a + ';', 'fi'].join(' '); return `
} else { if [ -f ${binfile} ]; then
return [ echo "Portainer binary exists";
'powershell -Command "& {if (Get-Item -Path ' + binfile + '.exe -ErrorAction:SilentlyContinue) {', else
'Write-Host "Portainer binary exists"', build/build_binary.sh ${platform} ${arch};
'} else {', fi
'& ".\\build\\build_binary.ps1" -platform ' + p + ' -arch ' + a + '', `;
'}}"',
].join(' ');
}
} }
function shell_build_binary_azuredevops(p, a) { // windows
return 'build/build_binary_azuredevops.sh ' + p + ' ' + a + ';'; return `
powershell -Command "& {if (Get-Item -Path ${binfile}.exe -ErrorAction:SilentlyContinue) {
Write-Host "Portainer binary exists"
} else {
& ".\\build\\build_binary.ps1" -platform ${platform} -arch ${arch}
}}"
`;
}
function shell_build_binary_azuredevops(platform, arch) {
return `build/build_binary_azuredevops.sh ${platform} ${arch};`;
} }
function shell_run_container() { function shell_run_container() {
return [ const portainerData = '${PORTAINER_DATA:-/tmp/portainer}';
'docker rm -f portainer', const portainerRoot = process.env.PORTAINER_PROJECT ? process.env.PORTAINER_PROJECT : process.env.PWD;
'docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 -v ' +
portainer_root + return `
'/dist:/app -v ' + docker rm -f portainer
portainer_data + docker run -d \
':/data -v /var/run/docker.sock:/var/run/docker.sock:z -v /var/run/docker.sock:/var/run/alternative.sock:z -v /tmp:/tmp --name portainer portainer/base /app/portainer', -p 8000:8000 \
].join(';'); -p 9000:9000 \
-p 9443:9443 \
-v ${portainerRoot}/dist:/app \
-v ${portainerData}:/data \
-v /var/run/docker.sock:/var/run/docker.sock:z \
-v /var/run/docker.sock:/var/run/alternative.sock:z \
-v /tmp:/tmp \
--name portainer \
portainer/base \
/app/portainer
`;
} }
function shell_run_localserver() { function shell_run_localserver() {
@ -199,20 +166,21 @@ function shell_install_yarndeps() {
return 'yarn'; return 'yarn';
} }
function shell_download_docker_binary(p, a) { function shell_download_docker_binary(platform, arch) {
var ps = { windows: 'win', darwin: 'mac' }; const ps = { windows: 'win', darwin: 'mac' };
var as = { amd64: 'x86_64', arm: 'armhf', arm64: 'aarch64' }; const as = { amd64: 'x86_64', arm: 'armhf', arm64: 'aarch64' };
var ip = ps[p] === undefined ? p : ps[p];
var ia = as[a] === undefined ? a : as[a];
var binaryVersion = p === 'windows' ? '<%= binaries.dockerWindowsVersion %>' : '<%= binaries.dockerLinuxVersion %>';
return [ const ip = ps[platform] === undefined ? platform : ps[platform];
'if [ -f dist/docker ] || [ -f dist/docker.exe ]; then', const ia = as[arch] === undefined ? arch : as[arch];
'echo "docker binary exists";', const binaryVersion = platform === 'windows' ? '<%= binaries.dockerWindowsVersion %>' : '<%= binaries.dockerLinuxVersion %>';
'else',
'build/download_docker_binary.sh ' + ip + ' ' + ia + ' ' + binaryVersion + ';', return `
'fi', if [ -f dist/docker ] || [ -f dist/docker.exe ]; then
].join(' '); echo "docker binary exists";
else
build/download_docker_binary.sh ${ip} ${ia} ${binaryVersion};
fi
`;
} }
function shell_download_docker_compose_binary(p, a) { function shell_download_docker_compose_binary(p, a) {
@ -242,38 +210,38 @@ function shell_download_docker_compose_binary(p, a) {
fi`; fi`;
} }
function shell_download_helm_binary(p, a) { function shell_download_helm_binary(platform, arch) {
var binaryVersion = '<%= binaries.helmVersion %>'; var binaryVersion = '<%= binaries.helmVersion %>';
return [ return `
'if [ -f dist/helm ] || [ -f dist/helm.exe ]; then', if [ -f dist/helm ] || [ -f dist/helm.exe ]; then
'echo "helm binary exists";', echo "helm binary exists";
'else', else
'build/download_helm_binary.sh ' + p + ' ' + a + ' ' + binaryVersion + ';', build/download_helm_binary.sh ${platform} ${arch} ${binaryVersion};
'fi', fi
].join(' '); `;
} }
function shell_download_kompose_binary(p, a) { function shell_download_kompose_binary(platform, arch) {
var binaryVersion = '<%= binaries.komposeVersion %>'; const binaryVersion = '<%= binaries.komposeVersion %>';
return [ return `
'if [ -f dist/kompose ] || [ -f dist/kompose.exe ]; then', if [ -f dist/kompose ] || [ -f dist/kompose.exe ]; then
'echo "kompose binary exists";', echo "kompose binary exists";
'else', else
'build/download_kompose_binary.sh ' + p + ' ' + a + ' ' + binaryVersion + ';', build/download_kompose_binary.sh ${platform} ${arch} ${binaryVersion};
'fi', fi
].join(' '); `;
} }
function shell_download_kubectl_binary(p, a) { function shell_download_kubectl_binary(platform, arch) {
var binaryVersion = '<%= binaries.kubectlVersion %>'; var binaryVersion = '<%= binaries.kubectlVersion %>';
return [ return `
'if [ -f dist/kubectl ] || [ -f dist/kubectl.exe ]; then', if [ -f dist/kubectl ] || [ -f dist/kubectl.exe ]; then
'echo "kubectl binary exists";', echo "kubectl binary exists";
'else', else
'build/download_kubectl_binary.sh ' + p + ' ' + a + ' ' + binaryVersion + ';', build/download_kubectl_binary.sh ${platform} ${arch} ${binaryVersion};
'fi', fi
].join(' '); `;
} }

View File

@ -30,7 +30,7 @@
"start:client": "grunt clean:client && grunt start:client", "start:client": "grunt clean:client && grunt start:client",
"dev:client": "grunt clean:client && webpack-dev-server --config=./webpack/webpack.develop.js", "dev:client": "grunt clean:client && webpack-dev-server --config=./webpack/webpack.develop.js",
"dev:client:prod": "grunt clean:client && webpack-dev-server --config=./webpack/webpack.production.js", "dev:client:prod": "grunt clean:client && webpack-dev-server --config=./webpack/webpack.production.js",
"dev:nodl": "grunt clean:server && grunt clean:client && grunt build:server && grunt copy:assets && grunt start:client", "dev:nodl": "grunt clean:server && grunt clean:client && grunt build:server && grunt start:client",
"start:toolkit": "grunt start:toolkit", "start:toolkit": "grunt start:toolkit",
"build:server:offline": "cd ./api/cmd/portainer && CGO_ENABLED=0 go build --installsuffix cgo --ldflags '-s' && mv -f portainer ../../../dist/portainer", "build:server:offline": "cd ./api/cmd/portainer && CGO_ENABLED=0 go build --installsuffix cgo --ldflags '-s' && mv -f portainer ../../../dist/portainer",
"clean:all": "grunt clean:all", "clean:all": "grunt clean:all",
@ -126,7 +126,6 @@
"file-loader": "^1.1.11", "file-loader": "^1.1.11",
"grunt": "^1.1.0", "grunt": "^1.1.0",
"grunt-cli": "^1.3.2", "grunt-cli": "^1.3.2",
"grunt-config": "^1.0.0",
"grunt-contrib-clean": "^2.0.0", "grunt-contrib-clean": "^2.0.0",
"grunt-contrib-copy": "^1.0.0", "grunt-contrib-copy": "^1.0.0",
"grunt-env": "^0.4.4", "grunt-env": "^0.4.4",

View File

@ -5296,13 +5296,6 @@ grunt-cli@~1.2.0:
nopt "~3.0.6" nopt "~3.0.6"
resolve "~1.1.0" resolve "~1.1.0"
grunt-config@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/grunt-config/-/grunt-config-1.0.0.tgz#e0a20e4cbadb8ae90843697a8afa05af8aeb860c"
integrity sha1-4KIOTLrbiukIQ2l6ivoFr4rrhgw=
dependencies:
chalk "^1.1.0"
grunt-contrib-clean@^2.0.0: grunt-contrib-clean@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/grunt-contrib-clean/-/grunt-contrib-clean-2.0.0.tgz#3be7ca480da4b740aa5e9d863e2f7e8b24f8a68b" resolved "https://registry.yarnpkg.com/grunt-contrib-clean/-/grunt-contrib-clean-2.0.0.tgz#3be7ca480da4b740aa5e9d863e2f7e8b24f8a68b"