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

FEAT: Slimline and templated Dockerfile #963

Open
wants to merge 3 commits into
base: dev/1.33
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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: 14 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# See https://docs.docker.com/engine/userguide/eng-image/multistage-build/
# First build the app on a maven open jdk 11 container
FROM maven:3-eclipse-temurin-11-focal as dev-builder
ARG JHOVE_VERSION=1.33.0-SNAPSHOT
FROM maven:3-eclipse-temurin-11-alpine AS dev-builder
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION:-1.32.0-RC1}
ENV JHOVE_VERSION=${JHOVE_VERSION}

# Copy the current dev source branch to a local build dir
COPY . /build/jhove/
WORKDIR /build/jhove
RUN apk add --no-cache git
WORKDIR /build

# Clone the repo, checkout the revision and build the application
RUN git clone https://github.com/openpreserve/jhove.git

RUN mvn clean package && java -jar jhove-installer/target/jhove-xplt-installer-${JHOVE_VERSION}.jar docker-install.xml
WORKDIR /build/jhove
RUN git checkout v${JHOVE_VERSION} && mvn clean package && java -jar jhove-installer/target/jhove-xplt-installer-${JHOVE_VERSION}.jar docker-install.xml

# Now build a Java JRE for the Alpine application image
# https://github.com/docker-library/docs/blob/master/eclipse-temurin/README.md#creating-a-jre-using-jlink
FROM eclipse-temurin:11 as jre-builder
FROM eclipse-temurin:11-jdk-alpine AS jre-builder

# Create a custom Java runtime
RUN "$JAVA_HOME/bin/jlink" \
Expand All @@ -24,14 +28,14 @@ RUN "$JAVA_HOME/bin/jlink" \
--output /javaruntime

# Now the final application image
FROM debian:bullseye-slim
FROM alpine:3

# Set for additional arguments passed to the java run command, no default
ARG JAVA_OPTS
ENV JAVA_OPTS=$JAVA_OPTS
# Specify the veraPDF REST version if you want to (to be used in build automation)
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION:-1.32.0-RC1}
ENV JHOVE_VERSION=${JHOVE_VERSION}

# Copy the JRE from the previous stage
ENV JAVA_HOME=/opt/java/openjdk
Expand All @@ -40,7 +44,7 @@ COPY --from=jre-builder /javaruntime $JAVA_HOME

# Since this is a running network service we'll create an unprivileged account
# which will be used to perform the rest of the work and run the actual service:
RUN useradd --system --user-group --home-dir=/opt/jhove jhove
RUN addgroup -S jhove && adduser -S -G jhove -h /opt/jhove jhove
RUN mkdir --parents /var/opt/jhove/logs && chown -R jhove:jhove /var/opt/jhove

USER jhove
Expand Down
53 changes: 53 additions & 0 deletions Dockerfile_dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# See https://docs.docker.com/engine/userguide/eng-image/multistage-build/
# First build the app on a maven open jdk 11 container
ARG JHOVE_VERSION=1.33.0-SNAPSHOT
FROM maven:3-eclipse-temurin-11-alpine AS dev-builder
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION}

# Copy the current dev source branch to a local build dir
COPY . /build/jhove/
WORKDIR /build/jhove

RUN mvn clean package && java -jar jhove-installer/target/jhove-xplt-installer-${JHOVE_VERSION}.jar docker-install.xml

# Now build a Java JRE for the Alpine application image
# https://github.com/docker-library/docs/blob/master/eclipse-temurin/README.md#creating-a-jre-using-jlink
FROM eclipse-temurin:11-jdk-alpine AS jre-builder

# Create a custom Java runtime
RUN "$JAVA_HOME/bin/jlink" \
--add-modules java.base,java.logging,java.xml,jdk.crypto.ec \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime

# Now the final application image
FROM alpine:3

# Set for additional arguments passed to the java run command, no default
ARG JAVA_OPTS
ENV JAVA_OPTS=$JAVA_OPTS
# Specify the veraPDF REST version if you want to (to be used in build automation)
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION}

# Copy the JRE from the previous stage
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=jre-builder /javaruntime $JAVA_HOME

# Since this is a running network service we'll create an unprivileged account
# which will be used to perform the rest of the work and run the actual service:
RUN addgroup -S jhove && adduser -S -G jhove -h /opt/jhove jhove
RUN mkdir --parents /var/opt/jhove/logs && chown -R jhove:jhove /var/opt/jhove

USER jhove

WORKDIR /opt/jhove
# Copy the application from the previous stage
COPY --from=dev-builder /opt/jhove/ /opt/jhove/

ENTRYPOINT ["/opt/jhove/jhove"]
55 changes: 55 additions & 0 deletions Dockerfile_installer
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# See https://docs.docker.com/engine/userguide/eng-image/multistage-build/
# First build the app on a maven open jdk 11 container
ARG JHOVE_VERSION=1.32
FROM eclipse-temurin:11-jdk-alpine AS app-installer
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION}

WORKDIR /tmp
COPY docker-install.xml .
RUN wget -O /tmp/jhove-installer.jar https://software.openpreservation.org/releases/jhove/jhove-${JHOVE_VERSION}.jar
RUN java -jar jhove-installer.jar docker-install.xml

# Now build a Java JRE for the Alpine application image
# https://github.com/docker-library/docs/blob/master/eclipse-temurin/README.md#creating-a-jre-using-jlink
FROM eclipse-temurin:11-jdk-alpine AS jre-builder

# Create a custom Java runtime
RUN "$JAVA_HOME/bin/jlink" \
--add-modules java.base,java.logging,java.xml,jdk.crypto.ec \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime

# Now the final application image
FROM alpine:3

