mirror of https://github.com/portainer/portainer
chore(build): clean gruntfile (#5411)
parent
41999e149f
commit
ba1f0f4018
254
gruntfile.js
254
gruntfile.js
|
@ -1,14 +1,13 @@
|
|||
var os = require('os');
|
||||
var loadGruntTasks = require('load-grunt-tasks');
|
||||
const os = require('os');
|
||||
const loadGruntTasks = require('load-grunt-tasks');
|
||||
const webpackDevConfig = require('./webpack/webpack.develop');
|
||||
const webpackProdConfig = require('./webpack/webpack.production');
|
||||
const webpackTestingConfig = require('./webpack/webpack.testing');
|
||||
|
||||
var arch = os.arch();
|
||||
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;
|
||||
let arch = os.arch();
|
||||
if (arch === 'x64') {
|
||||
arch = 'amd64';
|
||||
}
|
||||
|
||||
module.exports = function (grunt) {
|
||||
loadGruntTasks(grunt, {
|
||||
|
@ -28,78 +27,53 @@ module.exports = function (grunt) {
|
|||
komposeVersion: 'v1.22.0',
|
||||
kubectlVersion: 'v1.18.0',
|
||||
},
|
||||
config: gruntfile_cfg.config,
|
||||
env: gruntfile_cfg.env,
|
||||
src: gruntfile_cfg.src,
|
||||
clean: gruntfile_cfg.clean,
|
||||
eslint: gruntfile_cfg.eslint,
|
||||
shell: gruntfile_cfg.shell,
|
||||
copy: gruntfile_cfg.copy,
|
||||
webpack: gruntfile_cfg.webpack,
|
||||
env: gruntConfig.env,
|
||||
clean: gruntConfig.clean,
|
||||
shell: gruntConfig.shell,
|
||||
webpack: gruntConfig.webpack,
|
||||
});
|
||||
|
||||
grunt.registerTask('lint', ['eslint']);
|
||||
|
||||
grunt.registerTask('build:server', [
|
||||
'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:server', [`shell:build_binary:linux:${arch}`, `download_binaries: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:toolkit', ['start:localserver', 'start:client']);
|
||||
|
||||
grunt.task.registerTask('release', 'release:<platform>:<arch>', function (p = 'linux', a = arch) {
|
||||
grunt.task.run([
|
||||
'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('release', 'release:<platform>:<arch>', function (platform = 'linux', a = arch) {
|
||||
grunt.task.run(['env:prod', 'clean:all', `shell:build_binary:${platform}:${a}`, `download_binaries:${platform}:${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([
|
||||
'config:prod',
|
||||
`env:${env}`,
|
||||
'clean:all',
|
||||
'copy:assets',
|
||||
'shell:build_binary_azuredevops:' + 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:${env}`,
|
||||
`shell:download_docker_binary:${platform}:${a}`,
|
||||
`shell:download_docker_compose_binary:${platform}:${a}`,
|
||||
`shell:download_helm_binary:${platform}:${arch}`,
|
||||
`shell:download_kompose_binary:${platform}:${a}`,
|
||||
`shell:download_kubectl_binary:${platform}:${a}`,
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
/***/
|
||||
var gruntfile_cfg = {};
|
||||
const gruntConfig = {};
|
||||
|
||||
gruntfile_cfg.env = {
|
||||
gruntConfig.env = {
|
||||
dev: {
|
||||
NODE_ENV: 'development',
|
||||
},
|
||||
|
@ -111,44 +85,20 @@ gruntfile_cfg.env = {
|
|||
},
|
||||
};
|
||||
|
||||
gruntfile_cfg.webpack = {
|
||||
gruntConfig.webpack = {
|
||||
dev: webpackDevConfig,
|
||||
devWatch: Object.assign({ watch: true }, webpackDevConfig),
|
||||
prod: webpackProdConfig,
|
||||
testing: webpackTestingConfig,
|
||||
};
|
||||
|
||||
gruntfile_cfg.config = {
|
||||
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 = {
|
||||
gruntConfig.clean = {
|
||||
server: ['<%= root %>/portainer'],
|
||||
client: ['<%= distdir %>/*'],
|
||||
all: ['<%= root %>/*'],
|
||||
};
|
||||
|
||||
gruntfile_cfg.eslint = {
|
||||
src: ['gruntfile.js', '<%= src.js %>'],
|
||||
options: { configFile: '.eslintrc.yml' },
|
||||
};
|
||||
|
||||
gruntfile_cfg.copy = {
|
||||
assets: {
|
||||
files: [],
|
||||
},
|
||||
};
|
||||
|
||||
gruntfile_cfg.shell = {
|
||||
gruntConfig.shell = {
|
||||
build_binary: { command: shell_build_binary },
|
||||
build_binary_azuredevops: { command: shell_build_binary_azuredevops },
|
||||
download_docker_binary: { command: shell_download_docker_binary },
|
||||
|
@ -161,34 +111,51 @@ gruntfile_cfg.shell = {
|
|||
install_yarndeps: { command: shell_install_yarndeps },
|
||||
};
|
||||
|
||||
function shell_build_binary(p, a) {
|
||||
var binfile = 'dist/portainer';
|
||||
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_build_binary(platform, arch) {
|
||||
const binfile = 'dist/portainer';
|
||||
if (platform === 'linux') {
|
||||
return `
|
||||
if [ -f ${binfile} ]; then
|
||||
echo "Portainer binary exists";
|
||||
else
|
||||
build/build_binary.sh ${platform} ${arch};
|
||||
fi
|
||||
`;
|
||||
}
|
||||
|
||||
// windows
|
||||
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(p, a) {
|
||||
return 'build/build_binary_azuredevops.sh ' + p + ' ' + a + ';';
|
||||
function shell_build_binary_azuredevops(platform, arch) {
|
||||
return `build/build_binary_azuredevops.sh ${platform} ${arch};`;
|
||||
}
|
||||
|
||||
function shell_run_container() {
|
||||
return [
|
||||
'docker rm -f portainer',
|
||||
'docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 -v ' +
|
||||
portainer_root +
|
||||
'/dist:/app -v ' +
|
||||
portainer_data +
|
||||
':/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',
|
||||
].join(';');
|
||||
const portainerData = '${PORTAINER_DATA:-/tmp/portainer}';
|
||||
const portainerRoot = process.env.PORTAINER_PROJECT ? process.env.PORTAINER_PROJECT : process.env.PWD;
|
||||
|
||||
return `
|
||||
docker rm -f portainer
|
||||
docker run -d \
|
||||
-p 8000:8000 \
|
||||
-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() {
|
||||
|
@ -199,20 +166,21 @@ function shell_install_yarndeps() {
|
|||
return 'yarn';
|
||||
}
|
||||
|
||||
function shell_download_docker_binary(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];
|
||||
var binaryVersion = p === 'windows' ? '<%= binaries.dockerWindowsVersion %>' : '<%= binaries.dockerLinuxVersion %>';
|
||||
function shell_download_docker_binary(platform, arch) {
|
||||
const ps = { windows: 'win', darwin: 'mac' };
|
||||
const as = { amd64: 'x86_64', arm: 'armhf', arm64: 'aarch64' };
|
||||
|
||||
return [
|
||||
'if [ -f dist/docker ] || [ -f dist/docker.exe ]; then',
|
||||
'echo "docker binary exists";',
|
||||
'else',
|
||||
'build/download_docker_binary.sh ' + ip + ' ' + ia + ' ' + binaryVersion + ';',
|
||||
'fi',
|
||||
].join(' ');
|
||||
const ip = ps[platform] === undefined ? platform : ps[platform];
|
||||
const ia = as[arch] === undefined ? arch : as[arch];
|
||||
const binaryVersion = platform === 'windows' ? '<%= binaries.dockerWindowsVersion %>' : '<%= binaries.dockerLinuxVersion %>';
|
||||
|
||||
return `
|
||||
if [ -f dist/docker ] || [ -f dist/docker.exe ]; then
|
||||
echo "docker binary exists";
|
||||
else
|
||||
build/download_docker_binary.sh ${ip} ${ia} ${binaryVersion};
|
||||
fi
|
||||
`;
|
||||
}
|
||||
|
||||
function shell_download_docker_compose_binary(p, a) {
|
||||
|
@ -242,38 +210,38 @@ function shell_download_docker_compose_binary(p, a) {
|
|||
fi`;
|
||||
}
|
||||
|
||||
function shell_download_helm_binary(p, a) {
|
||||
function shell_download_helm_binary(platform, arch) {
|
||||
var binaryVersion = '<%= binaries.helmVersion %>';
|
||||
|
||||
return [
|
||||
'if [ -f dist/helm ] || [ -f dist/helm.exe ]; then',
|
||||
'echo "helm binary exists";',
|
||||
'else',
|
||||
'build/download_helm_binary.sh ' + p + ' ' + a + ' ' + binaryVersion + ';',
|
||||
'fi',
|
||||
].join(' ');
|
||||
return `
|
||||
if [ -f dist/helm ] || [ -f dist/helm.exe ]; then
|
||||
echo "helm binary exists";
|
||||
else
|
||||
build/download_helm_binary.sh ${platform} ${arch} ${binaryVersion};
|
||||
fi
|
||||
`;
|
||||
}
|
||||
|
||||
function shell_download_kompose_binary(p, a) {
|
||||
var binaryVersion = '<%= binaries.komposeVersion %>';
|
||||
function shell_download_kompose_binary(platform, arch) {
|
||||
const binaryVersion = '<%= binaries.komposeVersion %>';
|
||||
|
||||
return [
|
||||
'if [ -f dist/kompose ] || [ -f dist/kompose.exe ]; then',
|
||||
'echo "kompose binary exists";',
|
||||
'else',
|
||||
'build/download_kompose_binary.sh ' + p + ' ' + a + ' ' + binaryVersion + ';',
|
||||
'fi',
|
||||
].join(' ');
|
||||
return `
|
||||
if [ -f dist/kompose ] || [ -f dist/kompose.exe ]; then
|
||||
echo "kompose binary exists";
|
||||
else
|
||||
build/download_kompose_binary.sh ${platform} ${arch} ${binaryVersion};
|
||||
fi
|
||||
`;
|
||||
}
|
||||
|
||||
function shell_download_kubectl_binary(p, a) {
|
||||
function shell_download_kubectl_binary(platform, arch) {
|
||||
var binaryVersion = '<%= binaries.kubectlVersion %>';
|
||||
|
||||
return [
|
||||
'if [ -f dist/kubectl ] || [ -f dist/kubectl.exe ]; then',
|
||||
'echo "kubectl binary exists";',
|
||||
'else',
|
||||
'build/download_kubectl_binary.sh ' + p + ' ' + a + ' ' + binaryVersion + ';',
|
||||
'fi',
|
||||
].join(' ');
|
||||
return `
|
||||
if [ -f dist/kubectl ] || [ -f dist/kubectl.exe ]; then
|
||||
echo "kubectl binary exists";
|
||||
else
|
||||
build/download_kubectl_binary.sh ${platform} ${arch} ${binaryVersion};
|
||||
fi
|
||||
`;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
"start:client": "grunt clean:client && grunt start:client",
|
||||
"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: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",
|
||||
"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",
|
||||
|
@ -126,7 +126,6 @@
|
|||
"file-loader": "^1.1.11",
|
||||
"grunt": "^1.1.0",
|
||||
"grunt-cli": "^1.3.2",
|
||||
"grunt-config": "^1.0.0",
|
||||
"grunt-contrib-clean": "^2.0.0",
|
||||
"grunt-contrib-copy": "^1.0.0",
|
||||
"grunt-env": "^0.4.4",
|
||||
|
|
|
@ -5296,13 +5296,6 @@ grunt-cli@~1.2.0:
|
|||
nopt "~3.0.6"
|
||||
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:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/grunt-contrib-clean/-/grunt-contrib-clean-2.0.0.tgz#3be7ca480da4b740aa5e9d863e2f7e8b24f8a68b"
|
||||
|
|
Loading…
Reference in New Issue