From 72e3e8d58fce8735d79e76e5d0e0e1377c69e375 Mon Sep 17 00:00:00 2001 From: Stefan Peters Date: Mon, 4 Mar 2024 14:51:26 +0100 Subject: [PATCH] First implementation of Docker image, still missing data import --- .docker/Dockerfile | 17 ++++++++++ .docker/README.md | 67 ++++++++++++++++++++++++++++++++++++++ .docker/docker-compose.yml | 14 ++++++++ .docker/entrypoint.sh | 5 +++ .dockerignore | 5 +++ .gitignore | 1 + 6 files changed, 109 insertions(+) create mode 100644 .docker/Dockerfile create mode 100644 .docker/README.md create mode 100644 .docker/docker-compose.yml create mode 100755 .docker/entrypoint.sh create mode 100644 .dockerignore diff --git a/.docker/Dockerfile b/.docker/Dockerfile new file mode 100644 index 0000000..380da40 --- /dev/null +++ b/.docker/Dockerfile @@ -0,0 +1,17 @@ +FROM node:20-alpine + +WORKDIR /usr/src/app + +# Copy and install dependencies +COPY package*.json ./ +RUN npm ci --omit=dev + +# Bundle app source +COPY . . + +RUN mkdir /data + +# Use pm2 to run app +RUN npm i -g pm2 + +CMD .docker/entrypoint.sh diff --git a/.docker/README.md b/.docker/README.md new file mode 100644 index 0000000..f1166df --- /dev/null +++ b/.docker/README.md @@ -0,0 +1,67 @@ +# [Subjects API](https://github.com/gbv/subjects-api) (Docker) + +API to provide information about subject indexing in the K10plus catalog. It is part of a larger infrastructure of [Project coli-conc](https://coli-conc.gbv.de). + +- See [GitHub](https://github.com/gbv/subjects-api) for more information about the tool. + +## Supported Architectures +Currently, only `x86-64` is supported. + +## Available Tags +- The current release version is available under `latest`. However, new major versions might break compatibility of the previously used config file, therefore it is recommended to use a version tag instead. +- We follow SemVer for versioning the application. Therefore, `x` offers the latest image for the major version x, `x.y` offers the latest image for the minor version x.y, and `x.y.z` offers the image for a specific patch version x.y.z. +- Additionally, the latest development version is available under `dev`. + +## Usage +It is recommended to run the image using [Docker Compose](https://docs.docker.com/compose/). Note that depending on your system, it might be necessary to use `sudo docker compose`. For older Docker versions, use `docker-compose` instead of `docker compose`. + +1. Create `docker-compose.yml`: + +```yml +version: "3" + +services: + subjects-api: + image: ghcr.io/gbv/subjects-api + volumes: + - ./data:/data + environment: + - NODE_ENV=production + ports: + - 3141:3141 + restart: unless-stopped + +``` + +2. Create data folder: + +```bash +mkdir -p ./data +``` + +3. Import the data from TSV: + +TODO + + + +4. Start the application: + +```bash +docker compose up -d +``` + +This will create and start a subjects-api container running under host (and guest) port 3141. See [Configuration](#configuration) on how to configure it. + +You can now access the application under `http://localhost:3141`. + +## Application Setup +After changing `docker-compose.yml` (e.g. adjusting environment variables), it is necessary to recreate the container to apply changes: `docker compose up -d` + +### Configuration +The folder `/data` (mounted as `./data` if configured as above) will contain the SQLite database `subjects.db` and related files. You can use environment variables via `environment` to configure subjects-api. Please refer to the [main documentation](../README.md#configuration) for more information and all available options. (Note that paths are always **inside** the container.) diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml new file mode 100644 index 0000000..3198c29 --- /dev/null +++ b/.docker/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3" + +services: + subjects-api: + build: + context: .. + dockerfile: .docker/Dockerfile + volumes: + - ./data:/data + environment: + - NODE_ENV=production + ports: + - 3141:3141 + restart: unless-stopped diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh new file mode 100755 index 0000000..034fe21 --- /dev/null +++ b/.docker/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +export DATABASE="${DATABASE:-/data/subjects.db}" + +pm2-runtime server.js diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1f7e588 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +subjects.db* +*.tsv +node_modules/ +.env +.docker/data* diff --git a/.gitignore b/.gitignore index 9fac33a..c37a3f1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules/ *.tsv subjects.db* +.docker/data* npm-debug.log* yarn-debug.log*