From a272e318e6675b007880e314195908ce9e8279cf Mon Sep 17 00:00:00 2001 From: Jan Niestadt Date: Wed, 24 May 2023 12:50:24 +0200 Subject: [PATCH] Combined frontend + blacklab-proxy Docker image (#437) Docker image that adds frontend to BLS's. --- .dockerignore | 30 +++++++++++++++++++ README.md | 22 +++++++++++--- docker-compose.override.yml | 14 +++++++++ docker-compose.yml | 29 ++++++++++-------- docker/config/corpus-frontend.properties | 6 ++-- .../{Dockerfile => frontend-bls.dockerfile} | 8 +++-- docker/frontend-proxy.dockerfile | 28 +++++++++++++++++ 7 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 .dockerignore create mode 100644 docker-compose.override.yml rename docker/{Dockerfile => frontend-bls.dockerfile} (73%) create mode 100644 docker/frontend-proxy.dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..ae8dbd38 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +# Ignore these when building Docker image +**/.env +**/target + +**/.settings +**/.idea +**/*.iml +**/.vscode +**/doc +/*.md +**/README.md +**/.project +**/.classpath +**/.factorypath +**/.apt_generated/ +**/.apt_generated_tests/ + +.git + +# vi temporary files +**/*.swp + +# log files, such as JVM crash files +**/*.log + +# Ignore docker files, we don't need these inside the container. +**/Dockerfile +**/*.dockerfile +**/.dockerignore +**/docker-compose*.yml diff --git a/README.md b/README.md index 1bbed52a..516bea23 100644 --- a/README.md +++ b/README.md @@ -71,13 +71,27 @@ For further development and debugging help, see the [Development section](#Devel ## Using Docker -First, use docker-compose to create a blacklab-server. Then, to create this frontend run: +Make sure you [enable BuildKit](https://docs.docker.com/build/buildkit/#getting-started) +(e.g. `export DOCKER_BUILDKIT=1`) before building the image. +To create a container with BlackLab Frontend and Server, run: + +```bash +docker-compose up --build ``` -DOCKER_BUILDKIT=1 docker-compose build -docker-compose up + +The config file `./docker/config/corpus-frontend.properties` will be mounted inside the container. +(if you need to change some settings, you can set the `CONFIG_PATH` environment variable to read +`corpus-frontend.properties` from a different directory). + +If you have an indexed BlackLab corpus that you want to access, you can set `CORPUS_DIR` to +this directory and `CORPUS_NAME` to the name this corpus should have, e.g.: + +```bash +CORPUS_DIR="/tmp/mycorpus" CORPUS_NAME="my-awesome-corpus" docker-compose up --build ``` -The config file `./docker/config/corpus-frontend.properties` is mounted inside the container. See next section for the configuration details. + +See next section for how to configure BlackLab Frontend. Configuration ==================== diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 00000000..5693b10d --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,14 @@ +# Development overrides for BLS+frontend Compose +version: '3.9' + +services: + + frontend: + # Bind mount properties file for quick updates during development + volumes: + - ./docker/config/corpus-frontend.properties:/etc/blacklab/corpus-frontend.properties + + frontend-proxy: + # Bind mount properties file for quick updates during development + volumes: + - ./docker/config/corpus-frontend.properties:/etc/blacklab/corpus-frontend.properties diff --git a/docker-compose.yml b/docker-compose.yml index 39f4dcb4..8440d2be 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,21 +1,24 @@ -# use this docker-compose file to connect corpus-frontend to an existing blacklab-server -# assume the blacklab-server was created using docker-compose.yml from the blacklab repo with project name 'blacklab' -# it will have created a network named blacklab_default +# Run a container with both BlackLab Frontend and Server version: '3.9' services: frontend: - image: instituutnederlandsetaal/blacklab-corpus-frontend:${IMAGE_VERSION} + image: instituutnederlandsetaal/blacklab-frontend:${IMAGE_VERSION} build: - context: . - dockerfile: docker/Dockerfile - volumes: - - ./docker/config/corpus-frontend.properties:/etc/blacklab/corpus-frontend.properties + context: . + dockerfile: docker/frontend-bls.dockerfile ports: - - "8081:8080" # 8080 will be used by blacklab-server + - "8080:8080" # frontend and BLS will both be available on 8080 + volumes: + # Default values have no effect, but user can override CORPUS_DIR/_NAME to bind mount corpus + - ${CORPUS_DIR:-./README.md}:/data/index/${CORPUS_NAME:-README.md} -networks: - default: - external: - name: blacklab_default # network defined in blacklab-server's docker-compose.yml + frontend-proxy: + profiles: [ "proxy" ] # don't start this by default + image: instituutnederlandsetaal/blacklab-frontend-proxy:${IMAGE_VERSION} + build: + context: . + dockerfile: docker/frontend-proxy.dockerfile + ports: + - "8080:8080" # frontend and BLS will both be available on 8080 diff --git a/docker/config/corpus-frontend.properties b/docker/config/corpus-frontend.properties index b8ec97d5..0a60a113 100644 --- a/docker/config/corpus-frontend.properties +++ b/docker/config/corpus-frontend.properties @@ -1,15 +1,15 @@ # The url under which the back-end can reach blacklab-server. # Separate from the front-end to allow connections for proxy situations # where the paths or ports may differ internally and externally. -blsUrl=http://server:8080/blacklab-server/ +blsUrl=http://127.0.0.1:8080/blacklab-server/ # The url under which the front-end can reach blacklab-server. -blsUrlExternal=http://localhost:8080/blacklab-server/ +blsUrlExternal=/blacklab-server/ # Optional directory where you can place files to further configure and customize # the interface on a per-corpus basis. # Files should be placed in a directory with the name of your corpus, e.g. files -# for a corpus 'MyCorpus' should be placed under 'corporaInterfaceDataDir/MyCorpus/'. +# for a corpus 'MyCorpus' should be placed under '/MyCorpus/'. corporaInterfaceDataDir=/etc/blacklab/projectconfigs/ # For unconfigured corpora, the directory where defaults may be found (optional). diff --git a/docker/Dockerfile b/docker/frontend-bls.dockerfile similarity index 73% rename from docker/Dockerfile rename to docker/frontend-bls.dockerfile index 64d1f425..4f3cf055 100644 --- a/docker/Dockerfile +++ b/docker/frontend-bls.dockerfile @@ -14,11 +14,15 @@ RUN --mount=type=cache,target=/root/.m2 mvn --no-transfer-progress package # Tomcat container with the WAR file #-------------------------------------- -FROM tomcat:9 +FROM instituutnederlandsetaal/blacklab:latest + +# Where corpus-frontend.properties can be found. Can be overridden. ARG CONFIG_ROOT=docker/config + +# What the name of the Tomcat app (and therefore the URL should be). Can be overridden. ARG TOMCAT_APP_NAME=corpus-frontend -COPY docker/config/corpus-frontend.properties /etc/blacklab/ +COPY ${CONFIG_ROOT}/corpus-frontend.properties /etc/blacklab/ # Copy the WAR file COPY --from=builder /app/target/corpus-frontend-*.war /usr/local/tomcat/webapps/${TOMCAT_APP_NAME}.war \ No newline at end of file diff --git a/docker/frontend-proxy.dockerfile b/docker/frontend-proxy.dockerfile new file mode 100644 index 00000000..3cd9c5ba --- /dev/null +++ b/docker/frontend-proxy.dockerfile @@ -0,0 +1,28 @@ +# Stage "builder": build the WAR file +#-------------------------------------- +FROM maven:3.6-jdk-11 AS builder + +# Copy source +WORKDIR /app +COPY . . + +# Build the WAR. +# NOTE: make sure BuildKit is enabled (see https://docs.docker.com/develop/develop-images/build_enhancements/) +# to be able to cache Maven libs so they aren't re-downloaded every time you build the image +RUN --mount=type=cache,target=/root/.m2 mvn --no-transfer-progress package + + +# Tomcat container with the WAR file +#-------------------------------------- +FROM instituutnederlandsetaal/blacklab-proxy:latest + +# Where corpus-frontend.properties can be found. Can be overridden. +ARG CONFIG_ROOT=docker/config + +# What the name of the Tomcat app (and therefore the URL should be). Can be overridden. +ARG TOMCAT_APP_NAME=corpus-frontend + +COPY ${CONFIG_ROOT}/corpus-frontend.properties /etc/blacklab/ + +# Copy the WAR file +COPY --from=builder /app/target/corpus-frontend-*.war /usr/local/tomcat/webapps/${TOMCAT_APP_NAME}.war \ No newline at end of file