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

Not working in node:alpine Docker base image #47

Closed
kachkaev opened this issue May 11, 2019 · 7 comments · May be fixed by #57
Closed

Not working in node:alpine Docker base image #47

kachkaev opened this issue May 11, 2019 · 7 comments · May be fixed by #57

Comments

@kachkaev
Copy link

kachkaev commented May 11, 2019

I've got an app that relies on mozjpeg-bin the following way:

import imagemin from "imagemin";
import imageminMozjpeg from "imagemin-mozjpeg";

// ...

await imagemin(["/path/to/my/file.jpg"], "/output-path", {
  plugins: [imageminMozjpeg({ quality: 42 })],
});

Things work locally on macOS and in Docker, when an image is based on node:10.15.3 (Debian). However, when I switch to node:10.15.3-alpine, the following error shows up for each attempt to optimize an image:

Error in file: /path/to/my/file.jpg

spawn /app/node_modules/mozjpeg/vendor/cjpeg ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)

I tried a few workaround including installing libjpeg-turbo and libjpeg-turbo-utils packages and even tried some crazy things like swapping the binary in node_modules/mozjpeg/vendor/cjpeg, but no result after hours of hacking. The only solution was to switch back to Debian at a cost of a large added container size.

What can be done to make mozjpeg work in Alpine? Happy to switch back, but unfortunately can't manage this myself.

@kachkaev kachkaev changed the title Not working i node:alpine Docker base image Not working in node:alpine Docker base image May 11, 2019
@divick
Copy link

divick commented Jul 5, 2019

+1

@divick
Copy link

divick commented Jul 5, 2019

@kachkaev I have been able to resolve this issue. On investigating I found that imagemin-mozjpeg installs mozjpeg-bin but in absence of autoconf, automake, libtool, make, gcc, musl-dev and nasm cannot build mozjpeg-bin from source and pulls in a GLIBC linked binary from github. Since alpine linux has musl-dev, the cjpeg cannot run without rebuilding/relinking with musl libc.

Just install the above packages with apk add and then do npm install and it should work.

@kachkaev
Copy link
Author

kachkaev commented Jul 5, 2019

Great news @divick! Feel free to share the dockerfile recipe. I probably won’t change my setup for now, but people coming here from search will definitely be happy to see the solution!

@divick
Copy link

divick commented Jul 6, 2019

Additionally you may need zlib-dev, pkgconf and file packages to be installed in alpine image.

@divick
Copy link

divick commented Jul 6, 2019

Here is the recipe for docker image based on node:10-15-alpine, which has node v10 and yarn already installed.

One can use alpine-3.9 image too but would need to add build steps to install node and yarn/npm.

FROM node:10.15-alpine                                                                            
                                                                                                  
RUN apk --no-cache add shadow \                                                                   
    gcc \                                                                                         
    musl-dev \                                                                                    
    autoconf \                                                                                    
    automake \                                                                                    
    make \                                                                                        
    libtool \                                                                                     
    nasm \                                                                                        
    tiff \                                                                                        
    jpeg \                                                                                        
    zlib \                                                                                        
    zlib-dev \                                                                                    
    file \                                                                                        
    pkgconf \                                                                                     
    && yarn install

@BenMatheja
Copy link

Want to extend what @divick wrote.
With the current image of node:alpine these dependencies allowed me to build mozjpeg within my drone-runner

- name: npm install
    image: node:alpine
    commands:
      - apk add autoconf automake libtool make tiff jpeg zlib zlib-dev pkgconf nasm file gcc musl-dev
      - npm install

@1000ch
Copy link
Contributor

1000ch commented Sep 30, 2020

As above, we need to install appropriate dependencies for mozjpeg to use it on any platform including alpine.

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

Successfully merging a pull request may close this issue.

4 participants