From 211ec56fb6f87e742af679808667670f9871593f Mon Sep 17 00:00:00 2001 From: medina5 Date: Wed, 22 Oct 2025 21:27:41 +0200 Subject: [PATCH] =?UTF-8?q?mise=20=C3=A0=20jour=20compose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 5 ++++ .gitignore | 1 + compose.yml | 31 +++++++++++++++++++++---- mongodb-entrypoint-initdb.d/1_import.sh | 8 +++++++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .env.example create mode 100644 .gitignore create mode 100755 mongodb-entrypoint-initdb.d/1_import.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..b6cf63b --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +MONGODB_USER=admin +MONGODB_PASSWORD=!ChangeMe! + +MONGOEXPRESS_USER=admin +MONGOEXPRESS_PASSWORD=!ChangeMe! diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/compose.yml b/compose.yml index a28ad09..64e260e 100644 --- a/compose.yml +++ b/compose.yml @@ -1,14 +1,18 @@ services: mongodb: - image: mongo:${MONGODB_VERSION:-8.0-jammy} + image: mongodb/mongodb-community-server:8.0-ubi8 volumes: - mongodb_config:/data/configdb - mongodb_data:/data/db + - ./mongodb-entrypoint-initdb.d:/docker-entrypoint-initdb.d:Z + - ./initdb.d:/initdb.d:z ports: - - ${MONGODB_PORT:-27017}:27017 + - "27017:27017" + networks: + - caddy_net environment: - MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-admin} - MONGO_INITDB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:ChangeMe!} + MONGODB_INITDB_ROOT_USERNAME: ${MONGODB_USER} + MONGODB_INITDB_ROOT_PASSWORD: ${MONGODB_PASSWORD} mongodb-exporter: image: percona/mongodb_exporter:0.47 @@ -19,6 +23,25 @@ services: labels: prometheus-job: mongodb + mongo-express: + image: mongo-express + restart: "no" + depends_on: + - mongodb + environment: + ME_CONFIG_MONGODB_URL: mongodb://${MONGODB_USER}:${MONGODB_PASSWORD}@mongodb:27017/ + ME_CONFIG_BASICAUTH_ENABLED: true + ME_CONFIG_BASICAUTH_USERNAME: ${MONGOEXPRESS_USER} + ME_CONFIG_BASICAUTH_PASSWORD: ${MONGOEXPRESS_PASSWORD} + ports: + - 8081:8081 + networks: + - caddy_net + labels: + caddy: mongo-express.localhost + caddy.reverse_proxy: "{{upstreams 8081}}" + caddy.tls: internal + volumes: mongodb_config: mongodb_data: diff --git a/mongodb-entrypoint-initdb.d/1_import.sh b/mongodb-entrypoint-initdb.d/1_import.sh new file mode 100755 index 0000000..6eab1f1 --- /dev/null +++ b/mongodb-entrypoint-initdb.d/1_import.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +for file in /initdb.d/commandes/*.json; do + collection=$(basename "$file" .json) + echo "Importing $collection..." + mongoimport --db commerce --collection "$collection" --file "$file" --jsonArray +done