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

Version 3.4 uses cmake #37

Open
polarathene opened this issue Jan 2, 2019 · 3 comments
Open

Version 3.4 uses cmake #37

polarathene opened this issue Jan 2, 2019 · 3 comments

Comments

@polarathene
Copy link

Just a heads up with version 3.4(mozjpeg version 3.4.0 (build 20190102)
), they no longer use autotools to build, so your current build script will fail when updating to a newer version. cmake is used now.

@polarathene
Copy link
Author

polarathene commented Jan 2, 2019

For reference I've got mozjpeg building in Alpine docker image(part of a multi-stage build) like so:

# Build mozjpeg on our target version of node-alpine
# Based off https://github.com/egorovli/mozjpeg-docker/
FROM node:10-alpine as mozjpeg-builder

RUN apk --update --no-cache add \
  build-base \
  cmake \
  git \
  libtool \
  nasm

WORKDIR /src/mozjpeg
RUN git clone git://github.com/mozilla/mozjpeg.git ./

WORKDIR /src/mozjpeg/_build
RUN cmake -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_INSTALL_LIBDIR=/usr/local/lib64 .. \
  && make install prefix=/usr/local libdir=/usr/local/lib64

Would be nice to be able to use that binary as the current one doesn't seem to be compatible on alpine. If the bin-wrapper PR goes through to accept an env var to use system binaries instead, that'd also work.

@frossi85
Copy link

@polarathene Did u make this library with imagemin work in linux alpine? I am struggling to make it work, I tried different library versions and installing different build tool in my docker image but is not working in any way.

These are the versions that I used in my last tests:

"imagemin": "7.0.1",
    "imagemin-mozjpeg": "6.0.0",
    "imagemin-optipng": "7.1.0",

This is how I am using the library:

import imagemin from 'imagemin'
import imageminOptipng from 'imagemin-optipng'
import imageminMozjpeg from 'imagemin-mozjpeg'

And this is my Dockerfile:

FROM openfaas/of-watchdog:0.7.2 as watchdog
FROM node:12.13.0-alpine as ship

COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog

RUN apk --no-cache add curl ca-certificates \
	&& addgroup -S app && adduser -S -g app app

WORKDIR /root/

# Turn down the verbosity to default level.
ENV NPM_CONFIG_LOGLEVEL warn

RUN mkdir -p /home/app

# Wrapper/boot-strapper
WORKDIR /home/app
COPY package.json ./

RUN echo $'registry=https://npm.invertifacil.com.ar\n\
//npm.invertifacil.com.ar/:_authToken="some token"' > ~/.npmrc

# This ordering means the npm installation is cached for the outer function handler.
RUN npm i

# Copy outer function handler
COPY index.ts ./
COPY tsconfig.json ./

# COPY function node packages and install, adding this as a separate
# entry allows caching of npm install

WORKDIR /home/app/function

COPY function/*.json ./

RUN if grep "imagemin" ./package.json > /dev/null ; then \
		echo "Installing image min dependencies" &&  \
		apk --update --no-cache add \
				shadow \
				libc6-compat \
				libjpeg-turbo-dev \
				libpng-dev \
				g++ \
				musl-dev \
				autoconf \
				automake \
				cmake \
				make \
				libtool \
				nasm \
				tiff \
				jpeg \
				zlib \
				zlib-dev \
				file \
				pkgconf ; \
	fi

RUN npm i || :

RUN npm rebuild

# COPY function files and folders
COPY function/ ./

# Run any tests that may be available
#RUN npm test

# Set correct permissions to use non root user
WORKDIR /home/app/

# chmod for tmp is for a buildkit issue (@alexellis)
RUN chown app:app -R /home/app \
    && chmod 777 /tmp

USER app

# Compile the whole project
RUN ./node_modules/typescript/bin/tsc --project .

WORKDIR /home/app/function
# Run any tests that may be available
RUN npm test


WORKDIR /home/app/

ENV cgi_headers="true"
ENV fprocess="node index.js"
ENV mode="http"
ENV upstream_url="http://127.0.0.1:3000"

ENV exec_timeout="10s"
ENV write_timeout="15s"
ENV read_timeout="15s"

HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1

CMD ["fwatchdog"]

@xshapira
Copy link

After hours of research and experimenting with different settings, I managed to resolve mozjpeg errors when using Linux/Docker. The issue is particularly when using alpine image.

My updated Dockerfile:

FROM node:12-buster-slim

RUN npm i npm@latest -g

WORKDIR /usr/src

COPY ./app/package*.json ./

RUN apt-get update && apt-get install -y --no-install-recommends \
    autoconf \
    automake \
    g++ \
    libpng-dev \
    make\
    nasm \
    -y wget \
    && wget -q -O /tmp/libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb \
    && dpkg -i /tmp/libpng12.deb \
    && rm /tmp/libpng12.deb \
    && npm install --no-optional && npm cache clean --force \
    npm install -g gulp \
    && npm install gulp

ENV PATH /usr/src/node_modules/.bin/:$PATH

WORKDIR /usr/src/app

COPY . .

These settings might save you hours of frustration. BTW Node's alpine image is NOT recommended because of long build time, even though it's small image size.

Happy coding!

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

3 participants