From 28affcc3c39479985af92d721da78f8df1a6f985 Mon Sep 17 00:00:00 2001 From: saulteafarmer Date: Wed, 14 May 2025 18:26:09 +0000 Subject: [PATCH] Update docker-compose.yml --- docker-compose.yml | 89 +++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 52 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ef98e1d..14f5a2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,77 +1,62 @@ -version: "3.8" +version: "3.9" services: - - # ── Postgres Database ─────────────────────────────────────────────────────── db: - image: postgres:15-alpine - container_name: lnbits_db + image: postgres:15 + restart: always environment: - POSTGRES_USER: "${DB_USER}" - POSTGRES_PASSWORD: "${DB_PASS}" - POSTGRES_DB: "${DB_NAME}" + POSTGRES_USER: "${DB_USER:-postgres}" + POSTGRES_PASSWORD: "${DB_PASS:-}" + POSTGRES_DB: "${DB_NAME:-lnbitsdb}" volumes: - - postgres_data:/var/lib/postgresql/data + - db_data:/var/lib/postgresql/data healthcheck: - test: ["CMD", "pg_isready", "-U", "${DB_USER}"] - interval: 10s - timeout: 5s + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER}"] + interval: 5s + timeout: 2s retries: 5 - restart: unless-stopped - # ── Web UI ────────────────────────────────────────────────────────────────── web: build: context: . dockerfile: Dockerfile - container_name: discord-lnbits-web + restart: on-failure + depends_on: + db: + condition: service_healthy + env_file: + - .env ports: - "3000:3000" - environment: - DATABASE_URL: "${DATABASE_URL}" - FLASK_SECRET: "${FLASK_SECRET}" - depends_on: - - db - # wait for Postgres then launch Gunicorn + # wait for the DB, then launch the Flask app under Gunicorn command: > - sh -c ' - until pg_isready -h db -U "${DB_USER}" ; do - echo "[web] waiting for db…" ; - sleep 2 ; - done ; + sh -c " + until pg_isready -h db -U \$DB_USER; do + echo '[web] waiting for db…'; + sleep 1; + done && exec gunicorn -b 0.0.0.0:3000 app:app - ' - restart: unless-stopped + " - # ── Discord Lightning Bot ────────────────────────────────────────────────── bot: build: context: . dockerfile: Dockerfile - container_name: discord-lnbits-bot - environment: - DISCORD_TOKEN: "${DISCORD_TOKEN}" - GUILD_ID: "${GUILD_ID}" - ROLE_ID: "${ROLE_ID}" - CHANNEL_ID: "${CHANNEL_ID}" - LNBITS_URL: "${LNBITS_URL}" - LNBITS_API_KEY: "${LNBITS_API_KEY}" - PRICE: "${PRICE}" - COMMAND_NAME: "${COMMAND_NAME}" - INVOICE_MESSAGE: "${INVOICE_MESSAGE}" - DATABASE_URL: "${DATABASE_URL}" + restart: on-failure depends_on: - - db - # wait for Postgres as well, then launch the bot + db: + condition: service_healthy + env_file: + - .env + # wait for the DB, then run your bot loop command: > - sh -c ' - until pg_isready -h db -U "${DB_USER}" ; do - echo "[bot] waiting for db…" ; - sleep 2 ; - done ; - exec python3 discord_lnbits_bot.py - ' - restart: unless-stopped + sh -c " + until pg_isready -h db -U \$DB_USER; do + echo '[bot] waiting for db…'; + sleep 1; + done && + exec python discord_lnbits_bot.py + " volumes: - postgres_data: + db_data: