From 42fa29357f87acefac0620d0a529631e4cb91a0b Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Thu, 25 Jul 2024 10:23:05 +0100 Subject: [PATCH 1/2] Build OpenJPEG and Cantaloupe from sources --- Dockerfile | 115 +++++++++++------------------------------------------ 1 file changed, 23 insertions(+), 92 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0bacdd3..53e710e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,93 +1,24 @@ -FROM ubuntu:jammy as build - -ENV CANTALOUPE_VERSION=5.0.6 -ENV OPENJPEG_VERSION=2.5.2 -ENV GROK_VERSION=12.0.3 -ARG DEBIAN_FRONTEND=noninteractive - -# Install various dependencies: -# * ca-certificates is needed by wget -# * wget download stuffs in this dockerfile -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - wget \ - unzip - -RUN wget -q https://github.com/cantaloupe-project/cantaloupe/releases/download/v$CANTALOUPE_VERSION/cantaloupe-$CANTALOUPE_VERSION.zip \ - && unzip cantaloupe-$CANTALOUPE_VERSION.zip \ - && wget -q https://github.com/uclouvain/openjpeg/releases/download/v$OPENJPEG_VERSION/openjpeg-v$OPENJPEG_VERSION-linux-x86_64.tar.gz \ - && tar -xzf openjpeg-v$OPENJPEG_VERSION-linux-x86_64.tar.gz \ - && wget -q https://github.com/GrokImageCompression/grok/releases/download/v$GROK_VERSION/grok-ubuntu-latest.zip \ - && unzip grok-ubuntu-latest.zip - -FROM ubuntu:jammy - -ENV CANTALOUPE_VERSION=5.0.6 -ENV OPENJPEG_VERSION=2.5.2 -ENV JAVA_HOME=/opt/jdk -ENV PATH=$PATH:/opt/jdk/bin:/opt/maven/bin -ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib -ENV MAXHEAP=2g -ENV INITHEAP=256m -ARG DEBIAN_FRONTEND=noninteractive - -LABEL maintainer="Donald Gray " -LABEL org.opencontainers.image.source=https://github.com/dlcs/image-server-node-cantaloupe -LABEL org.opencontainers.image.description="Cantaloupe image-server on Ubuntu" - -# Install various dependencies: -# * ffmpeg is needed by FfmpegProcessor -# * libopenjp2-tools is needed by OpenJpegProcessor -# * All the rest is needed by GrokProcessor -RUN apt-get update && apt-get install -y --no-install-recommends \ - ffmpeg \ - libopenjp2-tools \ - liblcms2-dev \ - libpng-dev \ - libzstd-dev \ - libtiff-dev \ - libjpeg-dev \ - zlib1g-dev \ - libwebp-dev \ - libimage-exiftool-perl \ - default-jre-headless \ - awscli \ - && rm -rf /var/lib/apt/lists/* - -# Copy GrokProcessor -COPY --from=build /grok-ubuntu-latest/bin/* /bin -COPY --from=build /grok-ubuntu-latest/lib/* /lib -COPY --from=build /grok-ubuntu-latest/include/grok-12.0/* /usr/lib - -# Copy OpenJPEG -COPY --from=build /openjpeg-v$OPENJPEG_VERSION-linux-x86_64/bin/* /bin -COPY --from=build /openjpeg-v$OPENJPEG_VERSION-linux-x86_64/lib/* /lib -COPY --from=build /openjpeg-v$OPENJPEG_VERSION-linux-x86_64/include/openjpeg-2.5/* /usr/lib/ - -# Copy TurboJpegProcessor dependencies + create symlinks -COPY libjpeg /opt/libjpeg-turbo/lib - -RUN ln -s /opt/libjpeg-turbo/lib/libjpeg.so.62.3.0 /opt/libjpeg-turbo/lib/libjpeg.so.62 -RUN ln -s /opt/libjpeg-turbo/lib/libjpeg.so.62 /opt/libjpeg-turbo/lib/libjpeg.so - -RUN ln -s /opt/libjpeg-turbo/lib/libturbojpeg.so.0.2.0 /opt/libjpeg-turbo/lib/libturbojpeg.so.0 -RUN ln -s /opt/libjpeg-turbo/lib/libturbojpeg.so.0 /opt/libjpeg-turbo/lib/libturbojpeg.so - -# Add non-root user -RUN adduser --system cantaloupeusr - -# Setup Cantaloupe -COPY --from=build /cantaloupe-$CANTALOUPE_VERSION/cantaloupe-$CANTALOUPE_VERSION.jar /cantaloupe/cantaloupe-$CANTALOUPE_VERSION.jar -RUN mkdir -p /var/log/cantaloupe /var/cache/cantaloupe \ - && chown -R cantaloupeusr /cantaloupe /var/log/cantaloupe /var/cache/cantaloupe - -# Copy sample properties file + delegates -COPY cantaloupe.properties.sample /cantaloupe/cantaloupe.properties.sample -COPY delegates.rb /cantaloupe/delegates.rb - -COPY entrypoint/* /opt/app/ -RUN chmod +x --recursive /opt/app/ - +FROM registry.access.redhat.com/ubi8/ubi:latest AS openjpeg-build + +RUN yum module install -y llvm-toolset && yum install -y git cmake +RUN git clone https://github.com/uclouvain/openjpeg/ /work && \ + mkdir /work/build /opt/openjpeg + +RUN cmake -DCMAKE_INSTALL_PREFIX=/opt/openjpeg -DCMAKE_BUILD_TYPE=RelWithDebInfo -B /work/build -S /work && \ + cmake --build /work/build -t install + +FROM registry.access.redhat.com/ubi8/ubi:latest AS cantaloupe-build +RUN yum install -y git java-21-openjdk-devel java-21-openjdk-headless maven +RUN git clone https://github.com/cantaloupe-project/cantaloupe /work +WORKDIR /work +ENV JAVA_HOME=/usr/lib/jvm/jre-21-openjdk +RUN mvn dependency:resolve +RUN mvn clean package -DskipTests + +FROM registry.access.redhat.com/ubi8/openjdk-21-runtime +COPY --from=openjpeg-build /opt/openjpeg /opt/openjpeg +RUN mkdir /opt/cantaloupe +COPY --from=cantaloupe-build /work/target/cantaloupe-*.jar /opt/cantaloupe/cantaloupe.jar +COPY cantaloupe.properties.sample /opt/cantaloupe/cantaloupe.properties.sample EXPOSE 8182 -USER cantaloupeusr -CMD ["sh", "-c", "java -Dcantaloupe.config=/cantaloupe/cantaloupe.properties.sample -Xmx$MAXHEAP -Xms$INITHEAP -jar /cantaloupe/cantaloupe-$CANTALOUPE_VERSION.jar"] \ No newline at end of file +CMD ["java", "-Dcantaloupe.config=/opt/cantaloupe/cantaloupe.properties.sample", "-jar", "/opt/cantaloupe/cantaloupe.jar"] \ No newline at end of file From eebae96c41c81d26361c4fe11e33db405f828786 Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Thu, 25 Jul 2024 10:46:34 +0100 Subject: [PATCH 2/2] Build libjpeg-turbo from sources --- Dockerfile | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 53e710e..335d741 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,42 @@ +FROM registry.access.redhat.com/ubi8/ubi:latest AS jpegturbo-build + +RUN yum module install -y llvm-toolset && yum install -y git cmake java-21-openjdk-devel + +ARG jpegturbo_commitish="main" +RUN git clone -b "${jpegturbo_commitish}" https://github.com/libjpeg-turbo/libjpeg-turbo.git /work && \ + mkdir /work/build /opt/turbojpeg + +RUN cmake -DCMAKE_INSTALL_PREFIX=/opt/turbojpeg -DWITH_JAVA=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo -B /work/build -S /work && \ + cmake --build /work/build -t install + FROM registry.access.redhat.com/ubi8/ubi:latest AS openjpeg-build RUN yum module install -y llvm-toolset && yum install -y git cmake -RUN git clone https://github.com/uclouvain/openjpeg/ /work && \ + +ARG openjpeg_commitish="master" +RUN git clone -b "${openjpeg_commitish}" https://github.com/uclouvain/openjpeg/ /work && \ mkdir /work/build /opt/openjpeg RUN cmake -DCMAKE_INSTALL_PREFIX=/opt/openjpeg -DCMAKE_BUILD_TYPE=RelWithDebInfo -B /work/build -S /work && \ cmake --build /work/build -t install FROM registry.access.redhat.com/ubi8/ubi:latest AS cantaloupe-build + RUN yum install -y git java-21-openjdk-devel java-21-openjdk-headless maven -RUN git clone https://github.com/cantaloupe-project/cantaloupe /work + +ARG cantaloupe_commitish="develop" +RUN git clone -b "${cantaloupe_commitish}" https://github.com/cantaloupe-project/cantaloupe /work + WORKDIR /work ENV JAVA_HOME=/usr/lib/jvm/jre-21-openjdk -RUN mvn dependency:resolve -RUN mvn clean package -DskipTests +RUN --mount=type=cache,target=/root/.m2 mvn dependency:go-offline +RUN --mount=type=cache,target=/root/.m2 mvn package -DskipTests FROM registry.access.redhat.com/ubi8/openjdk-21-runtime COPY --from=openjpeg-build /opt/openjpeg /opt/openjpeg +COPY --from=jpegturbo-build /opt/turbojpeg /opt/turbojpeg RUN mkdir /opt/cantaloupe COPY --from=cantaloupe-build /work/target/cantaloupe-*.jar /opt/cantaloupe/cantaloupe.jar COPY cantaloupe.properties.sample /opt/cantaloupe/cantaloupe.properties.sample EXPOSE 8182 -CMD ["java", "-Dcantaloupe.config=/opt/cantaloupe/cantaloupe.properties.sample", "-jar", "/opt/cantaloupe/cantaloupe.jar"] \ No newline at end of file +CMD [ "java", "-Dcantaloupe.config=/opt/cantaloupe/cantaloupe.properties.sample", "-Djava.library.path=/opt/openjpeg/lib64:/opt/turbojpeg/lib64", "-jar", "/opt/cantaloupe/cantaloupe.jar"] \ No newline at end of file