Skip to content

Commit

Permalink
🐛(aws) upgrade cairo version used in lambda convert
Browse files Browse the repository at this point in the history
To convert a PDF into an SVG, we use the tool pdfToCairo made by
poppler. Cairo is responsible to the SVG part. In the lambda, an old
version of cairo is used with a known bug that "mangled" som SVG. To fix
this bug we have to build and install a newer version of Cairo fixing
this bug.
  • Loading branch information
lunika committed Jul 29, 2022
1 parent a788d80 commit 5e2df1b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
4 changes: 3 additions & 1 deletion bin/lambda
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ TAG: optional tag used for the marsha/lambda image (default: production)
tag="${1:-production}"
target="${2:-production}"
DOCKER_BUILDKIT=1 docker build \
--build-arg POPPLER_VERSION="${POPPLER_VERSION:-21.12.0}" \
--build-arg POPPLER_VERSION="${POPPLER_VERSION:-22.07.0}" \
--build-arg POPPLER_DATA_VERSION="${POPPLER_DATA_VERSION:-0.4.11}" \
--build-arg OPENJPEG_VERSION="${OPENJPEG_VERSION:-2.4.0}" \
--build-arg CAIRO_VERSION="${CAIRO_VERSION:-1.17.4}" \
--build-arg PIXMAN_VERSION="${PIXMAN_VERSION:-0.40.0}" \
-t "${LAMBDA_IMAGE_NAME}:${tag}" --target "${target}" "${BASE_DIR}"/../src/aws/
}

Expand Down
6 changes: 3 additions & 3 deletions bin/test_lambda
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export -f docker

# Calling `bin/lambda build` without any arguments should use production tag and target
result=$("${BASE_DIR}"/lambda build)
expected="build --build-arg POPPLER_VERSION=21.12.0 --build-arg POPPLER_DATA_VERSION=0.4.11 --build-arg OPENJPEG_VERSION=2.4.0 -t marsha/lambda:production --target production bin/../src/aws/"
expected="build --build-arg POPPLER_VERSION=21.12.0 --build-arg POPPLER_DATA_VERSION=0.4.11 --build-arg OPENJPEG_VERSION=2.4.0 --build-arg CAIRO_VERSION=1.17.4 --build-arg PIXMAN_VERSION=0.40.0 -t marsha/lambda:production --target production bin/../src/aws/"
assert_equal "${result}" "${expected}"

# Calling `bin/lambda build` with arguments should use given tag and target
result=$("${BASE_DIR}"/lambda build "test_tag" "test_target")
expected="build --build-arg POPPLER_VERSION=21.12.0 --build-arg POPPLER_DATA_VERSION=0.4.11 --build-arg OPENJPEG_VERSION=2.4.0 -t marsha/lambda:test_tag --target test_target bin/../src/aws/"
expected="build --build-arg POPPLER_VERSION=21.12.0 --build-arg POPPLER_DATA_VERSION=0.4.11 --build-arg OPENJPEG_VERSION=2.4.0 --build-arg CAIRO_VERSION=1.17.4 --build-arg PIXMAN_VERSION=0.40.0 -t marsha/lambda:test_tag --target test_target bin/../src/aws/"
assert_equal "${result}" "${expected}"

# Calling `make build-lambda-dev` should use dev tag and development target
result=$(make build-lambda-dev)
expected="build --build-arg POPPLER_VERSION=21.12.0 --build-arg POPPLER_DATA_VERSION=0.4.11 --build-arg OPENJPEG_VERSION=2.4.0 -t marsha/lambda:dev --target development bin/../src/aws/"
expected="build --build-arg POPPLER_VERSION=21.12.0 --build-arg POPPLER_DATA_VERSION=0.4.11 --build-arg OPENJPEG_VERSION=2.4.0 --build-arg CAIRO_VERSION=1.17.4 --build-arg PIXMAN_VERSION=0.40.0 -t marsha/lambda:dev --target development bin/../src/aws/"
assert_equal "${result}" "${expected}"
34 changes: 30 additions & 4 deletions src/aws/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ FROM amazon/aws-lambda-nodejs:14 as core
ARG POPPLER_VERSION
ARG POPPLER_DATA_VERSION
ARG OPENJPEG_VERSION
ARG CAIRO_VERSION
ARG PIXMAN_VERSION

# COPY mediainfo in core stage
COPY --from=mediainfo /tmp/mediainfo/bin/mediainfo /opt/bin/mediainfo
Expand Down Expand Up @@ -45,11 +47,17 @@ RUN yum install -y \
libjpeg-devel \
libpng-devel \
libtiff-devel \
libXrender-devel\
make \
tar \
xz \
zip && \
## download poppler, poppler-data and openjpeg
zip \
zlib-devel && \
## download cairo, poppler, poppler-data and openjpeg
curl -k -o cairo.tar.gz https://cairographics.org/snapshots/cairo-${CAIRO_VERSION}.tar.xz && \
tar -xf cairo.tar.gz && \
curl -k -o pixman.tar.gz https://cairographics.org/releases/pixman-${PIXMAN_VERSION}.tar.gz && \
tar -xf pixman.tar.gz && \
curl -k -o poppler.tar.xz https://poppler.freedesktop.org/poppler-${POPPLER_VERSION}.tar.xz && \
tar -xf poppler.tar.xz && \
curl -k -o poppler-data.tar.gz https://poppler.freedesktop.org/poppler-data-${POPPLER_DATA_VERSION}.tar.gz && \
Expand All @@ -73,9 +81,25 @@ RUN yum install -y \
-DENABLE_LIBOPENJPEG=openjpeg2 -DENABLE_CMS=none -DBUILD_SHARED_LIBS=OFF && \
make && \
make install && cd /root && \
## deinstall cairo
yum erase -y \
cairo-devel \
cairo \
pixman && \
## install pixman
cd pixman-${PIXMAN_VERSION} && \
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --prefix=/usr/local && \
make && \
make install && \
cd /root && \
## install cairo
cd cairo-${CAIRO_VERSION} && \
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --prefix=/usr/local && \
make && \
make install && \
cd /root && \
## Uninstall packages needed to compile poppler
yum erase -y \
cairo-devel \
cmake \
cmake3 \
fontconfig-devel \
Expand All @@ -84,10 +108,12 @@ RUN yum install -y \
libjpeg-devel \
libpng-devel \
libtiff-devel \
libXrender-devel\
make \
tar \
xz \
zip && \
zip \
zlib-devel && \
## Cleanup yum caches
yum clean all && \
rm -rf /var/cache/yum
Expand Down

0 comments on commit 5e2df1b

Please sign in to comment.