-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: Mutli-stage build and slim image for websocket container #21954
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14082d2
Mutli-stage build for websocket image
Yann-J 48e600d
Tweak npm install cmd
Yann-J 6491631
Merge branch 'master' into websocket-slim-image
Yann-J e51356d
Build and publish websocket image in CI
Yann-J 7b334ee
Use npm ci instead of npm install
Yann-J b2a50bb
Sync lock file
Yann-J File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is required since you run
npm ci
andnpm run build
from build container. I think you should copynode_modules
directory as well to the runtime container instead of running npm installThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is because one of the objectives is to avoid having the devDependencies in the production image to keep it slim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, not sure about this one either.
npm install
can make the builds non-deterministic as it can do patch version bumpsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it shouldn't because we're also committing
package-lock.json
(although I see it's outdated and not in sync withpackage.json
? some people tend to think it shouldn't be committed, but that's a misconception) - but more importantly this has little to do with whether the build is single or multi-stage - versions will be resolved at build time in both cases.Note that I didn't invent this... multi-stage builds with a prd-only
npm install
in the final image are a well established pattern for nodejs apps.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm ci
leverages the contents of the.lock
file to make a "clean" install (https://docs.npmjs.com/cli/v8/commands/npm-ci#description)Agree that multi-stage builds are good :). I just think that we should be doing an
npm ci
there, or just copynode_modules
from the baseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think I get it, you mean just use
npm ci
rather thannpm install
, but still ignoringdevDependencies
(which in fact seems to be the default whenNODE_ENV=production
)?Yeah, that seems to make sense, as long as we agree on not dragging the
devDependencies
(which in the build image, would be installed bynpm ci
since the build image doesn't haveNODE_ENV=production
- which is a good thing since the build image obviously needs those). Those don't just make the image fatter, they also increase the security footprint / exposure of the image...I've just pushed the change, and also re-synced up the lock file.