This commit is contained in:
2025-10-15 07:30:31 +02:00
parent 6961caa2af
commit 7f58f12b8d
7 changed files with 75 additions and 4 deletions

View File

@@ -21,14 +21,17 @@ services:
volumes:
- caddy_config:/config
- caddy_data:/data
- ./data:/srv/www:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data:/srv/www:ro
labels:
caddy: "static.localhost"
caddy.root: "* /srv/www"
caddy.file_server: "" # Active le serveur de fichiers statiques
caddy.tls: internal # HTTPS auto-signé géré par Caddy
# WhoAmI
# Tiny Go webserver that prints OS information and HTTP request to output.
# https://github.com/traefik/whoami
whoami:
image: traefik/whoami
depends_on:
@@ -119,6 +122,18 @@ services:
caddy.reverse_proxy: "{{upstreams 5984}}"
caddy.tls: internal
couchdb-init:
build:
dockerfile: ./couchdb-init.Dockerfile
context: .
environment:
COUCHDB_USER: ${COUCHDB_USER}
COUCHDB_PASSWORD: ${COUCHDB_PASSWORD}
depends_on:
- couchdb
networks:
- caddy_net
# MongoDB
#
# https://www.mongodb.com/

12
couchdb-init.Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM python:3.13-slim
# Installer requests une seule fois dans l'image
RUN python3 -m pip install --no-cache-dir requests
WORKDIR /app
# Copier le script Python
COPY couchdb-init.py /app/
# Lancer le script par défaut
ENTRYPOINT ["python3", "couchdb-init.py"]

40
couchdb-init.py Normal file
View File

@@ -0,0 +1,40 @@
import os, time, requests
COUCHDB_URL = 'http://couchdb:5984'
USER = os.getenv('COUCHDB_USER', 'admin')
PASSWORD = os.getenv('COUCHDB_PASSWORD', 'password')
for _ in range(30):
try:
r = requests.get(COUCHDB_URL)
if r.ok:
break
except Exception:
time.sleep(2)
else:
print('❌ CouchDB n\'est pas joignable')
exit(1)
print('🚀 Vérification de la configuration...')
try:
dbs = requests.get(f'{COUCHDB_URL}/_all_dbs', auth=(USER, PASSWORD))
if dbs.ok and '_users' in dbs.json():
print('✅ CouchDB déjà initialisé.')
exit(0)
except Exception:
pass
print('🛠 Initialisation du mode single-node...')
payload = {
"action": "enable_single_node",
"username": USER,
"password": PASSWORD,
"bind_address": "0.0.0.0"
}
r1 = requests.post(f'{COUCHDB_URL}/_cluster_setup', json=payload)
r2 = requests.post(f'{COUCHDB_URL}/_cluster_setup', json={"action": "finish_cluster"})
if r1.ok and r2.ok:
print('✅ CouchDB initialisé avec succès.')
else:
print('❌ Erreur lors de l\'initialisation :', r1.text, r2.text)

View File

@@ -1,6 +1,6 @@
@couchDB = http://{{$dotenv COUCHDB_USER}}:{{$dotenv COUCHDB_PASSWORD}}@couchdb.localhost
###
### Init
POST {{couchDB}}/_cluster_setup
Content-Type: application/json
@@ -13,6 +13,9 @@ Content-Type: application/json
"port": 5984
}
### Creates a new database.
GET {{couchDB}}/_users
###
GET {{couchDB}}/_all_dbs

View File

@@ -15,6 +15,7 @@
<li><a href="//whoami.localhost">whoami</a></li>
<li><a href="//pgadmin.localhost">pgAdmin</a></li>
<li><a href="//postgraphile.localhost/graphiql">PostGraphile</a></li>
<li><a href="//postgrest.localhost">PostgREST</a></li>
<li><a href="//scalar.localhost">Scalar</a></li>
<li><a href="//superset.localhost">Superset</a></li>
<li><a href="//metabase.localhost">Metabase</a></li>

View File

@@ -6,7 +6,7 @@ RUN python3 -m pip install --no-cache-dir requests
WORKDIR /app
# Copier le script Python
COPY init_metabase.py /app/
COPY metabase_init.py /app/
# Lancer le script par défaut
ENTRYPOINT ["python3", "init_metabase.py"]
ENTRYPOINT ["python3", "metabase_init.py"]