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

Native bcrypt requires additional command to compile on build #18

Closed
GuestInCorle opened this issue Jul 30, 2019 · 2 comments
Closed

Native bcrypt requires additional command to compile on build #18

GuestInCorle opened this issue Jul 30, 2019 · 2 comments

Comments

@GuestInCorle
Copy link

GuestInCorle commented Jul 30, 2019

Application silently crashes when Accounts#createUser is called.

I've cloned the latest version of your repo, added accounts-password Meteor package and bcrypt npm package, called Accounts.createUser server-side and expected it to work. Application crashed with no errors and traces in the logs.

I've forked to repo to reproduce this bug. See README and last commit. Keep in mind that port 9229 is exposed and --inspect Node.js option is passed to be able to use chrome://inspect tool.

@GeoffreyBooth
Copy link
Collaborator

Thank you for the detailed report and reproduction repo. This issue was also reported in https://forums.meteor.com/t/meteor-docker-image-for-multistage-docker-builds/44908/11.

The source of the issue is the dependency you added, bcrypt. Per https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions#alpine-linux-based-images:

Alpine linux based images use musl libc instead of the standard glibc and thus are not compatible with compiled binaries. node-pre-gyp currently does not test the pre-compiled binaries to be ABI-compatible and thus you may see segfaults. We are working to resolve this issue.

As a workaround, in Alpine based images, force recompiling the bcrypt native addon after a npm install with this command: npm rebuild bcrypt --build-from-source.

So we need to add npm rebuild bcrypt --build-from-source at the appropriate place. I see in your repo that you’re using app-with-native-dependencies.dockerfile, which is a good start. In that file, change the build-meteor-npm-dependencies.sh line to this:

RUN bash $SCRIPTS_FOLDER/build-meteor-npm-dependencies.sh \
	&& cd $APP_BUNDLE_FOLDER/bundle/programs/server/npm \
	&& npm rebuild --build-from-source bcrypt \
	&& apk del .node-gyp-compilation-dependencies

When I do this and rebuild, your app no longer crashes.

@GeoffreyBooth GeoffreyBooth changed the title Application silently crashes Native bcrypt requires additional command to compile on build Jul 30, 2019
@GeoffreyBooth
Copy link
Collaborator

I’ve updated the base image so that using app-with-native-dependencies.dockerfile causes npm rebuild --build-from-source to be run. This means that in the future, someone following the instructions in the README should be able to just install bcrypt and go, without needing to discover this issue and/or edit their dockerfile.

@tennox tennox mentioned this issue Oct 8, 2019
@gregory gregory mentioned this issue Feb 12, 2021
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

2 participants