diff --git a/Dockerfile b/Dockerfile index 8f9ba8d..9cf2b5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,108 +1,109 @@ ################################################################################ # # Copyright (c) 2017-2018 # Data Intensive Applications and Systems Labaratory (DIAS) # Ecole Polytechnique Federale de Lausanne # # All Rights Reserved. # # Permission to use, copy, modify and distribute this software and its # documentation is hereby granted, provided that both the copyright notice # and this permission notice appear in all copies of the software, derivative # works or modified versions, and any portions thereof, and that both notices # appear in supporting documentation. # # This code is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. THE AUTHORS AND ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE # DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM # THE USE OF THIS SOFTWARE. # ################################################################################ FROM openjdk:jre-alpine MAINTAINER Darius Sidlauskas RUN apk update && \ apk add tar bash ENV LANG=C.UTF-8 ENV SOLR_USER="solr" \ SOLR_UID="8983" \ SOLR_GROUP="solr" \ SOLR_GID="8983" \ SOLR_VERSION="8.0.0" \ PATH="/opt/hbp-lucene-solr/bin:/opt/hbp-lucene-solr-docker/scripts:$PATH" RUN addgroup -S -g $SOLR_GID $SOLR_GROUP && \ adduser -S -u $SOLR_UID -G $SOLR_GROUP $SOLR_USER COPY src/hbp-lucene-solr/solr/package/solr-8.0.0-SNAPSHOT.tgz /opt/hbp-lucene-solr.tgz RUN mkdir -p /opt/hbp-lucene-solr && \ tar -C /opt/hbp-lucene-solr --extract --file /opt/hbp-lucene-solr.tgz --strip-components=1 && \ rm /opt/hbp-lucene-solr.tgz* && \ rm -Rf /opt/hbp-lucene-solr/docs/ RUN chown -R $SOLR_USER:$SOLR_GROUP /opt/hbp-lucene-solr COPY scripts /opt/hbp-lucene-solr-docker/scripts RUN chown -R $SOLR_USER:$SOLR_GROUP /opt/hbp-lucene-solr-docker #RUN cd /opt/hbp-lucene-solr && ant ivy-bootstrap && ant compile #RUN cd solr && ant server && ant dist ################################################################################ # FROM openjdk:jre-alpine # Note: All environment variables are resetted by the FROM: ENV SOLR_HOME="/opt/hbp-lucene-solr/server/solr" ARG BUILD_DATE ARG VCS_REF LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.name="lucene-solr" \ org.label-schema.description="Docker image for running hbp-lucene-solr" \ org.label-schema.url="https://bitbucket.org/sakurad/hbp-lucene-solr-docker" \ org.label-schema.vcs-type="git" \ org.label-schema.vcs-ref=$VCS_REF \ org.label-schema.vcs-url="https://bitbucket.org/sakurad/hbp-lucene-solr-docker" \ org.label-schema.vendor="DIAS EPFL" \ org.label-schema.docker.dockerfile="Dockerfile" \ org.label-schema.schema-version="0.8" ################################################################################ WORKDIR /opt/hbp-lucene-solr USER $SOLR_USER EXPOSE 8983 # Both the ENTRYPOINT and CMD instructions support two different forms: the # shell form and the exec form. When using the shell form, the specified binary # is executed with an invocation of the shell using `/bin/sh -c`. # When the exec form of the ENTRYPOINT/CMD instruction is used the command will # be executed without a shell. # # Therefore, it is always recommended to use the *exec* form of the # ENTRYPOINT/CMD instructions which looks like this: # CMD ["executable","param1","param2"] # instead of *shell* form, which looks like this: # CMD executable param1 param2 # # The next CMD alone worked fine for running a single Solr instance within a # docker: -#CMD ["solr", "start", "-p", "8983", "-f", "-s", "server/solr" ] +# CMD ["solr", "start", "-p", "8983", "-f", "-s", "server/solr" ] # # The docker image can be run then using: -# `docker run --rm --name my-hbp-solr -d -p 8983:8983 -t hbp-lucene-solr` -# +# ```sh +# docker run --rm --name my-hbp-solr -p 8983:8983 -it hbp-lucene-solr +# ``` # # However, to have more flexibility and following existing conventions, it was # replaced by the bellow combination of ENTRYPOINT and CMD instructions. # # When both an ENTRYPOINT and CMD are specified, the CMD string(s) will be # appended to the ENTRYPOINT in order to generate the container's command # string. Remember that the CMD value can be easily overridden by supplying one # or more arguments to `docker run` after the name of the image. ENTRYPOINT ["docker-entrypoint.sh"] CMD ["hbp-solr-foreground"] diff --git a/README.md b/README.md index e631497..c41b378 100644 --- a/README.md +++ b/README.md @@ -1,105 +1,109 @@ # Docker container for HBP-Lucene/Solr # Copyright (c) 2017-2018 2017 [DIAS](https://dias.epfl.ch/BrainDB) laboratory --- This project creates a lightweight Docker image of a customized *Lucene/Solr* implementation ([HBP-Lucene/Solr](https://bitbucket.org/sakurad/hbp-lucene-solr)) for running HBP Spatial Search Service (API). --- ## Quick-start ## **0. Prerequisites** First, Java SDK is required for Lucene/Solr compilation: ```sh $ sudo apt-get update $ sudo apt-get install default-jdk # On Ubuntu, this will install OpenJDK 8 (the latest and recommended version) ``` Then you need to set `JAVA_HOME` with the path of your preferred installation and set it in `/etc/environment`: ```sh $ sudo update-alternatives --config java # will list all available Java installations $ sudo emacs /etc/environment # add 2 lines: "JAVA_HOME=/usr/lib/jvm/default-java/jre" and "export JAVA_HOME" $ source /etc/environment ``` Also Ant: ```sh -# sudo apt-get install ant +sudo apt-get install ant ``` **1. Clone this project** ```sh -$ git clone git@bitbucket.org:sakurad/hbp-lucene-solr-docker.git -$ cd hbp-lucene-solr-docker +git clone git@bitbucket.org:sakurad/hbp-lucene-solr-docker.git +cd hbp-lucene-solr-docker ``` **2. Clone the HBP-Lucene/Solr sources and build it** ```sh -$ git clone git@bitbucket.org:sakurad/hbp-lucene-solr.git src/hbp-lucene-solr -$ cd src/hbp-lucene-solr && ant ivy-bootstrap && ant compile && cd solr && ant package && cd ../../../ +git clone git@bitbucket.org:sakurad/hbp-lucene-solr.git src/hbp-lucene-solr +# or using https: +git clone https://sakurad@bitbucket.org/sakurad/hbp-lucene-solr.git src/hbp-lucene-solr +cd src/hbp-lucene-solr && ant ivy-bootstrap && ant compile && cd solr && ant package && cd ../../../ ``` **3. Build the docker image** ```sh -$ docker build -t hpb-lucene-solr \ -# --build-arg JOBS=8 \ +docker build -t hbp-lucene-solr \ --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ --build-arg VCS_REF=`git -C ./src/ rev-parse --short HEAD` \ +# --build-arg JOBS=8 \ . ``` **_Note:_** * If you update the sources, add `--no-cache=true` to the command above to take the new version in consideration. * Option `-t , --tag list`: Name and optionally a tag in the 'name:tag' format * Replace the `8` in `JOBS=8` with the number of CPU threads to reduce the build time on your machine. **4. Use the built image** ```sh -$ docker run --rm --name my-hbp-solr -d -p 8983:8983 hbp-lucene-solr +docker run --rm --name my-hbp-solr -d -p 8983:8983 hbp-lucene-solr ``` ## Using a custom `SOLR_HOME` (outside container) ## --- To use a custom *Solr home* directory directory on the host system (outside the container), we can employ a `SOLR_HOME` environment variable by setting it to the desired location (which is now inside the container in its default location at `/opt/hbp-lucene-solr/server/solr`). We support this in hbp-lucene-solr-docker, in combination with volumes: ```sh docker run -it -v $PWD/mysolrhome:/mysolrhome -e SOLR_HOME=/mysolrhome hbp-lucene-solr ``` This does need a pre-configured directory at that location (`/mysolrhome`). As such, hbp-lucene-solr-docker supports a `INIT_SOLR_HOME` setting, which copies the contents from the default directory in the image to the `SOLR_HOME` -(the newly specified must be empty). -```sh -$ mkdir -p docker-volumes/hbp-solr1 -$ sudo chown 8983:8983 docker-volumes/hbp-solr1 -$ docker run -it -v $PWD/docker-volumes/hbp-solr1:/hbp-solr1 \ - -e SOLR_HOME=/hbp-solr1 -e INIT_SOLR_HOME=yes \ - hbp-lucene-solr -``` - -## Putting it all together ## ---- +(the newly specified must be empty). The following is used to run the Spatial Search API in production mode: ```sh -$ mkdir -p docker-volumes/hbp-solr1 -$ sudo chown 8983:8983 docker-volumes/hbp-solr1 -$ docker run \ +mkdir -p docker-volumes/custom-solr-home-1 +sudo chown 8983:8983 docker-volumes/custom-solr-home-1 +docker run \ --name my-hbp-solr \ -d \ -p 8983:8983 \ -it \ - -v $PWD/docker-volumes/hbp-solr1:/hbp-solr1 \ - -e SOLR_HOME=/hbp-solr1 \ + -v $PWD/docker-volumes/custom-solr-home-1:/opt/custom-solr-home-1 \ + -e SOLR_HOME=/opt/custom-solr-home-1 \ -e INIT_SOLR_HOME=yes \ - -e SOLR_HEAP=12g \ + -e SOLR_HEAP=7g \ hbp-lucene-solr ``` -Note increased memory size (12GB). +Note increased memory size (7GB). + +**Options used:** + +```sh +--name string Assign a name to the container +-d, --detach Run container in background and print container ID +-p, --publish list Publish a container's port(s) to the host +-i, --interactive Keep STDIN open even if not attached +-t, --tty Allocate a pseudo-TTY +-v, --volume list Bind mount a volume +-e, --env list Set environment variables (within running conmtainer) +``` diff --git a/scripts/init-hbp-solr-home b/scripts/init-hbp-solr-home index 7a80259..32044f0 100755 --- a/scripts/init-hbp-solr-home +++ b/scripts/init-hbp-solr-home @@ -1,50 +1,52 @@ #!/bin/bash # # A helper script to initialise a custom SOLR_HOME. # For example: # # mkdir mysolrhome # sudo chown 8983:8983 mysolrhome # docker run -it -v $PWD/mysolrhome:/mysolrhome -e SOLR_HOME=/mysolrhome -e INIT_SOLR_HOME=yes hbp-solr # set -e if [[ "$VERBOSE" = "yes" ]]; then set -x fi # Normally SOLR_HOME is not set, and Solr will use /opt/solr/server/solr/ # If it's not set, then this script has no relevance. if [[ -z $SOLR_HOME ]]; then exit fi # require an explicit opt-in. Without this, you can use the SOLR_HOME and # volumes, and configure it from the command-line or a docker-entrypoint-initdb.d # script if [[ "$INIT_SOLR_HOME" != "yes" ]]; then exit fi # check the directory exists. if [ ! -d "$SOLR_HOME" ]; then echo "SOLR_HOME $SOLR_HOME does not exist" exit 1 fi # check for existing Solr if [ -f "$SOLR_HOME/solr.xml" ]; then exit fi # refuse to use non-empty directories, which are likely a misconfiguration if [ "$(find "$SOLR_HOME" -mindepth 1 ! -name lost+found | wc -l)" != '0' ]; then echo "SOLR_HOME directory $SOLR_HOME is not empty; refusing to create a solr home." exit 1 fi # populate with default solr home contents -echo "copying solr home contents to $SOLR_HOME" -cp -R /opt/hbp-lucene-solr/server/solr/* "$SOLR_HOME" +echo "copying solr home contents to (custom) $SOLR_HOME" +ls / +cp -r /opt/hbp-lucene-solr/server/solr/* "$SOLR_HOME" +echo "DONE: initialized a custom SOLR_HOME directory (at $SOLR_HOME)."