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

linux-musl build #77

Open
maxheyer opened this issue May 3, 2019 · 10 comments
Open

linux-musl build #77

maxheyer opened this issue May 3, 2019 · 10 comments

Comments

@maxheyer
Copy link

maxheyer commented May 3, 2019

Hi @chearon,
as many others we use docker for our development and continuous integration process. Linux Alpine uses musl as standard library which is currently not supported. I would find an linux-musl build useful.

Resources:
https://www.musl-libc.org/
https://alpinelinux.org/posts/Alpine-Linux-has-switched-to-musl-libc.html

@dvishniakov
Copy link

Hi @chearon , do you have any thoughts whether it could be easily added? I can't tag LinusU for some reason

@chearon
Copy link
Member

chearon commented Jul 2, 2019

I'll definitely accept a PR and help out as much as I can, but I haven't done any work on it. The easiest path would be to find a docker image that has musl (alpine?) and copy the RUN commands from the current docker file, then update the .travis.yml to invoke it after the glibc docker image. Off the top of my head that should be all that's needed, but getting the dockerfile working will probably not be simple.

@GimpMaster
Copy link

Would love to see the musl build as well. For now i'll attempt to build from node-gyp. Hopefully I don't need to add too many packages to Alpine. :)

@GimpMaster
Copy link

Just an FYI...these are the packages I had to add on Alpine. I might not have got them all but here is some of my history.

apk add --no-cache make gcc g++ python pkgconfig pixman-dev cairo-dev pango-dev libjpeg-turbo-dev giflib-dev

This allowed me to build. Now to test if it runs ok 👍

@FibreFoX
Copy link

Starting from alpine:edge I had to add this to make it working (as no other way was working for me):

apk add --no-cache nodejs npm build-base g++ cairo-dev jpeg-dev pango-devbash imagemagick
npm i -g node-gyp

Just for reference: Automattic/node-canvas#866

@nicoduj
Copy link

nicoduj commented Apr 19, 2020

Hi, i had this problem on an alpine based docker image (Homebridge / oznu).
I installed the following package to make it compile, even if there are some warnings during the compilation :
-e PACKAGES=build-base,cairo-dev,jpeg-dev,pango-dev,giflib-dev,librsvg-dev

I don't think bash / imageMagick are needed however.

@andriusign
Copy link

andriusign commented Jul 21, 2021

Adding these two lines to .gitlab-ci.yml fixed the problem:
image

apk add --no-cache build-base g++ cairo-dev jpeg-dev pango-dev giflib-dev
apk add --update --repository http://dl-3.alpinelinux.org/alpine/edge/testing libmount ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family fontconfig

@asbaghel08
Copy link

Just an FYI...these are the packages I had to add on Alpine. I might not have got them all but here is some of my history.

apk add --no-cache make gcc g++ python pkgconfig pixman-dev cairo-dev pango-dev libjpeg-turbo-dev giflib-dev

This allowed me to build. Now to test if it runs ok 👍

(node:181) UnhandledPromiseRejectionWarning: Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /app/node_modules/canvas/build/Release/libpixman-1.so.0)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object. (/app/node_modules/canvas/lib/bindings.js:3:18)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)

@smollweide
Copy link

smollweide commented Jul 26, 2022

Using node:16.16.0-bullseye instead of node:16.16.0-alpine fixed the problem for me. But I hope Alpine will be supported soon.

da70 added a commit to NYULibraries/primo-explore-devenv that referenced this issue May 8, 2023
….2` to succeed [+]

Added packages mentioned in [this comment](node-gfx/node-canvas-prebuilt#77 (comment)) of [linux\-musl build \ExLibrisGroup#77](node-gfx/node-canvas-prebuilt#77) to fix this problem in `docker compose` `web` build:

```shell
Command: node-pre-gyp install --fallback-to-build --update-binary
Arguments:
Directory: /tmp/node_modules/canvas
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using [email protected]
node-pre-gyp info using [email protected] | linux | x64
node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v93-linux-musl-x64.tar.gz
node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v93-linux-musl-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v93 ABI, musl) (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.11.2/canvas-v2.11.2-node-v93-linux-musl-x64.tar.gz
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info ok
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp ERR! find Python
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python3" can be used
gyp ERR! find Python - "python3" is not in PATH or produced an error
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - "python" is not in PATH or produced an error
gyp ERR! find Python
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:330:47)
gyp ERR! stack     at PythonFinder.runChecks (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:159:21)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:202:16)
gyp ERR! stack     at PythonFinder.execFileCallback (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:294:16)
gyp ERR! stack     at exithandler (node:child_process:408:5)
gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:420:5)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
gyp ERR! stack     at onErrorNT (node:internal/child_process:478:16)
gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
gyp ERR! System Linux 5.4.0-1025-aws
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" "--update-binary" "--module=/tmp/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/tmp/node_modules/canvas/build/Release" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93"
gyp ERR! cwd /tmp/node_modules/canvas
gyp ERR! node -v v16.17.0
gyp ERR! node-gyp -v v9.0.0
gyp ERR! not ok
node-pre-gyp ERR! build error
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 --update-binary --module=/tmp/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/tmp/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> (/tmp/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1093:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
node-pre-gyp ERR! System Linux 5.4.0-1025-aws
node-pre-gyp ERR! command "/usr/local/bin/node" "/tmp/node_modules/canvas/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" "--update-binary"
node-pre-gyp ERR! cwd /tmp/node_modules/canvas
node-pre-gyp ERR! node -v v16.17.0
node-pre-gyp ERR! node-pre-gyp -v v1.0.10
node-pre-gyp ERR! not ok
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 --update-binary --module=/tmp/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/tmp/node_modules/canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
ERROR: Service 'web' failed to build: The command '/bin/sh -c cd /tmp && yarn install --frozen-lockfile --ignore-optional   && mkdir -p $INSTALL_PATH   && cd $INSTALL_PATH   && cp -R /tmp/node_modules $INSTALL_PATH   && rm -r /tmp/* && yarn cache clean' returned a non-zero code: 1
```

For details, see `canvas` issue: [How to Troubleshoot Installation \#1511](Automattic/node-canvas#1511)
@stefan2718
Copy link

If anyone else is looking to cut down on their final image size, this is how I was able to use a multi-stage build to do so. Doing this reduces the final image size by about 300 mb. Note that I have not included the GIF and SVG libs, since I don't need them for my case.

FROM node:20-alpine AS build
RUN apk add --no-cache make gcc g++ python3 pkgconfig pixman-dev cairo-dev pango-dev libjpeg-turbo-dev
COPY package.json package-lock.json ./
RUN npm ci

FROM node:20-alpine
## These are runtime dependencies required by node-canvas
RUN apk add --no-cache cairo pango libjpeg-turbo
COPY --from=build  /node_modules ./node_modules
...etc.

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

10 participants