Skip to content
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

Dynamic (native) module loading not supported #3

Closed
alanpearce opened this issue Jan 21, 2019 · 9 comments
Closed

Dynamic (native) module loading not supported #3

alanpearce opened this issue Jan 21, 2019 · 9 comments

Comments

@alanpearce
Copy link

After trying to use these modules, it seems that they cannot load dynamic modules like bcrypt, for example.

I found this issue smebberson/docker-alpine#52 which seems to highlight the --fully-static compilation flag as being responsible for this and noticed that it is indeed passed here.

Would it be possible to get these images to work in a way that supports dynamic module loading, but is still rather small?

@astefanutti
Copy link
Owner

Yes, --fully-static compilation and support for loading dynamic modules are exclusive AFAIK. It should be added to the README.

It may be possible to use the --partly-static flag and add the required dependencies in the image, though that is likely to increase the image size, if that works at all.

@coolaj86
Copy link

@alanpearce I'm just curious: Are you using native modules that you had to write yourself, or is it something leftover from the dark ages of node before we had built-ins? I'm just wondering what in node (other than native desktop apps) still need native modules and why (because some of those problems I'm interested in tackling).

@alanpearce
Copy link
Author

It seems to be the bcrypt module, although there could be others. We haven't written anything native ourselves.

@dzek69
Copy link

dzek69 commented May 15, 2019

A lot of npm modules uses native bindings.
bcrypt, node-sass, sqlite (IIRC), mysql [?].

@alanpearce How much is "rather small" for you?

I've done "rather small" images: https://hub.docker.com/r/dzek69/nodemin/tags
(Size listed on docker hub = transfer size (compressed), container size is 53.5MB) and these should work with dynamic modules

How these are built? I'm taking node alpine official image and simply removing everything that's not needed (npm and yarn for example). System tools are left untouched (so wget and all these are working, busybox, which provides these is 8MB big IIRC). After removal image is squashed into single layer.

See here for Dockerfile: https://github.com/dzek69/docker-node-minimal/blob/master/build/Dockerfile.node - and here: https://github.com/dzek69/docker-node-minimal for more information. Building images by yourself is far from perfect (I'm not good at bash scripts), but it works.

I'm using these on production without any issue.

Sorry for kind of advertisement. I made this project when I discovered scratch-node wasn't working for ARM even when building by myself (#1) and instead of waiting - I just did what it was possible to get as small images as possible without being "too raw".

@alanpearce
Copy link
Author

@dzek69 Those images are pretty cool. We would like to avoid having any kind of tools in the image though. It looks as though there's a pending distroless/node PR which might work for us.

Thanks for the tips though

@astefanutti
Copy link
Owner

astefanutti commented May 17, 2019

This should be fixed with 1da3813.

I've re-pushed the latest, 12.2.0, 12.2 and 12 tags so you can give it a try.

On my side, I've tested it successfully for amd64 and arm32v7.

Thanks for your patience!

@alanpearce
Copy link
Author

Thanks for the new feature! Would it be possible to backport it to node 10? We'd like to stick to LTS versions on production. Node 12 will enter LTS at the end of October. I tried building the image locally and it seems to have worked

@astefanutti
Copy link
Owner

@alanpearce yes, all the documented images have been updated already, so 10, 10.16, 10.16.0 should have support for native modules.

@alanpearce
Copy link
Author

Oh, great, thanks! I must've misunderstood the previous message. 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants