Skip to content

Commit

Permalink
First implementation of Docker image, still missing data import
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Mar 4, 2024
1 parent 2d05aa8 commit 72e3e8d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
67 changes: 67 additions & 0 deletions .docker/README.md
Original file line number Diff line number Diff line change
@@ -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

<!--
```bash
# Move subjects TSV file to mounted data folder
cp subjects.tsv data/subjects.tsv
docker compose run -it subjects-api npm run import -- /data/subjects.tsv
``` -->

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.)
14 changes: 14 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

export DATABASE="${DATABASE:-/data/subjects.db}"

pm2-runtime server.js
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
subjects.db*
*.tsv
node_modules/
.env
.docker/data*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules/

*.tsv
subjects.db*
.docker/data*

npm-debug.log*
yarn-debug.log*
Expand Down

0 comments on commit 72e3e8d

Please sign in to comment.