inventaire service: use a custom entrypoint script

to initialize the local config from env variables
This commit is contained in:
maxlath
2025-02-26 23:32:20 +01:00
parent 1b94320cb2
commit 80b8985198
5 changed files with 41 additions and 7 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,3 @@
inventaire
.env
data
log

View File

@@ -1,8 +1,6 @@
services:
inventaire:
image: inventaire:latest
volumes:
- ./inventaire:/opt/inventaire
image: inventaire/inventaire:latest
env_file: .env
depends_on:
- couchdb

13
dotenv
View File

@@ -6,12 +6,21 @@ PROJECT_ROOT=/opt/inventaire
# Generic user, to modify only for good reason
COUCHDB_USER=couchdb
# Consider passwords with no less than 32 charracters, for example:
# cat /dev/urandom | tr -dc A-Za-z0-9-_ | head -c 32
COUCHDB_PASSWORD=your_password
NODE_ENV=production
NODE_APP_INSTANCE=federated
# Matching the port defined in inventaire/config/production-federated.cjs
# Conventional port for Inventaire server in federated mode
INVENTAIRE_PORT=3016
INSTANCE_NAME='My Inventaire Instance'
# Will be displayed on landing screen
ORG_NAME='Example Organization'
ORG_URL='https://inventaire.example.org'
# Users receiving emails from the instance can reply to this
CONTACT_ADDRESS='contact@inventaire.example.org'

View File

@@ -32,6 +32,8 @@ RUN npm ci \
WORKDIR /opt/inventaire
COPY docker-entrypoint.sh docker-entrypoint.sh
# Avoid using npm script to start the server
# See https://adambrodziak.pl/dockerfile-good-practices-for-node-and-npm#heading-use-node-not-npm-to-start-the-server
CMD [ "./scripts/typescript/start_built_server.sh" ]
ENTRYPOINT [ "./docker-entrypoint.sh" ]

26
inventaire/docker-entrypoint.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -eu
# Overwrite the local config with environment variables every time the container is restarted
cat > ./config/local.cjs << EOF
module.exports = {
port: '${INVENTAIRE_PORT}',
publicHostname: '${PUBLIC_HOSTNAME}',
instanceName: '${INSTANCE_NAME}',
orgName: '${ORG_NAME}',
orgUrl: '${ORG_URL}',
contactAddress: '${CONTACT_ADDRESS}',
db: {
username: '${COUCHDB_USER}',
password: '${COUCHDB_PASSWORD}',
hostname: 'couchdb',
},
elasticsearch: {
origin: 'http://elasticsearch:9200',
}
}
EOF
./scripts/typescript/start_built_server.sh