diff --git a/.env b/.env new file mode 100644 index 00000000..e6fa0b62 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +LOCAL_VIVO_HOME=./vivo-home +RESET_HOME=false +RESET_CORE=false +VERBOSE=no diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..d11d273f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Convert to LF line endings on checkout. +*.sh text eol=lf diff --git a/.gitignore b/.gitignore index 425a6cfb..40730697 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ utilities/rdbmigration/.work **/.classpath **/.project **/bin/ + +vivo-home/ diff --git a/Dockerfile b/Dockerfile index d2df2193..ccfe74a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index a77727e9..0deb596c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..e6386a71 --- /dev/null +++ b/docker-compose.yml @@ -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: diff --git a/start.sh b/start.sh new file mode 100644 index 00000000..90e76f60 --- /dev/null +++ b/start.sh @@ -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