Skip to content

Commit

Permalink
Merge pull request #174 from veraPDF/feat/docker-improvements
Browse files Browse the repository at this point in the history
FEAT: Slimmer Docker image
  • Loading branch information
carlwilson authored Sep 5, 2024
2 parents 0541182 + aa6bd37 commit 351251a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
24 changes: 10 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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.8.6-openjdk-11 as app-builder
FROM maven:3-eclipse-temurin-11-alpine AS app-builder
RUN apk add --no-cache git
WORKDIR /build

# A specifc git branch, tag or commit to build from, defaults to master (release build)
Expand All @@ -13,13 +14,9 @@ RUN git clone https://github.com/veraPDF/veraPDF-rest.git
WORKDIR /build/veraPDF-rest
RUN git checkout ${GH_CHECKOUT} && mvn clean package

# Install dumb-init for process safety
# https://github.com/Yelp/dumb-init
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64

# 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 @@ -31,16 +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), default is 1.27.1
ARG VERAPDF_REST_VERSION
ENV VERAPDF_REST_VERSION=${VERAPDF_REST_VERSION:-1.27.1}

COPY --from=app-builder /usr/local/bin/dumb-init /usr/local/bin/dumb-init
# Set up dumb-init for process safety: https://github.com/Yelp/dumb-init
ADD --link https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

# Copy the JRE from the previous stage
Expand All @@ -50,19 +45,20 @@ 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/verapdf-rest verapdf-rest
RUN addgroup -S verapdf-rest && adduser --system -D --home /opt/verapdf-rest -G verapdf-rest verapdf-rest
RUN mkdir --parents /var/opt/verapdf-rest/logs && chown -R verapdf-rest:verapdf-rest /var/opt/verapdf-rest

USER verapdf-rest
WORKDIR /opt/verapdf-rest

# Copy the application from the previous stage
COPY --from=app-builder /build/veraPDF-rest/target/verapdf-rest-${VERAPDF_REST_VERSION}.jar /opt/verapdf-rest/
COPY --from=app-builder /build/veraPDF-rest/target/verapdf-rest-${VERAPDF_REST_VERSION}.jar /opt/verapdf-rest/verapdf-rest.jar
# Copy the default configuration file
COPY --from=app-builder /build/veraPDF-rest/server.yml /var/opt/verapdf-rest/config/
COPY --from=app-builder /build/veraPDF-rest/config /opt/verapdf-rest/config/

VOLUME /var/opt/verapdf-rest
EXPOSE 8080

ENTRYPOINT dumb-init java $JAVA_OPTS -Djava.awt.headless=true -jar /opt/verapdf-rest/verapdf-rest-${VERAPDF_REST_VERSION}.jar server /var/opt/verapdf-rest/config/server.yml
ENTRYPOINT [ "dumb-init", "--" ]
CMD ["java", "-Djava.awt.headless=true", "-jar", "/opt/verapdf-rest/verapdf-rest.jar", "server", "/var/opt/verapdf-rest/config/server.yml"]
25 changes: 10 additions & 15 deletions Dockerfile_dev
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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.8.6-openjdk-11 as dev-builder
FROM maven:3-eclipse-temurin-11-alpine AS dev-builder
WORKDIR /build

# Copy the current dev source branch to a local build dir
Expand All @@ -10,13 +10,9 @@ COPY pom.xml /build/veraPDF-rest/
WORKDIR /build/veraPDF-rest
RUN mvn clean package

# Install dumb-init for process safety
# https://github.com/Yelp/dumb-init
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64

# 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 @@ -28,16 +24,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), default is 1.27.1
ARG VERAPDF_REST_VERSION
ENV VERAPDF_REST_VERSION=${VERAPDF_REST_VERSION:-1.27.1}

COPY --from=dev-builder /usr/local/bin/dumb-init /usr/local/bin/dumb-init
# Set up dumb-init for process safety: https://github.com/Yelp/dumb-init
ADD --link https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

# Copy the JRE from the previous stage
Expand All @@ -47,19 +41,20 @@ 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/verapdf-rest verapdf-rest
RUN addgroup -S verapdf-rest && adduser --system -D --home /opt/verapdf-rest -G verapdf-rest verapdf-rest
RUN mkdir --parents /var/opt/verapdf-rest/logs && chown -R verapdf-rest:verapdf-rest /var/opt/verapdf-rest

USER verapdf-rest

WORKDIR /opt/verapdf-rest
# Copy the application from the previous stage
COPY --from=dev-builder /build/veraPDF-rest/target/verapdf-rest-${VERAPDF_REST_VERSION}.jar /opt/verapdf-rest/
COPY --from=dev-builder /build/veraPDF-rest/target/verapdf-rest-${VERAPDF_REST_VERSION}.jar /opt/verapdf-rest/verapdf-rest.jar

# Copy the default configuration file
COPY server.yml /var/opt/verapdf-rest/config/
COPY config /opt/verapdf-rest/config/

VOLUME /var/opt/verapdf-rest
EXPOSE 8080

ENTRYPOINT dumb-init java $JAVA_OPTS -Djava.awt.headless=true -jar /opt/verapdf-rest/verapdf-rest-${VERAPDF_REST_VERSION}.jar server /var/opt/verapdf-rest/config/server.yml
ENTRYPOINT [ "dumb-init", "--" ]
CMD ["java", "-Djava.awt.headless=true", "-jar", "/opt/verapdf-rest/verapdf-rest.jar", "server", "/var/opt/verapdf-rest/config/server.yml"]

0 comments on commit 351251a

Please sign in to comment.