Hi all,
I'm struggling from few days to make work a Grpc service in NodeJs within my minikube cluster while developing.
It is very clear 馃. Grpc needs to be compiled / rebuilt within the right bindings of the OS is running.
I'm developing in MacOS Sierra OS, my Grpc service runs in a Alpine-Linux OS.
I'm installing my node dependencies outside the container (my mac machine).
This because i don't want to setup github authentication in my docker image and make it complex to maintain. So yarn install is run in my CI tool as well as locally.
I'm using Kubernetes and minikube to spawn my cluster and developing the application on it.
To do so, i'll need to mount a Volume which get bound to my local machine, within the directory where the application live.
# Rest of the Manifesto...
spec:
containers:
- name: authors
image: myvendor/authors:latest
ports:
- containerPort: 50051
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /var/www/authors/
name: app-shared-authors
volumes:
- name: app-shared-authors
hostPath:
path: /Users/fenos/Documents/Projects/myproject/authors/src # Local path
My docker file will instead looks like this:
FROM my-vendor/node-9.3
MAINTAINER me
ENV DEST_FOLDER=/var/www/authors
COPY src $DEST_FOLDER
WORKDIR $DEST_FOLDER
EXPOSE 50051
RUN yarn global add knex && npm rebuild grpc --update-binary
CMD ["sh", "-c", "npm run migrate && pm2-docker start pm2.config.js --only authors-service-development"]
As soon as my container starts up i get the following error (Obviously):
c0|authors- | { Error: Failed to load gRPC binary module because it was not installed for the current system
0|authors- | Expected directory: node-v57-linux-x64-musl
0|authors- | Found: [node-v57-darwin-x64-unknown]
0|authors- | This problem can often be fixed by running "npm rebuild" on the current system
0|authors- | Original error: Cannot find module '/var/www/authors/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-musl/grpc_node.node'
0|authors- | at Object.<anonymous> (/var/www/authors/node_modules/grpc/src/grpc_extension.js:53:17)
0|authors- | at Module._compile (module.js:635:30)
0|authors- | at Module._extensions..js (module.js:646:10)
0|authors- | at Object.require.extensions.(anonymous function) [as .js] (/var/www/authors/node_modules/babel-register/lib/node.js:152:7)
0|authors- | at Module.load (module.js:554:32)
0|authors- | at tryModuleLoad (module.js:497:12)
0|authors- | at Function.Module._load (module.js:489:3)
0|authors- | at Module.require (module.js:579:17)
0|authors- | at require (internal/module.js:11:18)
0|authors- | at Object.<anonymous> (/var/www/authors/node_modules/grpc/src/client.js:37:12)
0|authors- | at Module._compile (module.js:635:30)
0|authors- | at Module._extensions..js (module.js:646:10)
0|authors- | at Object.require.extensions.(anonymous function) [as .js] (/var/www/authors/node_modules/babel-register/lib/node.js:152:7)
My second trial was to rebuild grpc at start point within the CMD instruction as following:
CMD ["sh", "-c", "npm rebuild grpc --update-binary && npm run migrate && pm2-docker start pm2.config.js --only authors-service-development"]
As soon as the container tries to start i get the following error and the container dies:
npm ERR! path ../detect-libc/bin/detect-libc.js
npm ERR! code EPERM
npm ERR! errno -1
npm ERR! syscall symlink
npm ERR! Error: EPERM: operation not permitted, symlink '../detect-libc/bin/detect-libc.js' -> '/var/www/authors/node_modules/grpc/node_modules/.bin/detect-libc'
npm ERR! { Error: EPERM: operation not permitted, symlink '../detect-libc/bin/detect-libc.js' -> '/var/www/authors/node_modules/grpc/node_modules/.bin/detect-libc'
npm ERR! stack: 'Error: EPERM: operation not permitted, symlink \'../detect-libc/bin/detect-libc.js\' -> \'/var/www/authors/node_modules/grpc/node_modules/.bin/detect-libc\'',
npm ERR! errno: -1,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'symlink',
npm ERR! path: '../detect-libc/bin/detect-libc.js',
npm ERR! dest: '/var/www/authors/node_modules/grpc/node_modules/.bin/detect-libc' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-05-07T20_22_33_767Z-debug.log
I even tried to ssh into the container once started and run manually npm rebuild grpc but the same error of above occurred.
Can you please share your experience with this kind of setup!
Is there a nice way or workaround to make this combo working together?
(Grpc + Shared Volume with the host)?
I don't know the yarn equivalent would be, but you can always do this outside of your container:
npm rebuild --target=1.9.0 --target_libc=musl --target_platform=linux
The list of options you can pass is described here: https://www.npmjs.com/package/node-pre-gyp
@nicolasnoble Absolutely appreciate your trick!
I tried to run the exact command you provided but it was complaining about the --target flag.
I'm not sure i've understood it well what the --target flag mens, but I think is the version of my node-js runtime, am i right?
I've removed the --target flag and that worked! 馃帀 馃帀
Yes, sorry, the proper way was in fact --target=9.0.0 - that's the base version for NodeJS. Don't know why I put 1.9.0 here instead.
Anyway, closing this one.
Lovely, thanks again
Most helpful comment
I don't know the
yarnequivalent would be, but you can always do this outside of your container:The list of options you can pass is described here: https://www.npmjs.com/package/node-pre-gyp