From 8fa4e8e2d1711e460e2d33366b2730b1c0d23c2d Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Thu, 23 Jan 2025 19:28:42 +0530 Subject: [PATCH] Try using staticx on vips binary Dockerfile from https://github.com/joshuarli/static-builders --- desktop/scripts/vips/Dockerfile.staticx | 78 +++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 desktop/scripts/vips/Dockerfile.staticx diff --git a/desktop/scripts/vips/Dockerfile.staticx b/desktop/scripts/vips/Dockerfile.staticx new file mode 100644 index 0000000000..a64c3fecab --- /dev/null +++ b/desktop/scripts/vips/Dockerfile.staticx @@ -0,0 +1,78 @@ +FROM debian:bullseye + +# Don't care about layer size. +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + gcc-10 \ + make \ + pkg-config + +# Don't care about layer size. +RUN apt-get install -y --no-install-recommends \ + python3-minimal \ + python3-pip \ + python3-setuptools \ + patchelf + +RUN python3 -m pip \ + --disable-pip-version-check \ + --no-cache-dir \ + install \ + 'staticx==0.12.0' + +# Don't care about layer caching, because I'm only using docker for building. +RUN apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + g++ \ + g++-10 \ + libglib2.0-dev \ + libexpat1-dev \ + libjpeg-dev \ + libpng-dev \ + libimagequant-dev \ + libexif-dev \ + liborc-0.4-dev \ + && rm -rf /var/lib/apt/lists + +# TODO: Vendored source to remove test/ and doc/ with patches to remove test/ from configure. +# This would also remove the need to install ca-certificates + curl. + +# TODO: libspng build with meson, miniz to replace libpng-dev. +# https://github.com/randy408/libspng/blob/master/docs/build.md#meson +# Then, publish the final image somewhere. + +WORKDIR /build +RUN curl -sL https://github.com/libvips/libvips/releases/download/v8.10.1/vips-8.10.1.tar.gz | \ + tar -xz -f- --strip-components=1 + +# XXX: -static doesn't work here. I'm using staticx to make the final vips binary static. +# Could also try clang. +# TODO: webp support +RUN CFLAGS="-O2 -flto -pipe" CXXFLAGS="-O2 -flto -pipe" \ + ./configure \ + --disable-deprecated \ + --disable-shared \ + --disable-static \ + --disable-dependency-tracking \ + --disable-gtk-doc + +# This is the fastest easiest way I found to compile the +# CLI as fast as possible. You can probably get more optimal, +# but it'd be a lot harder wrestling autotools. +RUN cd libvips \ + && make -j"$(nproc)" + +RUN cd tools \ + && make -j"$(nproc)" vips + +RUN cd tools \ + && staticx vips /bin/vips \ + && strip -s /bin/vips + +FROM scratch +COPY --from=builder /bin/vips /bin/vips +# This is a nice hack to mkdir /tmp in a scratch image. +WORKDIR /tmp/ +ENTRYPOINT ["/bin/vips"] +CMD ["--help"]