docker-compose.yml: use a pre-build inventaire image and env_file=.env

and customize CouchDB entrypoint script to fix the issue of the missing _users database
This commit is contained in:
maxlath
2025-02-26 20:55:53 +01:00
parent 9187c32c00
commit 69db3e1a86
6 changed files with 48 additions and 24 deletions

0
Dockerfile.inventaire Executable file → Normal file
View File

View File

@@ -0,0 +1,14 @@
FROM couchdb:3.4.2
COPY docker-custom-entrypoint.sh /usr/local/bin/docker-custom-entrypoint.sh
COPY init_users_db.sh /usr/local/bin/init_users_db.sh
ENTRYPOINT ["tini", "--", "/usr/local/bin/docker-custom-entrypoint.sh"]
EXPOSE 5984
# Copied from the couchdb image Dockerfile
# https://github.com/apache/couchdb-docker/blob/734c61f/3.4.2/Dockerfile#L104
# as it would have been otherwise reset to an empty string
# See https://docs.docker.com/reference/dockerfile/#understand-how-cmd-and-entrypoint-interact
CMD ["/opt/couchdb/bin/couchdb"]

View File

@@ -0,0 +1,3 @@
#!/bin/bash
/usr/local/bin/init_users_db.sh &
tini -- /docker-entrypoint.sh "$@"

12
couchdb/init_users_db.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
while :; do {
echo "[init_users_db.sh] Waiting for CouchDB to be online to initialize the _users database"
curl http://localhost:5984 && {
echo "[init_users_db.sh] CouchDB is online! Trying to initialize _users database"
curl --user "$COUCHDB_USER:$COUCHDB_PASSWORD" -XPUT http://localhost:5984/_users
break
} || {
sleep 1
}
}; done

View File

@@ -1,31 +1,23 @@
version: '3'
services: services:
inventaire: inventaire:
build: image: inventaire:latest
context: ./.
dockerfile: Dockerfile.inventaire
volumes: volumes:
- ./inventaire:${PROJECT_ROOT} - ./inventaire:/opt/inventaire
working_dir: ${PROJECT_ROOT} env_file: .env
environment:
NODE_ENV: 'production'
NODE_APP_INSTANCE: 'federated'
COUCHDB_USER: ${COUCHDB_USER}
COUCHDB_PASSWORD: ${COUCHDB_PASSWORD}
PUBLIC_HOSTNAME: ${PUBLIC_HOSTNAME}
depends_on: depends_on:
- couchdb
- elasticsearch - elasticsearch
tty: true tty: true
logging: logging:
options: options:
max-size: "10m" max-size: "10m"
max-file: "3" max-file: "3"
restart: "always" restart: unless-stopped
couchdb: couchdb:
image: couchdb:3.4.2 build:
environment: context: ./couchdb
COUCHDB_USER: ${COUCHDB_USER} dockerfile: Dockerfile.couchdb
COUCHDB_PASSWORD: ${COUCHDB_PASSWORD} env_file: .env
# Uncomment ports to get access to the db # Uncomment ports to get access to the db
# ie. for database transformation, querying, UI access (http://localhost:5984/_utils/) # ie. for database transformation, querying, UI access (http://localhost:5984/_utils/)
# ports: # ports:
@@ -34,7 +26,7 @@ services:
- 'couchdb:/opt/couchdb/data' - 'couchdb:/opt/couchdb/data'
- './configs:/opt/couchdb/etc/local.d' - './configs:/opt/couchdb/etc/local.d'
tty: true tty: true
restart: "always" restart: unless-stopped
elasticsearch: elasticsearch:
image: elasticsearch:7.16.2 image: elasticsearch:7.16.2
environment: environment:
@@ -47,7 +39,7 @@ services:
- 'ES_JAVA_OPTS=-Xms1g -Xmx1g' - 'ES_JAVA_OPTS=-Xms1g -Xmx1g'
volumes: volumes:
- 'elasticsearch:/usr/share/elasticsearch/data' - 'elasticsearch:/usr/share/elasticsearch/data'
restart: "always" restart: unless-stopped
nginx: nginx:
build: build:
context: ./nginx context: ./nginx
@@ -61,13 +53,11 @@ services:
- ./inventaire:${PROJECT_ROOT} - ./inventaire:${PROJECT_ROOT}
- certbot-www:/var/www/certbot - certbot-www:/var/www/certbot
- ./certbot/conf:/etc/letsencrypt - ./certbot/conf:/etc/letsencrypt
environment: env_file: .env
PROJECT_ROOT: ${PROJECT_ROOT}
PUBLIC_HOSTNAME: ${PUBLIC_HOSTNAME}
INVENTAIRE_PORT: ${INVENTAIRE_PORT}
depends_on: depends_on:
# Required to be able to define the `inventaire` host as an upstream
- inventaire - inventaire
restart: "always" restart: unless-stopped
certbot: certbot:
image: certbot/certbot:latest image: certbot/certbot:latest
volumes: volumes:

5
dotenv
View File

@@ -10,3 +10,8 @@ COUCHDB_USER=couchdb
# Consider passwords with no less than 32 charracters, for example: # Consider passwords with no less than 32 charracters, for example:
# cat /dev/urandom | tr -dc A-Za-z0-9-_ | head -c 32 # cat /dev/urandom | tr -dc A-Za-z0-9-_ | head -c 32
COUCHDB_PASSWORD=your_password COUCHDB_PASSWORD=your_password
NODE_ENV=production
NODE_APP_INSTANCE=federated
# Matching the port defined in inventaire/config/production-federated.cjs
INVENTAIRE_PORT=3016