WeasyPrint install instructions for Alpine Linux

Created on 25 Sep 2018  路  3Comments  路  Source: Kozea/WeasyPrint

Just wanted to recommend adding to documentation instructions to install WeasyPrint in Alpine Linux 3.6. It took me a while but I made it work with this command:
apk --update --upgrade add gcc musl-dev jpeg-dev zlib-dev libffi-dev cairo-dev pango-dev gdk-pixbuf

If someone else have a more efficient aproach (important when working with docker containers for small size images) can comment on this.

documentation

Most helpful comment

Finally!
With the latest versions of alpine & weasyprint we can keep build pretty small & clean.

Here my current approach:

FROM python:3.7-alpine
ENV PYTHONUNBUFFERED 1

RUN apk --update --upgrade --no-cache add \
    cairo-dev pango-dev gdk-pixbuf

...

ADD /etc/pip/requirements.txt /code/requirements.txt
RUN set -ex \
    && apk add --no-cache --virtual .build-deps \
        musl-dev gcc jpeg-dev zlib-dev libffi-dev \
    && pip install --no-cache-dir -r /code/requirements.txt \
    && apk del .build-deps

...

Packages cairo-dev pango-dev gdk-pixbuf need in runtime, so we kept them.
Other ones need only on building stage - so we clean.

In requirements.txt just weasyprint and my specific dependencies, not related to this issue.

All 3 comments

Thank you!

Also spent some time for finding non redundant solution.

As a result of experiments, found next
1) these packages required for running cairo pango gdk-pixbuf
2) these packages required only on the building stage gcc musl-dev libffi-dev jpeg-dev zlib-dev (and could be deleted after that for keeping image as small/clean as possible )

Alpine broke ldconfig...
https://github.com/docker-library/python/issues/111

So unfortunately it looks most simple way now - include gcc and dev versions into build.
This is awful, because size of the image increased 2 times...

packages for run: gcc cairo-dev pango-dev gdk-pixbuf
packages for build: musl-dev jpeg-dev zlib-dev libffi-dev

P.S. Will hope they will fix this, workarounds with LD_LIBRARY_PATH also not looks as working now (waiting PR into python)

Finally!
With the latest versions of alpine & weasyprint we can keep build pretty small & clean.

Here my current approach:

FROM python:3.7-alpine
ENV PYTHONUNBUFFERED 1

RUN apk --update --upgrade --no-cache add \
    cairo-dev pango-dev gdk-pixbuf

...

ADD /etc/pip/requirements.txt /code/requirements.txt
RUN set -ex \
    && apk add --no-cache --virtual .build-deps \
        musl-dev gcc jpeg-dev zlib-dev libffi-dev \
    && pip install --no-cache-dir -r /code/requirements.txt \
    && apk del .build-deps

...

Packages cairo-dev pango-dev gdk-pixbuf need in runtime, so we kept them.
Other ones need only on building stage - so we clean.

In requirements.txt just weasyprint and my specific dependencies, not related to this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amarnav picture amarnav  路  5Comments

muzzamilkhan picture muzzamilkhan  路  3Comments

jeffgabhart picture jeffgabhart  路  3Comments

ivanprice picture ivanprice  路  3Comments

ajakubo1 picture ajakubo1  路  5Comments