Skip to content

Commit

Permalink
Add Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Jan 24, 2024
1 parent b6f11be commit 1b276fb
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ cache/
.env
config.json

docker/data
!docker/.env

.DS_Store
node_modules

Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ This node module provides [a web service](#web-service), a [command line client]

- [Background](#background)
- [Install](#install)
- [Clone and Install](#clone-and-install)
- [Configuration](#configuration)
- [Docker](#docker)
- [Node.js](#nodejs)
- [Configuration](#configuration)
- [Usage](#usage)
- [Run Server](#run-server)
- [Deployment](#deployment)
Expand Down Expand Up @@ -69,12 +70,18 @@ Other systems (not including DDC) may also work but they have not been converted

## Install

### Clone and Install
### Docker

The easiest way to run wikidata-jskos is via Docker. Please refer to the [Docker documentation](./docker/README.md).

### Node.js

Node.js 18 is required (Node.js 20 recommended).

```sh
git clone https://github.com/gbv/wikidata-jskos.git
cd wikidata-jskos
npm install
npm ci
```

Optionally make the [command line tool](#command-line-tool) `wdjskos` available:
Expand All @@ -83,7 +90,7 @@ Optionally make the [command line tool](#command-line-tool) `wdjskos` available:
npm link
```

### Configuration
## Configuration

You can customize the application settings via a configuration file, e.g. by providing a generic `config.json` file and/or a more specific `config.{env}.json` file (where `{env}` is the environment like `development` or `production`). The latter will have precendent over the former, and all missing keys will be defaulted with values from `config.default.json`.

Expand Down
1 change: 1 addition & 0 deletions docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Environment variables can also be set here
21 changes: 21 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 /config

# Use pm2 to run app
RUN npm i -g pm2

# Symlink config file
RUN rm config.json
RUN ln -s /config/config.json ./config.json

CMD pm2-runtime server.js
64 changes: 64 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# [Wikidata JSKOS](https://github.com/gbv/wikidata-jskos) (Docker)

Wikidata JSKOS implements a web service to access [Wikidata] in [JSKOS] format. The data includes Wikidata items as concepts and concept schemes (read) and mappings between Wikidata and other authority files (read and write). It is part of a larger infrastructure of [Project coli-conc](https://coli-conc.gbv.de).

- See [GitHub](https://github.com/gbv/wikidata-jskos) 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:
wikidata-jskos:
image: ghcr.io/gbv/wikidata-jskos
# Can be configured via a JSON file mounted into `/config/config.json`...
volumes:
- ./data/config:/config
# ... or via environment variables
environment:
- NODE_ENV=production
- PORT=2013
ports:
- 2013:2013
restart: unless-stopped
```
2. Create data folders:
```bash
mkdir -p ./data/config
echo "{}" > ./data/config/config.json
```

3. Start the application:

```bash
docker compose up -d
```

This will create and start a wikidata-jskos container running under host (and guest) port 2013. See [Configuration](#configuration) on how to configure it.

You can now access the application under `http://localhost:2013`.

## Application Setup
Note: After adjusting any configurations, it is required to restart or recreate the container:
- After changing configuration files, restart the container: `docker compose restart`
- After changing `docker-compose.yml` (e.g. adjusting environment variables), recreate the container: `docker compose up -d`

### Configuration
The folder `/config` (mounted as `./data/config` if configured as above) contains the configuration file `config.json` where wikidata-jskos is configured. You can also use environment variables via `environment` or `env_file` to configure wikidata-jskos. Please refer to the [main documentation](../README.md#configuration) for more information and all available options.

[Wikidata]: https://www.wikidata.org/
[JSKOS]: https://gbv.github.io/jskos/
28 changes: 28 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "3"

services:
wikidata-jskos:
build:
context: ..
dockerfile: docker/Dockerfile
volumes:
- ./data/config:/config
environment:
- NODE_ENV=production
- AUTH_ALGORITHM=RS256
# Example how to set AUTH_KEY (it is recommend to use env_file or config.json instead though)
- |-
AUTH_KEY_=-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjmpVmMlsiVyihtYc/lwS
pxZpyCXcMmdNH8nLHWFbmTvzcBXA7R5uvdH3mZMqF2Cap+VmPmnqXj0A9dLgrDuq
xC4UK049xqcNnuM7Kz7BDJ91KflFN3JBdqW4V7CDTXz4tArzCzrSgOhGACsv3kti
gvi3UEnb74eajS2ZZxHuoXBfvUdBi10RaxEajbbHTl9yGbdcGpLwPo/wum6hCpEv
5yfPx48Sf8T8hgBWccAOljorkKOTNS54Qf9hFH4rGPhnfjjYHz+G3xH6WlNcqIkO
mUd+qsCLVCtxTVh3na0gn2skWDpXwph/o8ftO+/05wykkaodza74P9mvalhk3Vzb
xQIDAQAB
-----END PUBLIC KEY-----
env_file:
- .env
ports:
- 2013:2013
restart: unless-stopped

0 comments on commit 1b276fb

Please sign in to comment.