Change scripts to use npm ci and webpack --mode development by default #10221
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
pinot-controllercontains a resource which is the controller frontend, which is built with npm. This PR tries to improve the developer relation with these code by:npm ciinstead ofnpm install.webpack --mode developmentinstead ofwebpack --mode productionby default.The first is a recommended way to build npm projects when package-lock.json is used. From https://docs.npmjs.com/cli/v9/commands/npm-ci:
The differences with
npm installcan be seen in the link above, but the main idea is thatnpm ciwill always use the dependencies inpackage-lock.jsonwhilenpm installwill try to verify if there is a newer library version (when open versions, aka ^ in npm, are used). By usingnpm ciwe are going to have more repeatable builds. The idea is that whenever we actually want to upgrade dependencies we should donpm install(or the alternative that only updates the single dependency we care about) locally, which will modify thepackage-lock.jsonand the commit that file, which will make that anynpm ciexecuted after that (in both dev envs and ci env) will use the new dependency.The second change tries to accelerate the build in dev machines. Right now the
generate-resourcesmaven phase is bound to executenpm run-script build, which in fact executeswebpack --mode production. There is another npm script calledbuild-devwhich runswebpack --mode development. The difference between these modes can be seen in the offical documentation, but the idea is that development mode should be used in... well, development environments. It will not mangle the code, which means that it will be more verbose and easier to debug, but it will take less time to create the package.What this PR does is to add and use a new npm script called
build-ciwhich is defined as:CI is a variable defined in most CIs, including GitHub Actions (link). If this variable is defined and its value is true, then
npm run-script buildwill be executed, which is the normal behavior right now. Otherwisenpm run-script build-devwill be executed. Therefore in dev machines, where CI env variable will not be defined, we will build the bundle using the faster and easier to debug mode.In the build log we can know whether it is using one mode or the other. For example:
This PR also changes the dockerfile when building Pinot in order to set the CI variable to true by default. This is needed to correctly build the image in both CI environments and in local ones, although we can opt out by setting the docker ARG to false