From eb848af0ad7e1f90ca622b19864be566c126fd1f Mon Sep 17 00:00:00 2001 From: knoflook Date: Thu, 20 Jun 2024 15:36:08 +0200 Subject: [PATCH] add mariadb support --- .env.sample | 3 +++ abra.sh | 1 + compose.yml | 46 +++++++++++++++++++++++++++++++++++++++++++++- entrypoint.sh.tmpl | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 abra.sh create mode 100644 entrypoint.sh.tmpl diff --git a/.env.sample b/.env.sample index 5df1894..30e2966 100644 --- a/.env.sample +++ b/.env.sample @@ -5,4 +5,7 @@ DOMAIN=uptime-kuma.example.com ## Domain aliases #EXTRA_DOMAINS=', `www.uptime-kuma.example.com`' +SECRET_DB_PASSWORD_VERSION=v1 +SECRET_DB_ROOT_PASSWORD_VERSION=v1 + LETS_ENCRYPT_ENV=production diff --git a/abra.sh b/abra.sh new file mode 100644 index 0000000..7c5fe57 --- /dev/null +++ b/abra.sh @@ -0,0 +1 @@ +export APP_ENTRYPOINT_VERSION=v1 diff --git a/compose.yml b/compose.yml index 77a0efc..45a3291 100644 --- a/compose.yml +++ b/compose.yml @@ -3,11 +3,25 @@ version: "3.8" services: app: - image: louislam/uptime-kuma:1.23.11 + image: kn0fl00k/uptime-kuma:unstable volumes: - data:/app/data networks: + - internal - proxy + environment: + - UPTIME_KUMA_GH_REPO=louislam:uptime-kuma + - UPTIME_KUMA_DB_TYPE=mariadb + - UPTIME_KUMA_DB_HOSTNAME=db + - UPTIME_KUMA_DB_PORT=3306 + - UPTIME_KUMA_DB_NAME=kuma + - UPTIME_KUMA_DB_USERNAME=kuma + - UPTIME_KUMA_DB_PASSWORD_FILE=/run/secrets/db_password + configs: + - source: app_entrypoint + target: /docker-entrypoint.sh + mode: 0555 + entrypoint: /docker-entrypoint.sh deploy: update_config: failure_action: rollback @@ -29,10 +43,40 @@ services: timeout: 10s retries: 5 start_period: 2m + db: + image: mariadb:10.8 + environment: + - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_root_password + - MYSQL_PASSWORD_FILE=/run/secrets/db_password + - MYSQL_USER=kuma + - MYSQL_DATABASE=kuma + volumes: + - mariadb:/var/lib/mysql + networks: + - internal + secrets: + - db_password + - db_root_password volumes: + mariadb: data: networks: proxy: external: true + internal: + +secrets: + db_password: + external: true + name: ${STACK_NAME}_db_password_${DB_PASSWORD_VERSION} + db_root_password: + external: true + name: ${STACK_NAME}_db_root_password_${DB_ROOT_PASSWORD_VERSION} + +configs: + app_entrypoint: + name: ${STACK_NAME}_app_entrypoint_${APP_ENTRYPOINT_VERSION} + file: entrypoint.sh.tmpl + template_driver: golang diff --git a/entrypoint.sh.tmpl b/entrypoint.sh.tmpl new file mode 100644 index 0000000..dd0a3a0 --- /dev/null +++ b/entrypoint.sh.tmpl @@ -0,0 +1,32 @@ + +#!/bin/bash + +set -e + +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local def="${2:-}" + + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo >&2 "error: both $var and $fileVar are set (but are exclusive)" + exit 1 + fi + + local val="$def" + + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +file_env "UPTIME_KUMA_DB_PASSWORD" + +# upstream startup command +cd /app +node server/server.js