Skip to content

Fix Docker build for DSpace-CRIS backend #469

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

Open
wants to merge 14 commits into
base: dspace-cris-2023_02_x
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
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ jobs:
# Get Metadata for docker_build_test step below
- name: Sync metadata (tags, labels) from GitHub to Docker for 'dspace-test' image
id: meta_build_test
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: dspace/dspace
tags: ${{ env.IMAGE_TAGS }}
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ARG JDK_VERSION=11

# Step 1 - Run Maven Build
FROM dspace/dspace-dependencies:dspace-7_x as build
FROM dspace/dspace-dependencies:dspace-7_x AS build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# The dspace-installer directory will be written to /install
Expand All @@ -20,12 +20,15 @@ USER dspace
ADD --chown=dspace . /app/
# Build DSpace (note: this build doesn't include the optional, deprecated "dspace-rest" webapp)
# Copy the dspace-installer directory to /install. Clean up the build to keep the docker image small
RUN mvn --no-transfer-progress package && \
# Maven flags here ensure that we skip building test environment and skip all code verification checks.
# These flags speed up this compilation as much as reasonably possible.
ENV MAVEN_FLAGS="-P-test-environment -Denforcer.skip=true -Dcheckstyle.skip=true -Dlicense.skip=true -Dxml.skip=true"
RUN mvn --no-transfer-progress package ${MAVEN_FLAGS} && \
mv /app/dspace/target/${TARGET_DIR}/* /install && \
mvn clean

# Step 2 - Run Ant Deploy
FROM openjdk:${JDK_VERSION}-slim as ant_build
FROM eclipse-temurin:${JDK_VERSION} AS ant_build
ARG TARGET_DIR=dspace-installer
# COPY the /install directory from 'build' container to /dspace-src in this container
COPY --from=build /install /dspace-src
Expand Down
15 changes: 10 additions & 5 deletions Dockerfile.cli
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ARG JDK_VERSION=11

# Step 1 - Run Maven Build
FROM dspace/dspace-dependencies:dspace-7_x as build
FROM dspace/dspace-dependencies:dspace-7_x AS build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# The dspace-installer directory will be written to /install
Expand All @@ -24,7 +24,7 @@ RUN mvn --no-transfer-progress package && \
mvn clean

# Step 2 - Run Ant Deploy
FROM openjdk:${JDK_VERSION}-slim as ant_build
FROM eclipse-temurin:${JDK_VERSION} AS ant_build
ARG TARGET_DIR=dspace-installer
# COPY the /install directory from 'build' container to /dspace-src in this container
COPY --from=build /install /dspace-src
Expand All @@ -33,9 +33,9 @@ WORKDIR /dspace-src
ENV ANT_VERSION 1.10.13
ENV ANT_HOME /tmp/ant-$ANT_VERSION
ENV PATH $ANT_HOME/bin:$PATH
# Need wget to install ant, and unzip for managing AIPs
# Need wget to install ant
RUN apt-get update \
&& apt-get install -y --no-install-recommends wget unzip \
&& apt-get install -y --no-install-recommends wget \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/*
# Download and install 'ant'
Expand All @@ -45,10 +45,15 @@ RUN mkdir $ANT_HOME && \
RUN ant init_installation update_configs update_code

# Step 3 - Run jdk
FROM openjdk:${JDK_VERSION}
FROM eclipse-temurin:${JDK_VERSION}
# NOTE: DSPACE_INSTALL must align with the "dspace.dir" default configuration.
ENV DSPACE_INSTALL=/dspace
# Copy the /dspace directory from 'ant_build' container to /dspace in this container
COPY --from=ant_build /dspace $DSPACE_INSTALL
# Give java extra memory (1GB)
ENV JAVA_OPTS=-Xmx1000m
# Install unzip for AIPs
RUN apt-get update \
&& apt-get install -y --no-install-recommends unzip \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/*
12 changes: 5 additions & 7 deletions Dockerfile.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
ARG JDK_VERSION=11

# Step 1 - Run Maven Build
FROM maven:3-openjdk-${JDK_VERSION}-slim as build
FROM maven:3-eclipse-temurin-${JDK_VERSION} AS build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# Create the 'dspace' user account & home directory
RUN useradd dspace \
&& mkdir -p /home/dspace \
&& chown -Rv dspace: /home/dspace
RUN chown -Rv dspace: /app
# Need git to support buildnumber-maven-plugin, which lets us know what version of DSpace is being run.
RUN apt-get update \
&& apt-get install -y --no-install-recommends git \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/*

# Switch to dspace user & run below commands as that user
USER dspace
Expand All @@ -28,7 +23,10 @@ USER dspace
ADD --chown=dspace . /app/

# Trigger the installation of all maven dependencies (hide download progress messages)
RUN mvn --no-transfer-progress package
# Maven flags here ensure that we skip final assembly, skip building test environment and skip all code verification checks.
# These flags speed up this installation as much as reasonably possible.
ENV MAVEN_FLAGS="-P-assembly -P-test-environment -Denforcer.skip=true -Dcheckstyle.skip=true -Dlicense.skip=true -Dxml.skip=true"
RUN mvn --no-transfer-progress install ${MAVEN_FLAGS}

# Clear the contents of the /app directory (including all maven builds), so no artifacts remain.
# This ensures when dspace:dspace is built, it will use the Maven local cache (~/.m2) for dependencies
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ARG JDK_VERSION=11

# Step 1 - Run Maven Build
FROM dspace/dspace-dependencies:dspace-7_x as build
FROM dspace/dspace-dependencies:dspace-7_x AS build
ARG TARGET_DIR=dspace-installer
WORKDIR /app
# The dspace-installer directory will be written to /install
Expand All @@ -27,7 +27,7 @@ RUN mvn --no-transfer-progress package -Pdspace-rest && \
mvn clean

# Step 2 - Run Ant Deploy
FROM openjdk:${JDK_VERSION}-slim as ant_build
FROM eclipse-temurin:${JDK_VERSION} AS ant_build
ARG TARGET_DIR=dspace-installer
# COPY the /install directory from 'build' container to /dspace-src in this container
COPY --from=build /install /dspace-src
Expand Down
18 changes: 10 additions & 8 deletions docker-compose-cli.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
version: "3.7"

networks:
# Default to using network named 'dspacenet' from docker-compose.yml.
# Its full name will be prepended with the project name (e.g. "-p d7" means it will be named "d7_dspacenet")
default:
name: ${COMPOSE_PROJECT_NAME}_dspacenet
external: true
services:
dspace-cli:
image: "${DOCKER_OWNER:-dspace}/dspace-cli:${DSPACE_VER:-dspace-7_x}"
image: "${DOCKER_OWNER:-dspace}/dspace-cli:${DSPACE_VER:-dspace-cris-7_x}"
container_name: dspace-cli
build:
context: .
Expand All @@ -24,15 +28,13 @@ services:
# Mount local [src]/dspace/config/ to container. This syncs your local configs with container
# NOTE: Environment variables specified above will OVERRIDE any configs in local.cfg or dspace.cfg
- ./dspace/config:/dspace/config
# Mount local [src]/dspace/etc/ to container. This syncs local etc files with container.
# These etc files are used to initialize DSpace-CRIS layout
- ./dspace/etc:/dspace/etc
entrypoint: /dspace/bin/dspace
command: help
networks:
- dspacenet
tty: true
stdin_open: true

volumes:
assetstore:

networks:
dspacenet:
35 changes: 26 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
networks:
dspacenet:
ipam:
Expand All @@ -20,7 +19,7 @@ services:
# Uncomment to set a non-default value for dspace.server.url or dspace.ui.url
# dspace__P__server__P__url: http://localhost:8080/server
# dspace__P__ui__P__url: http://localhost:4000
dspace__P__name: 'DSpace Started with Docker Compose'
dspace__P__name: 'DSpace-CRIS Started with Docker Compose'
# db.url: Ensure we are using the 'dspacedb' image for our database
db__P__url: 'jdbc:postgresql://dspacedb:5432/dspace'
# solr.server: Ensure we are using the 'dspacesolr' image for Solr
Expand All @@ -29,14 +28,14 @@ services:
# from the host machine. This IP range MUST correspond to the 'dspacenet' subnet defined above.
proxies__P__trusted__P__ipranges: '172.23.0'
LOGGING_CONFIG: /dspace/config/log4j2-container.xml
image: "${DOCKER_OWNER:-dspace}/dspace:${DSPACE_VER:-dspace-7_x-test}"
image: "${DOCKER_OWNER:-dspace}/dspace:${DSPACE_VER:-dspace-cris-7_x-test}"
build:
context: .
dockerfile: Dockerfile.test
depends_on:
- dspacedb
networks:
dspacenet:
- dspacenet
ports:
- published: 8080
target: 8080
Expand All @@ -52,22 +51,30 @@ services:
# Mount local [src]/dspace/config/ to container. This syncs your local configs with container
# NOTE: Environment variables specified above will OVERRIDE any configs in local.cfg or dspace.cfg
- ./dspace/config:/dspace/config
# Mount local [src]/dspace/etc/ to container. This syncs local etc files with container.
# These etc files are used to initialize DSpace-CRIS layout
- ./dspace/etc:/dspace/etc
# Ensure that the database is ready BEFORE starting tomcat
# 1. While a TCP connection to dspacedb port 5432 is not available, continue to sleep
# 2. Then, run database migration to init database tables
# 3. Finally, start Tomcat
# 3. Then, create the default Entity Types defined in cris.cfg
# 4. Then, create custom DSpace relationship types defined in correction & hide-sort configs
# 5. Finally, start Tomcat
entrypoint:
- /bin/bash
- '-c'
- |
while (!</dev/tcp/dspacedb/5432) > /dev/null 2>&1; do sleep 1; done;
/dspace/bin/dspace database migrate
/dspace/bin/dspace dsrun org.dspace.app.util.InitializeEntityTypesOnly -d
/dspace/bin/dspace dsrun org.dspace.app.util.InitializeEntities -f /dspace/config/entities/correction-relationship-types.xml
/dspace/bin/dspace dsrun org.dspace.app.util.InitializeEntities -f /dspace/config/entities/hide-sort-relationship-types.xml
catalina.sh run
# DSpace PostgreSQL database container
dspacedb:
container_name: dspacedb
# Uses a custom Postgres image with pgcrypto installed
image: "${DOCKER_OWNER:-dspace}/dspace-postgres-pgcrypto:${DSPACE_VER:-dspace-7_x}"
image: "${DOCKER_OWNER:-dspace}/dspace-postgres-pgcrypto:${DSPACE_VER:-dspace-cris-7_x}"
build:
# Must build out of subdirectory to have access to install script for pgcrypto
context: ./dspace/src/main/docker/dspace-postgres-pgcrypto/
Expand All @@ -87,10 +94,12 @@ services:
# DSpace Solr container
dspacesolr:
container_name: dspacesolr
image: "${DOCKER_OWNER:-dspace}/dspace-solr:${DSPACE_VER:-dspace-7_x}"
image: "${DOCKER_OWNER:-dspace}/dspace-solr:${DSPACE_VER:-dspace-cris-7_x}"
build:
context: .
dockerfile: ./dspace/src/main/docker/dspace-solr/Dockerfile
context: ./dspace/src/main/docker/dspace-solr/
# Provide path to Solr configs necessary to build Docker image
additional_contexts:
solrconfigs: ./dspace/solr/
args:
SOLR_VERSION: "${SOLR_VER:-8.11}"
networks:
Expand All @@ -113,14 +122,22 @@ services:
- '-c'
- |
init-var-solr
precreate-core audit /opt/solr/server/solr/configsets/audit
cp -r /opt/solr/server/solr/configsets/audit/* audit
precreate-core authority /opt/solr/server/solr/configsets/authority
cp -r /opt/solr/server/solr/configsets/authority/* authority
precreate-core dedup /opt/solr/server/solr/configsets/dedup
cp -r /opt/solr/server/solr/configsets/dedup/* dedup
precreate-core nbevent /opt/solr/server/solr/configsets/nbevent
cp -r /opt/solr/server/solr/configsets/nbevent/* nbevent
precreate-core oai /opt/solr/server/solr/configsets/oai
cp -r /opt/solr/server/solr/configsets/oai/* oai
precreate-core search /opt/solr/server/solr/configsets/search
cp -r /opt/solr/server/solr/configsets/search/* search
precreate-core statistics /opt/solr/server/solr/configsets/statistics
cp -r /opt/solr/server/solr/configsets/statistics/* statistics
precreate-core suggestion /opt/solr/server/solr/configsets/suggestion
cp -r /opt/solr/server/solr/configsets/suggestion/* suggestion
exec solr -f
volumes:
assetstore:
Expand Down
38 changes: 27 additions & 11 deletions dspace/src/main/docker-compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,49 @@ Documentation for all Dockerfiles used by these compose scripts can be found in

Documentation for all Dockerfiles used by these compose scripts can be found in the ["docker" folder README](../docker/README.md)

## To build DSpace-CRIS images using code in your branch
```
docker compose -f docker-compose.yml -f docker-compose-cli.yml build
```

## To refresh / pull DSpace images from Dockerhub
OPTIONALLY, you can build DSpace images using a different JDK_VERSION like this:
```
docker-compose -f docker-compose.yml -f docker-compose-cli.yml pull
docker compose -f docker-compose.yml -f docker-compose-cli.yml build --build-arg JDK_VERSION=17
```
Default is Java 11, but other LTS releases (e.g. 17) are also supported.

## Install/Run DSpace-CRIS 7 REST from your current branch

## To build DSpace images using code in your branch
First, start up the containers
```
docker-compose -f docker-compose.yml -f docker-compose-cli.yml build
docker compose -p dcris7 up -d
```

OPTIONALLY, you can build DSpace images using a different JDK_VERSION like this:
Then, you will need to create an Administrator account to initialize the DSpace-CRIS community/collection structure.
This example creates an Admin "[email protected]" with a password of "dspace":
```
docker-compose -f docker-compose.yml -f docker-compose-cli.yml build --build-arg JDK_VERSION=17
docker compose -p dcris7 -f docker-compose-cli.yml run --rm dspace-cli create-administrator -e [email protected] -f Demo -l Administrator -p dspace -c en
```
Default is Java 11, but other LTS releases (e.g. 17) are also supported.

## Run DSpace 7 REST from your current branch
Next, create the sample Community/Collection structure (using that Admin account)
```
docker compose -p dcris7 -f docker-compose-cli.yml run --rm dspace-cli dsrun org.dspace.administer.StructBuilder -e [email protected] -f /dspace/config/sample-structure.xml -o -
```
docker-compose -p d7 up -d

Finally, initialize the layout using the provided XLS config file
```
docker compose -p dcris7 -f docker-compose-cli.yml run --rm dspace-cli cris-layout-tool -f /dspace/etc/conftool/cris-layout-configuration.xls
```

## Run DSpace-CRIS 7 REST and Angular from your branch

## Run DSpace 7 REST and Angular from your branch
NOTE: If this is your first time running the DSpace-CRIS backend, make sure to follow the "Install/Run" instructions
above *first*.

```
docker-compose -p d7 -f docker-compose.yml -f dspace/src/main/docker-compose/docker-compose-angular.yml up -d
docker compose -p dcris7 -f docker-compose.yml -f dspace/src/main/docker-compose/docker-compose-angular.yml up -d
```
NOTE: This starts the UI in development mode. It will take a few minutes to see the UI as the Angular code needs to be compiled.

## Run DSpace REST and DSpace Angular from local branches

Expand Down
2 changes: 0 additions & 2 deletions dspace/src/main/docker-compose/cli.assetstore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# http://www.dspace.org/license/
#

version: "3.7"

services:
dspace-cli:
environment:
Expand Down
2 changes: 0 additions & 2 deletions dspace/src/main/docker-compose/cli.ingest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# http://www.dspace.org/license/
#

version: "3.7"

services:
dspace-cli:
environment:
Expand Down
25 changes: 4 additions & 21 deletions dspace/src/main/docker-compose/db.entities.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,22 @@
# http://www.dspace.org/license/
#

version: "3.7"

services:
dspacedb:
image: dspace/dspace-postgres-pgcrypto:dspace-7_x-loadsql
image: dspace/dspace-postgres-pgcrypto:dspace-cris-7_x-loadsql
environment:
# This SQL is available from https://github.com/DSpace-Labs/AIP-Files/releases/tag/demo-entities-data
- LOADSQL=https://github.com/DSpace-Labs/AIP-Files/releases/download/demo-entities-data/dspace7-entities-data.sql
dspace:
### OVERRIDE default 'entrypoint' in 'docker-compose.yml ####
# Ensure that the database is ready BEFORE starting tomcat
# 1. While a TCP connection to dspacedb port 5432 is not available, continue to sleep
# 2. Then, run database migration to init database tables
# 3. (Custom for Entities) enable Entity-specific collection submission mappings in item-submission.xml
# This 'sed' command inserts the sample configurations specific to the Entities data set, see:
# https://github.com/DSpace/DSpace/blob/main/dspace/config/item-submission.xml#L36-L49
# 4. Finally, start Tomcat
# 2. Then, run migration latest version of database tables (run with "ignored" in case this SQL data is outdated)
# 3. Finally, start Tomcat
entrypoint:
- /bin/bash
- '-c'
- |
while (!</dev/tcp/dspacedb/5432) > /dev/null 2>&1; do sleep 1; done;
/dspace/bin/dspace database migrate
sed -i '/name-map collection-handle="default".*/a \\n <name-map collection-handle="123456789/3" submission-name="Publication"/> \
<name-map collection-handle="123456789/4" submission-name="Publication"/> \
<name-map collection-handle="123456789/281" submission-name="Publication"/> \
<name-map collection-handle="123456789/5" submission-name="Publication"/> \
<name-map collection-handle="123456789/8" submission-name="OrgUnit"/> \
<name-map collection-handle="123456789/6" submission-name="Person"/> \
<name-map collection-handle="123456789/279" submission-name="Person"/> \
<name-map collection-handle="123456789/7" submission-name="Project"/> \
<name-map collection-handle="123456789/280" submission-name="Project"/> \
<name-map collection-handle="123456789/28" submission-name="Journal"/> \
<name-map collection-handle="123456789/29" submission-name="JournalVolume"/> \
<name-map collection-handle="123456789/30" submission-name="JournalIssue"/>' /dspace/config/item-submission.xml
/dspace/bin/dspace database migrate ignored
catalina.sh run
Loading
Loading