Skip to content

Instantly share code, notes, and snippets.

@RulerOf
Created May 22, 2024 19:43
Show Gist options
  • Save RulerOf/2dd33681032ef9edf4dc551f25339c7d to your computer and use it in GitHub Desktop.
Save RulerOf/2dd33681032ef9edf4dc551f25339c7d to your computer and use it in GitHub Desktop.
Build ImageMagick into a Ruby AWS Lambda build image at /opt
FROM public.ecr.aws/sam/build-ruby3.2:latest as builder
# Prereqs
RUN yum install -y git gcc gcc-c++ cpp cpio make cmake automake autoconf chkconfig clang clang-libs dos2unix zlib zlib-devel zip unzip tar perl libxml2 bzip2 bzip2-libs xz xz-libs pkgconfig libtool
# libjpg
RUN cd /root && \
curl https://github.com/winlibs/libjpeg/archive/refs/tags/libjpeg-9c.tar.gz -L -o tmp-libjpeg.tar.gz && \
tar xf tmp-libjpeg.tar.gz && \
cd libjpeg* && \
dos2unix * && \
dos2unix -f configure && \
chmod +x configure && \
PKG_CONFIG_PATH=/root/build/cache/lib/pkgconfig \
./configure \
CPPFLAGS=-I/root/build/cache/include \
LDFLAGS=-L/root/build/cache/lib \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=/root/build/cache && \
dos2unix -f libtool && \
make -j$(nproc) && \
make install
# libpng
RUN cd /root && \
curl http://prdownloads.sourceforge.net/libpng/libpng-1.6.43.tar.xz -L -o tmp-libpng.tar.xz && \
tar xf tmp-libpng.tar.xz && \
cd libpng* && \
PKG_CONFIG_PATH=/root/build/cache/lib/pkgconfig \
./configure \
CPPFLAGS=-I/root/build/cache/include \
LDFLAGS=-L/root/build/cache/lib \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=/root/build/cache && \
make -j$(nproc) && \
make install
# webp
RUN cd /root && \
curl https://github.com/webmproject/libwebp/archive/v1.4.0.tar.gz -L -o tmp-libwebp.tar.gz && \
tar xf tmp-libwebp.tar.gz && \
cd libwebp* && \
sh autogen.sh && \
PKG_CONFIG_PATH=/root/build/cache/lib/pkgconfig \
./configure \
CPPFLAGS=-I/root/build/cache/include \
LDFLAGS=-L/root/build/cache/lib \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=/root/build/cache && \
make -j$(nproc) && \
make install
# libde265
RUN cd /root && \
curl https://github.com/strukturag/libde265/releases/download/v1.0.15/libde265-1.0.15.tar.gz -L -o tmp-libde265.tar.gz && \
tar xf tmp-libde265.tar.gz && \
cd libde265* && \
sh autogen.sh && \
PKG_CONFIG_PATH=/root/build/cache/lib/pkgconfig \
./configure \
CPPFLAGS=-I/root/build/cache/include \
LDFLAGS=-L/root/build/cache/lib \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=/root/build/cache && \
make -j$(nproc) && \
make install
# heif
RUN cd /root && \
curl https://github.com/strukturag/libheif/releases/download/v1.15.2/libheif-1.15.2.tar.gz -L -o tmp-libheif.tar.gz && \
tar xf tmp-libheif.tar.gz && \
cd libheif* && \
sh autogen.sh && \
PKG_CONFIG_PATH=/root/build/cache/lib/pkgconfig \
./configure \
CPPFLAGS=-I/root/build/cache/include \
LDFLAGS=-L/root/build/cache/lib \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=/root/build/cache && \
make -j$(nproc) && \
make install
# jp2
RUN cd /root && \
curl https://github.com/uclouvain/openjpeg/archive/v2.4.0.tar.gz -L -o tmp-libopenjp2.tar.gz && \
tar xf tmp-libopenjp2.tar.gz && \
cd openjpeg* && \
mkdir -p build && \
cd build && \
PKG_CONFIG_PATH=/root/build/cache/lib/pkgconfig \
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/root/build/cache \
-DBUILD_SHARED_LIBS:bool=off \
-DBUILD_CODEC:bool=off && \
make clean && \
make -j$(nproc) install
# tiff
RUN cd /root && \
curl http://download.osgeo.org/libtiff/tiff-4.6.0.tar.gz -L -o tmp-libtiff.tar.gz && \
tar xf tmp-libtiff.tar.gz && \
cd tiff* && \
PKG_CONFIG_PATH=/root/build/cache/lib/pkgconfig \
./configure \
CPPFLAGS=-I/root/build/cache/include \
LDFLAGS=-L/root/build/cache/lib \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=/root/build/cache && \
make -j$(nproc) && \
make install
# Libbz2
RUN cd /root && \
curl http://prdownloads.sourceforge.net/bzip2/bzip2-1.0.6.tar.gz -L -o tmp-bzip2.tar.gz && \
tar xf tmp-bzip2.tar.gz && \
cd bzip2* && \
make libbz2.a && \
make -j$(nproc) install PREFIX=/root/build/cache
# lcms
RUN cd /root && \
curl https://github.com/mm2/Little-CMS/releases/download/lcms2.16/lcms2-2.16.tar.gz -L -o tmp-lcms2.tar.gz && \
tar xf tmp-lcms2.tar.gz && \
cd lcms2* && \
sh autogen.sh && \
PKG_CONFIG_PATH=/root/build/cache/lib/pkgconfig \
./configure \
CPPFLAGS=-I/root/build/cache/include \
LDFLAGS=-L/root/build/cache/lib \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=/root/build/cache && \
make -j$(nproc) && \
make install
# Imagemagick
RUN cd /root && \
curl https://github.com/ImageMagick/ImageMagick/archive/7.1.1-32.tar.gz -L -o tmp-imagemagick.tar.gz && \
tar xf tmp-imagemagick.tar.gz && \
cd ImageMagick* && \
PKG_CONFIG_PATH=/root/build/cache/lib/pkgconfig \
./configure \
CPPFLAGS=-I/root/build/cache/include \
LDFLAGS="-L/root/build/cache/lib -lstdc++" \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=/opt \
--enable-delegate-build \
--disable-installed \
--without-modules \
--disable-docs \
--without-magick-plus-plus \
--without-perl \
--without-x \
--disable-openmp && \
make clean && \
make all -j$(nproc) install
FROM public.ecr.aws/sam/build-ruby3.2:latest
COPY --from=builder /opt /opt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment