-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add git to the alpine image #367
Conversation
|
What does this add to the image size? |
Depends if it needs it. In the case of npm, I would argue it needs it, since npm includes support for git URLs as dependencies. See the related issue I opened #366
17.6 MB. I pulled 7.4-alpine, then made a simple Dockerfile extending it with just git:
Now one could argue that the really right solution is for npm to access git natively, not call out to the external binary, but until that happens... |
17.6 MB is way to much for what is supposed to be the smallest Docker image possible. |
I agree. I'd prefer documenting this as a common usecase instead of adding it to the image. |
I am somewhat torn. Adding 1/3 to the image size is a lot. On the other hand, without it, a well-documented and heavily-used official standard npm use case is broken.
If it doesn't support npm's documented features, is it the smallest possible? I don't know. Coming back to where this started, I think the correct thing is fixing npm to support git natively (is npm itself in JS? Most langs have some form of native git support), but until then... |
Yeah, that's a significant increase in size. 👎 The main use case for the Alpine image is to provide something really small that users can build upon. So for me the working assumption is yeah, you'll need to install things like git. The same applies to the slim variants. A lot of npm modules will fail to install because the I think we need to document the above (that it's a minimal image and you will need git and And really we need to probably document some very strict criteria for adding things to the slim and alpine images. |
Yeah. The docs probably should say something like, "contains only node and npm, period. If you try to install an npm package with additional dependencies like git or python or... it will fail. Extend the image and make your own with those dependencies installed." |
You mean like the description on the Docker Hub:
|
Ha! |
We should probably update the README to also mention build-base. |
"some stuff like xx is not included" is not quite the same as "the following basic npm features require additional installs: ____" |
I'm really on the fence with this one....I want to keep the size to a minimum but the Node package should work out of the box and since npm is packaged with it, that also should work. That part of the docs, I interpret as saying that alpine shouldn't include "helpful tools" such as bash which is easier to use than the builtin sh. However, you could argue that in this case, git is a dependency of npm. |
@LaurentGoderre : you said that much more eloquently than I did! :-) Any idea why: a- git is so darn big? checking on my Mac, it is all compiled binaries |
One could also argue that npm is strictly not a part of node, providing it with the official image is only done as a service to our users (it is provided with the official nodejs distribution). |
I think it is inseparable at this point. In the early days, when they were separate installs, maybe. At this point, it is a single install, and just about everything is packaged via npm and required to run almost any programs. |
@deitch I think a big chunk of the size is merge tools |
More precisely, git is an optional dependency of npm. Many applications (probably most) don't really need it. I admit though that the lines are blurry especially after we already included Yarn in the Alpine image. Still, I think there were two factors which made it a bit more suitable for inclusion than git:
I still think the best approach would be to document the most common use cases. Need to install modules from git? Do this. Need native modules? Do that. Need Flowtype? Do that. |
Perhaps we'd need a whole separate document dedicated to alpine, we could document ndoe-gyp, this, FFlow-type etc.. |
npm seems to centralize git actions here https://github.com/npm/npm/blob/latest/lib/utils/git.js which just |
We ran into this issue for building, and ended up splitting our image so we have a build image and a runtime image because we wanted to keep our runtime alpine image as tiny as possible. The build image has git, build tools, and runs Simplified version of our images: https://gist.github.com/EnzoMartin/6b40242e38b6ae232c9d6c990871b454 |
@EnzoMartin funny, that is precisely what I do with go, java, and any other lang that has a compile-time environment. I never really thought of node in that light. I guess you could argue that a truly lightweight node image would have just node, not even npm, as npm is part of the build-time. But I don't see the world going that way; try to remove npm from this image and see what happens. :-) |
Agreed. I would not want to see I would actually love to see |
So can we close this? |
@EnzoMartin thanks so much for sharing that build thing, I had never seen this in Docker and I can find quite a bit of use for that? |
You'll find similar set up for using languages that generate an artifact, like for Java or Go services that have an executable file that gets compiled. You don't want the runtime to be responsible for building as that generates a lot of layers and dependencies that are simply not needed for the actual runtime and breaks the docker layer caching that would otherwise speed up the container build times. It's just not something that's been documented/talked about much in the Node ecosystem yet |
These upcoming Docker changes would make most of this obsolete also: http://blog.alexellis.io/mutli-stage-docker-builds/ |
I've found this issue after discovering that my build was failing on gitlab using an alpine node image due to a valid git+ package specification. I wouldn't expect a node image to not support this, so it was very surprising. I hadn't initially spotted this as Gitlab was caching my node_modules directory. I agree with the proposer, if it doesn't work with valid package.json files, then its not really a node image. |
Then you should use the full NodeJS image, not the alpine image. |
All of this might get resolved with the new builder pattern that Docker released. We might be able to have a build and a production image. |
What base images would we use for a multi stage build? |
@james you can use any of them really. Alpine is the smallest but requires more work sometimes to setup |
I inclined for |
Some are suggesting multistage build is a solution but I'm not sure how a requirement for when |
@SalathielGenese you would run npm in the first stage (where git would be installed) and copy the installed modules to the second stage (without git) |
Malin le gringo, Thanks @LaurentGoderre, much thanks !!! |
Just add
In your |
It is important to keep the image as slim as possible (even in multiple stage build)... So am I using
May I note here that what I first missed is that |
express-cache-middleware depends on express-mung, which is pulled directly from git. See nodejs/docker-node#367
Fixes #366