Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IIIF-1113] Support using a Java delegate #113

Merged
merged 3 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<!-- Java dependency versions -->
<freelib.utils.version>2.1.0</freelib.utils.version>
<freelib.maven.version>0.1.2</freelib.maven.version>
<maven.jar.version>3.2.0</maven.jar.version>
<jsoup.version>1.13.1</jsoup.version>
<json.version>20180130</json.version>
<scm.plugin.version>1.11.2</scm.plugin.version>
Expand Down Expand Up @@ -116,6 +117,9 @@
<docker.cleanup>remove</docker.cleanup>
<docker.showLogs>true</docker.showLogs>

<!-- We don't need to build the jar outside of the Docker build -->
<jar.phase></jar.phase>

<!-- The image root when running the test instance of Cantaloupe -->
<image.root>src/test/resources/images/</image.root>

Expand Down Expand Up @@ -197,6 +201,26 @@
</testResources>

<plugins>
<!-- We can skip building the Jar except when Docker runs the build -->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.version}</version>
<executions>
<execution>
<id>default-jar</id>
<phase>${jar.phase}</phase>
</execution>
</executions>
</plugin>

<!-- We don't install the Jar but package it up in our Docker image -->
<plugin>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

<plugin>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
Expand Down
22 changes: 15 additions & 7 deletions src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN if [ "${cantaloupe.version}" = "dev" ] ; then \
mvn -q install:install-file -Dfile="/tmp/${JAI_IMAGEIO_JAR}" -DgroupId="javax.media" \
-DartifactId="jai_imageio" -Dversion="$JAI_IMAGEIO_VERSION" -Dpackaging="jar" && \
\
mvn -DskipTests=true -q clean package && \
mvn -DskipTests=true -Djar.phase=package -q clean package && \
mv target/cantaloupe-?.?-SNAPSHOT.zip "/build/Cantaloupe-${cantaloupe.version}.zip" ; \
markmatney marked this conversation as resolved.
Show resolved Hide resolved
else \
curl -o "../Cantaloupe-${cantaloupe.version}.zip" -s -L \
Expand Down Expand Up @@ -77,11 +77,16 @@ RUN if [ ! -z "${kakadu.version}" ]; then \
# The third and final stage of our multi-stage build pulls all the pieces together
FROM ubuntu:${ubuntu.tag}

# The location of the Cantaloupe config file
ENV CONFIG_FILE="/etc/cantaloupe.properties"
ENV HEAP_SIZE="2g"

# We're using a percentage of available RAM
ENV HEAP_PERCENTAGE="80"

# The port we expose the Cantaloupe service on
EXPOSE 8182

# The container's file system location for images
VOLUME /imageroot

# Update packages and install tools
Expand Down Expand Up @@ -132,8 +137,8 @@ ENV LD_LIBRARY_PATH="/usr/lib/jni:${LD_LIBRARY_PATH}"

# Clean up the placeholder files if we built without kakadu; else configure Cantaloupe for Kakadu
RUN if [ -z "${kakadu.version}" ]; then \
rm -rf /build/kakadu/lib/placeholder.so && \
rm -rf /build/kakadu/bin/kdu_placeholder ; \
rm -rf /usr/local/lib/placeholder.so && \
rm -rf /usr/local/bin/kdu_placeholder ; \
else \
echo "CANTALOUPE_MANUAL_PROCESSOR_JP2=KakaduNativeProcessor" >> /etc/environment && \
echo "CANTALOUPE_PROCESSOR_SELECTION_STRATEGY=ManualSelectionStrategy" >> /etc/environment ; \
Expand All @@ -144,10 +149,13 @@ COPY docker-entrypoint.sh /usr/local/bin/
COPY "configs/cantaloupe.properties.tmpl-${cantaloupe.version}" /etc/cantaloupe.properties.tmpl
COPY "configs/cantaloupe.properties.default-${cantaloupe.version}" /etc/cantaloupe.properties.default

# Set up a script to run Cantaloupe
COPY --chown=cantaloupe:users scripts/run_cantaloupe.sh /usr/local/bin/

RUN mkdir -p /var/log/cantaloupe /var/cache/cantaloupe && \
touch "$CONFIG_FILE" && \
chown -R cantaloupe -L /var/log/cantaloupe /var/cache/cantaloupe "$CONFIG_FILE" \
/usr/local/bin/docker-entrypoint.sh /usr/local/cantaloupe
/usr/local/bin/docker-entrypoint.sh /usr/local/cantaloupe/

# Install grok JPEG-2000 library and tools
WORKDIR /tmp
Expand All @@ -166,5 +174,5 @@ ENV CANTALOUPE_LOG_ERROR_ROLLINGFILEAPPENDER_PATHNAME=/var/log/cantaloupe/error.
# Wrap things up with the entrypoint and command that the container runs
USER cantaloupe
WORKDIR /home/cantaloupe
ENTRYPOINT ["docker-entrypoint.sh"]
CMD [ "sh", "-c", "exec java -Dcantaloupe.config=$CONFIG_FILE -Xmx$HEAP_SIZE -jar /usr/local/cantaloupe/cantaloupe-*.*ar" ]
ENTRYPOINT [ "docker-entrypoint.sh" ]
CMD [ "sh", "-c", "exec /usr/local/bin/run_cantaloupe.sh" ]
10 changes: 7 additions & 3 deletions src/main/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ EOT
# Write our merged properties file to /etc directory
$PYTHON -c "$SCRIPT" >> $PROPERTIES

# If we have a DELEGATE_URL, grab it
# If we have a DELEGATE_URL, grab it and copy it to the container for us to use
if [[ -v DELEGATE_URL && ! -z DELEGATE_URL ]]; then
curl "${DELEGATE_URL}" > /usr/local/cantaloupe/delegates.rb
chown cantaloupe /usr/local/cantaloupe/delegates.rb
if [[ "${DELEGATE_URL}" == *rb ]]; then
curl -s "${DELEGATE_URL}" > /usr/local/cantaloupe/delegates.rb
chown cantaloupe /usr/local/cantaloupe/delegates.rb
elif [[ "${DELEGATE_URL}" == *jar ]]; then
curl -s "${DELEGATE_URL}" > /usr/local/cantaloupe/delegate.jar
fi
fi

# If LOGBACK_URL is defined, download and insert logback.xml file into war file
Expand Down
11 changes: 11 additions & 0 deletions src/main/docker/scripts/run_cantaloupe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/bash

if [ -f /usr/local/cantaloupe/delegate.jar ]; then
DELEGATE_JAR=":/usr/local/cantaloupe/delegate.jar"
fi

CANTALOUPE_JAR=$(ls /usr/local/cantaloupe/cantaloupe-*.jar)

# A Cantaloupe startup script that uses ENV properties to configure the application
java -Dcantaloupe.config="${CONFIG_FILE}" -XX:MaxRAMPercentage="${HEAP_PERCENTAGE}" \
-cp "${CANTALOUPE_JAR}${DELEGATE_JAR}" edu.illinois.library.cantaloupe.StandaloneEntry