Optimize docker builds

This commit is contained in:
Terry Brady
2018-12-20 21:16:05 -08:00
parent 9c16711dbe
commit a13f18f093
3 changed files with 47 additions and 16 deletions

25
Dockerfile.dependencies Normal file
View File

@@ -0,0 +1,25 @@
# This image will be published as dspace/dspace-dependencies
# The purpose of this image is to make the build for dspace/dspace run faster
# Step 1 - Run Maven Build
FROM maven as build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# The Mirage2 build cannot run as root. Setting the user to dspace.
RUN useradd dspace \
&& mkdir /home/dspace \
&& chown -Rv dspace: /home/dspace
USER dspace
# Copy the DSpace source code into the workdir (excluding .dockerignore contents)
ADD --chown=dspace . /app/
COPY dspace/src/main/docker/local.cfg /app/local.cfg
# Trigger the installation of all maven dependencies including the Mirage2 dependencies
# Clean up the built artifacts in the same step to keep the docker image small
RUN mvn package -Dmirage2.on=true && mvn clean
# clear the contents of the /app directory so no artifacts are left when dspace:dspace is built
USER root
RUN rm -rf /app/*

View File

@@ -9,26 +9,30 @@
# - default tag for branch: dspace/dspace: dspace/dspace:dspace-6_x-jdk8
# Step 1 - Run Maven Build
FROM maven as build
FROM dspace/dspace-dependencies:dspace-6_x as build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# The Mirage2 build cannot run as root. Setting the user to dspace.
RUN useradd dspace \
&& mkdir /home/dspace \
&& chown -Rv dspace: /home/dspace
# The dspace-install directory will be written to /install
RUN mkdir /install \
&& chown -Rv dspace: /install
USER dspace
# Copy the DSpace source code into the workdir (excluding .dockerignore contents)
ADD --chown=dspace . /app/
COPY dspace/src/main/docker/local.cfg /app/local.cfg
RUN mvn package -Dmirage2.on=true
# Build DSpace. Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
RUN mvn package -Dmirage2.on=true && \
mv /app/dspace/target/${TARGET_DIR}/* /install && \
mvn clean
# Step 2 - Run Ant Deploy
FROM tomcat:8-jre8 as ant_build
ARG TARGET_DIR=dspace-installer
COPY --from=build /app /dspace-src
WORKDIR /dspace-src/dspace/target/${TARGET_DIR}
COPY --from=build /install /dspace-src
WORKDIR /dspace-src
# Create the initial install deployment using ANT
ENV ANT_VERSION 1.10.5

View File

@@ -9,13 +9,13 @@
# - default tag for branch: dspace/dspace: dspace/dspace:dspace-6_x-jdk8
# Step 1 - Run Maven Build
FROM maven as build
FROM dspace/dspace-dependencies:dspace-6_x as build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# The Mirage2 build cannot run as root. Setting the user to dspace.
RUN useradd dspace \
&& mkdir /home/dspace \
&& chown -Rv dspace: /home/dspace
RUN mkdir /install \
&& chown -Rv dspace: /install
USER dspace
# Copy the DSpace source code into the workdir (excluding .dockerignore contents)
@@ -26,13 +26,15 @@ COPY dspace/src/main/docker/local.cfg /app/local.cfg
COPY dspace/src/main/docker/test/solr_web.xml /app/dspace-solr/src/main/webapp/WEB-INF/web.xml
COPY dspace/src/main/docker/test/rest_web.xml /app/dspace-rest/src/main/webapp/WEB-INF/web.xml
RUN mvn package -Dmirage2.on=true
RUN mvn package -Dmirage2.on=true && \
mv /app/dspace/target/${TARGET_DIR}/* /install && \
mvn clean
# Step 2 - Run Ant Deploy
FROM tomcat:8-jre8 as ant_build
ARG TARGET_DIR=dspace-installer
COPY --from=build /app /dspace-src
WORKDIR /dspace-src/dspace/target/${TARGET_DIR}
COPY --from=build /install /dspace-src
WORKDIR /dspace-src
# Create the initial install deployment using ANT
ENV ANT_VERSION 1.10.5