feat(mongosh): implement multi-stage build and optimize image size#35
feat(mongosh): implement multi-stage build and optimize image size#35jahirvidrio wants to merge 5 commits into
Conversation
- Introduce multi-stage build to reduce final image footprint. - Implement node-prune and manual cleanup of .d.ts, .ts, and .map files. - Fetch mongosh tarball directly from NPM registry for a leaner build. - Achieved a size reduction of ~100MB compared to the previous version.
ARGs defined before the first FROM instruction are in the global scope but must be re-declared inside each stage to be accessible. This ensures the correct version of mongosh is fetched during the build process.
To ensure compatibility with scripts executed by CircleCI
|
Not big difference |
|
You’re right, the size difference isn't that big. I think I misleadingly framed this PR by focusing on 'optimization' in the title, but the real goal is to finally unblock the mongosh update, which has been stuck for two years. The current approach in #31 is hitting a wall because the new mongosh needs glibc. Trying to force glibc into Alpine (using frolvlad or sgerrand) just adds technical debt and security risks, especially regarding base image trust, as you mentioned.
About the Node.js CVEs, I actually think using This PR is a clean, working way to get mongosh 2.x out there now, without the headache of maintaining a custom Alpine+glibc layer. |
I've implemented a multi-stage build to significantly reduce the final image size.
Changes:
node-pruneand manual cleanup of.d.ts,.ts, and.mapfiles.mongoshtarball directly from NPM registry for a leaner build.