|
| 1 | +# See https://docs.docker.com/engine/userguide/eng-image/multistage-build/ |
| 2 | +# First build the app on a maven open jdk 11 container |
| 3 | +ARG JHOVE_VERSION=1.32 |
| 4 | +FROM eclipse-temurin:11-jdk-alpine AS app-installer |
| 5 | +ARG JHOVE_VERSION |
| 6 | +ENV JHOVE_VERSION=${JHOVE_VERSION} |
| 7 | + |
| 8 | +WORKDIR /tmp |
| 9 | +COPY docker-install.xml . |
| 10 | +RUN wget -O /tmp/jhove-installer.jar https://software.openpreservation.org/releases/jhove/jhove-${JHOVE_VERSION}.jar |
| 11 | +RUN java -jar jhove-installer.jar docker-install.xml |
| 12 | + |
| 13 | +# Now build a Java JRE for the Alpine application image |
| 14 | +# https://github.com/docker-library/docs/blob/master/eclipse-temurin/README.md#creating-a-jre-using-jlink |
| 15 | +FROM eclipse-temurin:11-jdk-alpine AS jre-builder |
| 16 | + |
| 17 | +# Create a custom Java runtime |
| 18 | +RUN "$JAVA_HOME/bin/jlink" \ |
| 19 | + --add-modules java.base,java.logging,java.xml,jdk.crypto.ec \ |
| 20 | + --strip-debug \ |
| 21 | + --no-man-pages \ |
| 22 | + --no-header-files \ |
| 23 | + --compress=2 \ |
| 24 | + --output /javaruntime |
| 25 | + |
| 26 | +# Now the final application image |
| 27 | +FROM alpine:3 |
| 28 | + |
| 29 | +# Set for additional arguments passed to the java run command, no default |
| 30 | +ARG JAVA_OPTS |
| 31 | +ENV JAVA_OPTS=$JAVA_OPTS |
| 32 | +# Specify the veraPDF REST version if you want to (to be used in build automation) |
| 33 | +ARG JHOVE_VERSION |
| 34 | +ENV JHOVE_VERSION=${JHOVE_VERSION} |
| 35 | + |
| 36 | +# Copy the JRE from the previous stage |
| 37 | +ENV JAVA_HOME=/opt/java/openjdk |
| 38 | +ENV PATH "${JAVA_HOME}/bin:${PATH}" |
| 39 | +COPY --from=jre-builder /javaruntime $JAVA_HOME |
| 40 | + |
| 41 | +# Since this is a running network service we'll create an unprivileged account |
| 42 | +# which will be used to perform the rest of the work and run the actual service: |
| 43 | +RUN addgroup -S jhove && adduser -S -G jhove -h /opt/jhove jhove |
| 44 | +RUN mkdir --parents /var/opt/jhove/logs && chown -R jhove:jhove /var/opt/jhove |
| 45 | + |
| 46 | +USER jhove |
| 47 | + |
| 48 | +WORKDIR /opt/jhove |
| 49 | +# Copy the application from the previous stage |
| 50 | +COPY --from=app-installer /opt/jhove/ /opt/jhove/ |
| 51 | + |
| 52 | +ENTRYPOINT ["/opt/jhove/jhove"] |
0 commit comments