# Set for additional arguments passed to the java run command, no default
ARG JAVA_OPTS
ENV JAVA_OPTS=$JAVA_OPTS
# Specify the veraPDF REST version if you want to (to be used in build automation)
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION}

# Copy the JRE from the previous stage
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=jre-builder /javaruntime $JAVA_HOME

# Since this is a running network service we'll create an unprivileged account
# which will be used to perform the rest of the work and run the actual service:
RUN addgroup -S jhove && adduser -S -G jhove -h /opt/jhove jhove
RUN mkdir --parents /var/opt/jhove/logs && chown -R jhove:jhove /var/opt/jhove

USER jhove
WORKDIR /opt/jhove

# Copy the application from the previous stage
COPY --from=app-installer /opt/jhove/ /opt/jhove/

WORKDIR /data
VOLUME [ "/data" ]

ENTRYPOINT ["/opt/jhove/jhove"]
51 changes: 38 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,36 @@
</goals>
</execution>
<execution>
<id>generate-code-coverage-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<id>generate-code-coverage-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}</outputDirectory>
<resources>
<resource>
<directory>templates/docker</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Expand All @@ -233,6 +258,7 @@

<dependencies>
</dependencies>

<profiles>
<profile>
<id>jdk9</id>
Expand Down Expand Up @@ -273,13 +299,13 @@
</build>
<dependencies>

<!-- https://mvnrepository.com/artifact/org.sonarsource.java/sonar-jacoco-listeners -->
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>5.14.0.18788</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.sonarsource.java/sonar-jacoco-listeners -->
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>5.14.0.18788</version>
<scope>test</scope>
</dependency>

</dependencies>
</profile>
Expand Down Expand Up @@ -405,7 +431,6 @@
</repository>
</distributionManagement>
</profile>

</profiles>

</project>
56 changes: 56 additions & 0 deletions templates/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# See https://docs.docker.com/engine/userguide/eng-image/multistage-build/
# First build the app on a maven open jdk 11 container
ARG JHOVE_VERSION=${project.version}
FROM maven:3-eclipse-temurin-11-alpine AS dev-builder
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION}

RUN apk add --no-cache git
WORKDIR /build

# Clone the repo, checkout the revision and build the application
RUN git clone https://github.com/openpreserve/jhove.git

WORKDIR /build/jhove
RUN git checkout v${JHOVE_VERSION} && mvn clean package && java -jar jhove-installer/target/jhove-xplt-installer-${JHOVE_VERSION}.jar docker-install.xml

# Now build a Java JRE for the Alpine application image
# https://github.com/docker-library/docs/blob/master/eclipse-temurin/README.md#creating-a-jre-using-jlink
FROM eclipse-temurin:11-jdk-alpine AS jre-builder

# Create a custom Java runtime
RUN "$JAVA_HOME/bin/jlink" \
--add-modules java.base,java.logging,java.xml,jdk.crypto.ec \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime

# Now the final application image
FROM alpine:3

# Set for additional arguments passed to the java run command, no default
ARG JAVA_OPTS
ENV JAVA_OPTS=$JAVA_OPTS
# Specify the veraPDF REST version if you want to (to be used in build automation)
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION}

# Copy the JRE from the previous stage
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=jre-builder /javaruntime $JAVA_HOME

# Since this is a running network service we'll create an unprivileged account
# which will be used to perform the rest of the work and run the actual service:
RUN addgroup -S jhove && adduser -S -G jhove -h /opt/jhove jhove
RUN mkdir --parents /var/opt/jhove/logs && chown -R jhove:jhove /var/opt/jhove

USER jhove

WORKDIR /opt/jhove
# Copy the application from the previous stage
COPY --from=dev-builder /opt/jhove/ /opt/jhove/

ENTRYPOINT ["/opt/jhove/jhove"]
53 changes: 53 additions & 0 deletions templates/docker/Dockerfile_dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# See https://docs.docker.com/engine/userguide/eng-image/multistage-build/
# First build the app on a maven open jdk 11 container
ARG JHOVE_VERSION=${project.version}
FROM maven:3-eclipse-temurin-11-alpine AS dev-builder
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION}

# Copy the current dev source branch to a local build dir
COPY . /build/jhove/
WORKDIR /build/jhove

RUN mvn clean package && java -jar jhove-installer/target/jhove-xplt-installer-${JHOVE_VERSION}.jar docker-install.xml

# Now build a Java JRE for the Alpine application image
# https://github.com/docker-library/docs/blob/master/eclipse-temurin/README.md#creating-a-jre-using-jlink
FROM eclipse-temurin:11-jdk-alpine AS jre-builder

# Create a custom Java runtime
RUN "$JAVA_HOME/bin/jlink" \
--add-modules java.base,java.logging,java.xml,jdk.crypto.ec \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime

# Now the final application image
FROM alpine:3

# Set for additional arguments passed to the java run command, no default
ARG JAVA_OPTS
ENV JAVA_OPTS=$JAVA_OPTS
# Specify the veraPDF REST version if you want to (to be used in build automation)
ARG JHOVE_VERSION
ENV JHOVE_VERSION=${JHOVE_VERSION}

# Copy the JRE from the previous stage
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=jre-builder /javaruntime $JAVA_HOME

# Since this is a running network service we'll create an unprivileged account
# which will be used to perform the rest of the work and run the actual service:
RUN addgroup -S jhove && adduser -S -G jhove -h /opt/jhove jhove
RUN mkdir --parents /var/opt/jhove/logs && chown -R jhove:jhove /var/opt/jhove

USER jhove

WORKDIR /opt/jhove
# Copy the application from the previous stage
COPY --from=dev-builder /opt/jhove/ /opt/jhove/

ENTRYPOINT ["/opt/jhove/jhove"]
Loading