From 92b3481828425f1c4b1dba1c5addc193204c8ab5 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 9 Nov 2021 01:39:28 +0200 Subject: [PATCH] Update standalone dockerfile and add support for config via env vars --- maubot/standalone/Dockerfile | 2 +- maubot/standalone/__main__.py | 4 +++- maubot/standalone/config.py | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/maubot/standalone/Dockerfile b/maubot/standalone/Dockerfile index 2475749..7456e8b 100644 --- a/maubot/standalone/Dockerfile +++ b/maubot/standalone/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/alpine:3.11 +FROM docker.io/alpine:3.14 RUN apk add --no-cache \ py3-aiohttp \ diff --git a/maubot/standalone/__main__.py b/maubot/standalone/__main__.py index bcc2c72..75e65c2 100644 --- a/maubot/standalone/__main__.py +++ b/maubot/standalone/__main__.py @@ -27,7 +27,7 @@ from ruamel.yaml import YAML from ruamel.yaml.comments import CommentedMap import sqlalchemy as sql -from mautrix.util.config import RecursiveDict +from mautrix.util.config import RecursiveDict, BaseMissingError from mautrix.util.db import Base from mautrix.types import (UserID, Filter, RoomFilter, RoomEventFilter, StrippedStateEvent, EventType, Membership) @@ -55,6 +55,8 @@ config = Config(args.config, args.base_config) config.load() try: config.update() +except BaseMissingError: + print("No example config found, not updating config") except Exception as e: print("Failed to update config:", e) diff --git a/maubot/standalone/config.py b/maubot/standalone/config.py index 2b0fdfe..84f817d 100644 --- a/maubot/standalone/config.py +++ b/maubot/standalone/config.py @@ -17,6 +17,12 @@ from mautrix.util.config import BaseFileConfig, ConfigUpdateHelper class Config(BaseFileConfig): + def __getitem__(self, key: str) -> Any: + try: + return os.environ[f"MAUBOT_{key.replace('.', '_').upper()}"] + except KeyError: + return super().__getitem__(key) + def do_update(self, helper: ConfigUpdateHelper) -> None: copy, _, base = helper copy("user.credentials.id")