diff --git a/compose.yaml b/compose.yaml index 9b245a8..97087b7 100644 --- a/compose.yaml +++ b/compose.yaml @@ -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/ diff --git a/couchdb-init.Dockerfile b/couchdb-init.Dockerfile new file mode 100644 index 0000000..b12ca24 --- /dev/null +++ b/couchdb-init.Dockerfile @@ -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"] diff --git a/couchdb-init.py b/couchdb-init.py new file mode 100644 index 0000000..9c2537a --- /dev/null +++ b/couchdb-init.py @@ -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) diff --git a/couchdb.http b/couchdb.http index bea3b02..1bec66b 100644 --- a/couchdb.http +++ b/couchdb.http @@ -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 diff --git a/data/index.html b/data/index.html index 379cb01..fe2aea4 100644 --- a/data/index.html +++ b/data/index.html @@ -15,6 +15,7 @@
  • whoami
  • pgAdmin
  • PostGraphile
  • +
  • PostgREST
  • Scalar
  • Superset
  • Metabase
  • diff --git a/metabase/Dockerfile b/metabase/Dockerfile index b93adab..dba1809 100644 --- a/metabase/Dockerfile +++ b/metabase/Dockerfile @@ -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"] diff --git a/metabase/init_metabase.py b/metabase/metabase_init.py similarity index 100% rename from metabase/init_metabase.py rename to metabase/metabase_init.py