Skip to content

Commit 6651e9f

Browse files
author
Thomas Bergwinkl
authored
Merge pull request #80 from sandhose/sandhose/config-from-env
Load config file from env
2 parents 5e2a763 + 07b3a00 commit 6651e9f

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

Dockerfile

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ FROM node:lts-alpine
22

33
WORKDIR /app
44

5+
# Use tini for PID1
6+
# https://github.com/krallin/tini
7+
RUN apk add --no-cache tini
8+
59
# Copy the package.json and install the dependencies
610
COPY package.json ./
711
COPY .npmrc ./
@@ -18,12 +22,9 @@ LABEL org.label-schema.name="Trifid" \
1822
org.label-schema.vendor="Zazuko" \
1923
org.label-schema.schema-version="1.0"
2024

21-
ENTRYPOINT []
25+
ENTRYPOINT ["tini", "--", "/app/server.js"]
2226

23-
# Using npm scripts for running the app allows two things:
24-
# - Handle signals correctly (Node does not like to be PID1)
25-
# - Let Skaffold detect it's a node app so it can attach the Node debugger
26-
CMD ["npm", "run", "start"]
27+
ENV TRIFID_CONFIG config.json
2728

2829
EXPOSE 8080
2930
HEALTHCHECK CMD wget -q -O- http://localhost:8080/health

Tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ If you just want to execute Trifid without much tweaking, the easiest way is to
1616

1717
The default configuration won't do much so you need to specify a different configuration file, as described below. Once you have an adjusted config file run the image:
1818

19-
docker run -ti -e TRIFID_CONFIG=config-custom.json -v $(pwd)/config-custom.json:/usr/src/app/config-custom.json -p 8080:8080 zazuko/trifid
19+
docker run -ti -e TRIFID_CONFIG=config-custom.json -v $(pwd)/config-custom.json:/app/config-custom.json -p 8080:8080 zazuko/trifid
2020

2121
With `-e TRIFID_CONFIG=config-custom.json` we override the configuration file, `-v` mounts the local config file into the container. The `$(pwd)` is necessary as `-v` does not support relative paths.
2222

@@ -27,7 +27,7 @@ In case you want to do the same with `docker-compose, a YAML file should contain
2727
container_name: myfancyname
2828
image: zazuko/trifid
2929
volumes:
30-
- ./config-custom.json:/usr/src/app/config-custom.json
30+
- ./config-custom.json:/app/config-custom.json
3131
environment:
3232
- TRIFID_CONFIG=config-custom.json
3333
```

server.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ const Trifid = require('trifid-core')
88

99
program
1010
.option('-v, --verbose', 'verbose output', () => true)
11-
.option('-c, --config <path>', 'configuration file', 'config.json')
11+
.option('-c, --config <path>', 'configuration file', process.env.TRIFID_CONFIG)
1212
.option('-p, --port <port>', 'listener port', parseInt)
1313
.option('--sparql-endpoint-url <url>', 'URL of the SPARQL HTTP query interface')
1414
.option('--dataset-base-url <url>', 'Base URL of the dataset')
1515
.parse(process.argv)
1616

1717
// automatically switch to config-sparql if a SPARQL endpoint URL is given and no config file was defined
18-
if (program.sparqlEndpointUrl && program.config === 'config.json') {
18+
if (program.sparqlEndpointUrl && !program.config) {
1919
program.config = 'config-sparql.json'
20+
} else if (!program.config) {
21+
program.config = 'config.json'
2022
}
2123

2224
// create a minimal configuration with a baseConfig pointing to the given config file

0 commit comments

Comments
 (0)