connor4312 / blake3

BLAKE3 hashing for JavaScript: native Node bindings (where available) and WebAssembly
https://connor4312.github.io/blake3/index.html
MIT License
177 stars 18 forks source link

Error trying to import bindings in Dockerfile #20

Closed nasushkov closed 3 years ago

nasushkov commented 3 years ago

Hi I'm using this library in my project and it works well. However, when I try to build a docker image from my Dockerfile I receive the following error:

API version for node@v12.18.2 linux not explicitly built, falling back to latest. If this does not work, open an issue at https://github.com/connor4312/blake3/issues/new Retrieving native BLAKE3 bindings for Node v12 on linux... Error trying to import bindings: Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/src/app/node_modules/blake3/dist/native.node) at Object.Module._extensions..node (internal/modules/cjs/loader.js:1188:18) at Module.load (internal/modules/cjs/loader.js:986:32) at Function.Module._load (internal/modules/cjs/loader.js:879:14) at Module.require (internal/modules/cjs/loader.js:1026:19) at require (internal/modules/cjs/helpers.js:72:18) at /usr/src/app/node_modules/blake3/dist/build/install.js:51:13 at Generator.next () at fulfilled (/usr/src/app/node_modules/blake3/dist/build/install.js:5:58) at processTicksAndRejections (internal/process/task_queues.js:97:5) BLAKE3 will use slower WebAssembly bindings when required in Node.js

My Dockerfile is:

FROM mhart/alpine-node:12.18.2 AS appserver
WORKDIR /usr/src/app
RUN npm install -g typescript
COPY package*.json tsconfig.json ormconfig.js  ./
COPY ./src ./src
RUN npm ci --quiet && npm run build 

FROM mhart/alpine-node:12.18.2 as production
WORKDIR /usr/src/prod
COPY --from=appserver /usr/src/app/package.json ./
COPY --from=appserver /usr/src/app/ormconfig.js ./
COPY --from=appserver /usr/src/app/lib ./lib
COPY --from=appserver /usr/src/app/node_modules ./node_modules
EXPOSE 4000
CMD ["node", "--max_old_space_size=4096", "--max_semi_space_size=256", "./lib/index.js"]

I tried installing the required packages like so:

FROM mhart/alpine-node:12.18.2 AS appserver
LABEL maintainer="nasushkov@gmail.com"
WORKDIR /usr/src/app
RUN apk add --no-cache \ 
    libc6-compat \
    gcompat && \
    npm install -g typescript
COPY package*.json tsconfig.json ormconfig.js  ./
COPY ./src ./src
RUN npm ci --quiet && npm run build

Although the initial error disappears, now it fails with another error:

API version for node@v12.18.2 linux not explicitly built, falling back to latest. If this does not work, open an issue at https://github.com/connor4312/blake3/issues/new Retrieving native BLAKE3 bindings for Node v12 on linux... BLAKE3 will use slower WebAssembly bindings when required in Node.js Error trying to import bindings: Error: Error relocating /usr/src/app/node_modules/blake3/dist/native.node: _ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeEPKNS_9CFunctionE: symbol not found at Object.Module._extensions..node (internal/modules/cjs/loader.js:1188:18) at Module.load (internal/modules/cjs/loader.js:986:32) at Function.Module._load (internal/modules/cjs/loader.js:879:14) at Module.require (internal/modules/cjs/loader.js:1026:19) at require (internal/modules/cjs/helpers.js:72:18) at /usr/src/app/node_modules/blake3/dist/build/install.js:51:13 at Generator.next () at fulfilled (/usr/src/app/node_modules/blake3/dist/build/install.js:5:58) at processTicksAndRejections (internal/process/task_queues.js:97:5)

Is there any workaround for this or maybe there is an image that works out of the box?

Thanks, Nikita

BobbyWibowo commented 3 years ago

Hey there, is the commit https://github.com/connor4312/blake3/commit/9f69ead596225cdef5a7c7eb81b0dd2d8e5e3686 still not thoroughly working to deserve an actual v2.1.5 release? With v2.1.4, I'm still getting these:

$ npm i --update-binary

> deasync@0.1.21 install /home/bobby/src/chibisafe/node_modules/deasync
> node ./build.js

`linux-x64-node-12` exists; testing
Binary is fine; exiting

> bcrypt@5.0.0 install /home/bobby/src/chibisafe/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
[bcrypt] Success: "/home/bobby/src/chibisafe/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" is installed via remote

> blake3@2.1.4 install /home/bobby/src/chibisafe/node_modules/blake3
> node -e "try{require('./dist/build/install')}catch(e){}"

API version for node@v12.20.1 linux not explicitly built, falling back to latest. If this does not work, open an issue at https://github.com/connor4312/blake3/issues/new
Retrieving native BLAKE3 bindings for Node v12 on linux...
Error trying to import bindings: Error: /home/bobby/src/chibisafe/node_modules/blake3/dist/native.node: undefined symbol: _ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeEPKNS_9CFunctionE
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at /home/bobby/src/chibisafe/node_modules/blake3/dist/build/install.js:51:13
    at Generator.next (<anonymous>)
    at fulfilled (/home/bobby/src/chibisafe/node_modules/blake3/dist/build/install.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
BLAKE3 will use slower WebAssembly bindings when required in Node.js

...