VIVO-1963: Initial docker compose (#223)

* initial docker compose

* for docker volume use direct tdb filemode

* runtime properties with solr url configured

* move gitattributes to root to ensure scripts stay valid

* fix VIVO dockerfile command permissions

* use public vivoweb/vivo-solr image

* start script improvements

* pass docker compose env to containers

* generate digest.md5 of existing VIVO home

* add initial readme

* reset docker compose env defaults

* minor readme updates
This commit is contained in:
William Welling 2021-02-18 10:07:19 -06:00 committed by GitHub
parent 5f6cabc42a
commit 880ac5b797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 143 additions and 2 deletions

4
.env Normal file
View file

@ -0,0 +1,4 @@
LOCAL_VIVO_HOME=./vivo-home
RESET_HOME=false
RESET_CORE=false
VERBOSE=no

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Convert to LF line endings on checkout.
*.sh text eol=lf

2
.gitignore vendored
View file

@ -20,3 +20,5 @@ utilities/rdbmigration/.work
**/.classpath
**/.project
**/bin/
vivo-home/

View file

@ -1,12 +1,22 @@
FROM tomcat:9-jdk11-openjdk
ENV JAVA_OPTS="${JAVA_OPTS} -Dvivo-dir=/opt/vivo/home/"
ARG SOLR_URL=http://localhost:8983/solr/vivocore
ARG VIVO_DIR=/opt/vivo/home
ARG TDB_FILE_MODE=direct
ENV SOLR_URL=${SOLR_URL}
ENV JAVA_OPTS="${JAVA_OPTS} -Dvivo-dir=$VIVO_DIR -Dtdb:fileMode=$TDB_FILE_MODE"
RUN mkdir /opt/vivo
RUN mkdir /opt/vivo/home
COPY ./installer/webapp/target/vivo.war /usr/local/tomcat/webapps/ROOT.war
COPY ./home/src/main/resources/config/default.applicationSetup.n3 /applicationSetup.n3
COPY ./home/src/main/resources/config/default.runtime.properties /runtime.properties
COPY start.sh /start.sh
EXPOSE 8080
CMD ["catalina.sh", "run"]
CMD ["/bin/bash", "/start.sh"]

View file

@ -21,6 +21,41 @@ https://wiki.duraspace.org/display/VIVO/
Installation instructions for the latest release can be found at this location on the wiki:
https://wiki.duraspace.org/display/VIVODOC110x/Installing+VIVO
### Docker
VIVO docker container is available at [vivoweb/vivo](https://hub.docker.com/repository/docker/vivoweb/vivo) with accompanying [vivoweb/vivo-solr](https://hub.docker.com/repository/docker/vivoweb/vivo-solr). These can be used independently or with docker-compose.
### Docker Compose
Docker Compose environment variables.
.env defaults
```
LOCAL_VIVO_HOME=./vivo-home
RESET_HOME=false
RESET_CORE=false
```
- `LOCAL_VIVO_HOME`: VIVO home directory on your host machine which will mount to volume in docker container.
- `RESET_HOME`: Convinience to reset VIVO home when starting container. **Caution** will delete local configuration, content, and configuration model.
- `RESET_CORE`: Convinience to reset VIVO Solr core when starting container. **Caution** will require complete reindex.
Build and start VIVO.
```
mvn clean install
docker-compose up
```
### Docker Image
To build and run local Docker image.
```
docker build -t vivoweb/vivo:development .
docker run -p 8080:8080 vivoweb/vivo:development
```
## Contact us
There are several ways to contact the VIVO community.
Whatever your interest, we would be pleased to hear from you.

36
docker-compose.yml Normal file
View file

@ -0,0 +1,36 @@
version: '3.2'
services:
solr:
image: vivoweb/vivo-solr:latest
environment:
- RESET_CORE=${RESET_CORE}
- VERBOSE=${VERBOSE}
ports:
- 8983:8983
networks:
- vivo
tomcat:
container_name: vivo
hostname: vivo
build:
context: ./
dockerfile: Dockerfile
args:
- VIVO_DIR=/opt/vivo/home
- TDB_FILE_MODE=direct
- SOLR_URL=http://solr:8983/solr/vivocore
environment:
- RESET_HOME=${RESET_HOME}
- VERBOSE=${VERBOSE}
ports:
- 8080:8080
volumes:
- ${LOCAL_VIVO_HOME}:/opt/vivo/home
networks:
- vivo
networks:
vivo:

52
start.sh Normal file
View file

@ -0,0 +1,52 @@
#!/bin/bash
set -e
# allow easier debugging with `docker run -e VERBOSE=yes`
if [[ "$VERBOSE" = "yes" ]]; then
set -x
fi
# allow easier reset home with `docker run -e RESET_HOME=true`
if [[ "$RESET_HOME" = "true" ]]; then
echo 'Clearing VIVO HOME /opt/vivo/home'
rm -rf /opt/vivo/home/*
fi
# ensure home config directory exists
mkdir -p /opt/vivo/home/config
# generate digest.md5 for existing VIVO home if not already exist
if [ ! -f /opt/vivo/home/digest.md5 ]; then
find /opt/vivo/home -type f | grep -E '^/opt/vivo/home/bin/|^/opt/vivo/home/config/|^/opt/vivo/home/rdf/' | xargs md5sum > /opt/vivo/home/digest.md5
echo "Generated digest.md5 for VIVO home"
cat /opt/vivo/home/digest.md5
fi
# only move runtime.properties first time and if it does not already exist in target home directory
if [ -f /runtime.properties ]; then
# template runtime.properties vitro.local.solr.url value to $SOLR_URL value
echo "Templating runtime.properties vitro.local.solr.url = $SOLR_URL"
sed -i "s,http://localhost:8983/solr/vivocore,$SOLR_URL,g" /runtime.properties
if [ ! -f /opt/vivo/home/config/runtime.properties ]
then
echo "First time: moving /runtime.properties to /opt/vivo/home/config/runtime.properties"
mv -n /runtime.properties /opt/vivo/home/config/runtime.properties
else
echo "Using existing /opt/vivo/home/config/runtime.properties"
fi
fi
# only move applicationSetup.n3 first time and if it does not already exist in target home directory
if [ -f /applicationSetup.n3 ]; then
if [ ! -f /opt/vivo/home/config/applicationSetup.n3 ]
then
echo "First time: moving /applicationSetup.n3 to /opt/vivo/home/config/applicationSetup.n3"
mv -n /applicationSetup.n3 /opt/vivo/home/config/applicationSetup.n3
else
echo "Using existing /opt/vivo/home/config/applicationSetup.n3"
fi
fi
catalina.sh run