node-gfx/node-canvas-prebuilt

linux-musl build

maxheyer opened this issue ยท 10 comments

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

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

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.

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. :)

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 ๐Ÿ‘

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

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.

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

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)

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.

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.