Skip to content

Commit

Permalink
Combined frontend + blacklab-proxy Docker image (#437)
Browse files Browse the repository at this point in the history
Docker image that adds frontend to BLS's.
  • Loading branch information
jan-niestadt authored May 24, 2023
1 parent 9091082 commit a272e31
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 22 deletions.
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
====================
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 16 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions docker/config/corpus-frontend.properties
Original file line number Diff line number Diff line change
@@ -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 '<corporaInterfaceDataDir>/MyCorpus/'.
corporaInterfaceDataDir=/etc/blacklab/projectconfigs/

# For unconfigured corpora, the directory where defaults may be found (optional).
Expand Down
8 changes: 6 additions & 2 deletions docker/Dockerfile → docker/frontend-bls.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions docker/frontend-proxy.dockerfile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a272e31

Please sign in to comment.