-
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
Conversation
Hello @craig-rueda no sure if you're also coordinating the docker changes, but I think this one is ready for review (and should be the last piece of my recent round of Helm updates) and should be really safe. Note that I've integrated the changes from #21379 as well to club the reviews. The new slim image has been running in production for us for about a week now. |
superset-websocket/Dockerfile
Outdated
COPY package*.json ./ | ||
|
||
# Only install production dependencies | ||
RUN npm install --omit=dev |
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
and npm run build
from build container. I think you should copy node_modules
directory as well to the runtime container instead of running npm install
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.
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 bumps
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.
Hmm, it shouldn't because we're also committing package-lock.json
(although I see it's outdated and not in sync with package.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 copy node_modules
from the base
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.
Oh, I think I get it, you mean just use npm ci
rather than npm install
, but still ignoring devDependencies
(which in fact seems to be the default when NODE_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 by npm ci
since the build image doesn't have NODE_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.
SUMMARY
This PR improved the Docker build for the websocket image, in particular by:
node:16-alpine
)devDependencies
in the PRD imageroot
(will prevent from exposing port < 1024)BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Brought down the image size from 380Mb to 42Mb - see the builds published on DockerHub from my fork:
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION