2

I have following Dockerfile which I run on my MacBook Air M1 (so inside docker I have linux with M1)

FROM node:16.7.0
WORKDIR /work
CMD while true; do sleep 10000; done
EXPOSE 3000

Which I build, run and login to container by

docker build --no-cache -t node-cmd-custom .
docker run -d --name node-cmd-custom -p 3000:3000 -v /work/code/metaplex:/work node-cmd-custom
docker exec -it node-cmd-custom bash -c "cd /work/code/metaplex; bash"

And inside docker container I install Metaplex (using official doc) as follows

git clone --branch v1.0.0 https://github.com/metaplex-foundation/metaplex.git
cd metaplex/js && yarn install && yarn bootstrap

But I get following error

[5/5] Building fresh packages...
[6/21] ⠁ canvas
[10/21] ⠁ keccak
[11/21] ⠁ core-js-pure
[9/21] ⠁ secp256k1
error /work/code/metaplex/metaplex/js/node_modules/canvas: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments: 
Directory: /work/code/metaplex/metaplex/js/node_modules/canvas
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@1.0.5
node-pre-gyp info using node@16.7.0 | linux | arm64
node-pre-gyp info check checked for "/work/code/metaplex/metaplex/js/node_modules/canvas/build/Release/canvas.node" (not found)
node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.8.0/canvas-v2.8.0-node-v93-linux-glibc-arm64.tar.gz
node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.8.0/canvas-v2.8.0-node-v93-linux-glibc-arm64.tar.gz 
node-pre-gyp WARN Pre-built binaries not installable for canvas@2.8.0 and node@16.7.0 (node-v93 ABI, glibc) (falling back to source compile with node-gyp) 
node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.8.0/canvas-v2.8.0-node-v93-linux-glibc-arm64.tar.gz 
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.1
gyp info using node@16.7.0 | linux | arm64
gyp info ok 
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.1
gyp info using node@16.7.0 | linux | arm64
gyp info find Python using Python version 2.7.16 found at "/usr/bin/python"
gyp http GET https://nodejs.org/download/release/v16.7.0/node-v16.7.0-headers.tar.gz
gyp http 200 https://nodejs.org/download/release/v16.7.0/node-v16.7.0-headers.tar.gz
gyp http GET https://nodejs.org/download/release/v16.7.0/SHASUMS256.txt
gyp http 200 https://nodejs.org/download/release/v16.7.0/SHASUMS256.txt
(node:238) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
(Use `node --trace-deprecation ...` to show where the warning was created)
gyp info spawn /usr/bin/python
gyp info spawn args [
gyp info spawn args   '/work/code/metaplex/metaplex/js/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/work/code/metaplex/metaplex/js/node_modules/canvas/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/work/code/metaplex/metaplex/js/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.cache/node-gyp/16.7.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.cache/node-gyp/16.7.0',
gyp info spawn args   '-Dnode_gyp_dir=/work/code/metaplex/metaplex/js/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/16.7.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/work/code/metaplex/metaplex/js/node_modules/canvas',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
Package pangocairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `pangocairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'pangocairo' found
gyp: Call to 'pkg-config pangocairo --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/work/code/metaplex/metaplex/js/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Linux 5.10.47-linuxkit
gyp ERR! command "/usr/local/bin/node" "/work/code/metaplex/metaplex/js/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/work/code/metaplex/metaplex/js/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/work/code/metaplex/metaplex/js/node_modules/canvas/build/Release" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93"
gyp ERR! cwd /work/code/metaplex/metaplex/js/node_modules/canvas
gyp ERR! node -v v16.7.0
gyp ERR! node-gyp -v v5.1.1
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /work/code/metaplex/metaplex/js/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/work/code/metaplex/metaplex/js/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/work/code/metaplex/metaplex/js/node_modules/canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/work/code/metaplex/metaplex/js/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
node-pre-gyp ERR! System Linux 5.10.47-linuxkit
node-pre-gyp ERR! command "/usr/local/bin/node" "/work/code/metaplex/metaplex/js/node_modules/canvas/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /work/code/metaplex/metaplex/js/node_modules/canvas
node-pre-gyp ERR! node -v v16.7.0
node-pre-gyp ERR! node-pre-gyp -v v1.0.5

When I try to install only canvas npm install canvas I have similar error

npm ERR! code 1
npm ERR! path /work/code/metaplex/metaplex/node_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install --fallback-to-build
npm ERR! Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/work/code/metaplex/metaplex/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/work/code/metaplex/metaplex/node_modules/canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using node-pre-gyp@1.0.8
npm ERR! node-pre-gyp info using node@16.7.0 | linux | arm64
npm ERR! node-pre-gyp info check checked for "/work/code/metaplex/metaplex/node_modules/canvas/build/Release/canvas.node" (not found)
npm ERR! node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.8.0/canvas-v2.8.0-node-v93-linux-glibc-arm64.tar.gz
npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.8.0/canvas-v2.8.0-node-v93-linux-glibc-arm64.tar.gz 
npm ERR! node-pre-gyp WARN Pre-built binaries not installable for canvas@2.8.0 and node@16.7.0 (node-v93 ABI, glibc) (falling back to source compile with node-gyp) 
npm ERR! node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.8.0/canvas-v2.8.0-node-v93-linux-glibc-arm64.tar.gz 
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@16.7.0 | linux | arm64
npm ERR! gyp info ok 
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@16.7.0 | linux | arm64
npm ERR! gyp info find Python using Python version 3.7.3 found at "/usr/bin/python3"
npm ERR! (node:1436) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/work/code/metaplex/metaplex/node_modules/canvas/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/root/.cache/node-gyp/16.7.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/root/.cache/node-gyp/16.7.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/16.7.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/work/code/metaplex/metaplex/node_modules/canvas',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! Package pangocairo was not found in the pkg-config search path.
npm ERR! Perhaps you should add the directory containing `pangocairo.pc'
npm ERR! to the PKG_CONFIG_PATH environment variable
npm ERR! No package 'pangocairo' found
npm ERR! gyp: Call to 'pkg-config pangocairo --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Linux 5.10.47-linuxkit
npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/work/code/metaplex/metaplex/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/work/code/metaplex/metaplex/node_modules/canvas/build/Release" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93"
npm ERR! gyp ERR! cwd /work/code/metaplex/metaplex/node_modules/canvas
npm ERR! gyp ERR! node -v v16.7.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok 
npm ERR! node-pre-gyp ERR! build error 
npm ERR! node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/work/code/metaplex/metaplex/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/work/code/metaplex/metaplex/node_modules/canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
npm ERR! node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/work/code/metaplex/metaplex/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
npm ERR! node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
npm ERR! node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
npm ERR! node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
npm ERR! node-pre-gyp ERR! System Linux 5.10.47-linuxkit
npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/work/code/metaplex/metaplex/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
npm ERR! node-pre-gyp ERR! cwd /work/code/metaplex/metaplex/node_modules/canvas
npm ERR! node-pre-gyp ERR! node -v v16.7.0
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.8
npm ERR! node-pre-gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-12-28T11_59_12_514Z-debug.log

In documentation there is solution for OSx with M1 processors (which use brew - but actually there is no info how to solve this in Linux with M1 (which is inside docker - and where we not have brew). How to fix it?

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345

1 Answers1

3

Change your dockerfile to (it base on this info) following and install/run metaplex/canvas again

FROM node:16.7.0
WORKDIR /work

RUN apt-get update
RUN apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev

CMD while true; do sleep 10000; done
EXPOSE 3000

(now you can build canvas only using npm install canvas --build-from-source)

If you want do the same on node:16.7.0-alpine (alpine linux) look here

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345
  • This Dockerfile seems to be missing the steps to `COPY` in the application, and to set the `CMD` to run it. Can you edit this answer to reflect better Docker image practice? – David Maze Dec 28 '21 at 14:33
  • @DavidMaze this dockerfile is for develompent - not for production. It only setup container with embeded node which allows to run node commands without actually instaling node directly on my MacOs. After login to this docker container you will have access to linux cmd with node (and project MAPPED form macOS directory into /work container dir - more details in question)... I hope this more is clear now. My goal was to run Metaplex without actually installing node on my macos - just only by using docker. An in this file i only add 2 `RUN` lines which fix problem. – Kamil Kiełczewski Dec 28 '21 at 14:49