Update standalone dockerfile and add support for config via env vars

This commit is contained in:
Tulir Asokan 2021-11-09 01:39:28 +02:00
parent 274b5465f6
commit 92b3481828
3 changed files with 10 additions and 2 deletions

View file

@ -1,4 +1,4 @@
FROM docker.io/alpine:3.11 FROM docker.io/alpine:3.14
RUN apk add --no-cache \ RUN apk add --no-cache \
py3-aiohttp \ py3-aiohttp \

View file

@ -27,7 +27,7 @@ from ruamel.yaml import YAML
from ruamel.yaml.comments import CommentedMap from ruamel.yaml.comments import CommentedMap
import sqlalchemy as sql 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.util.db import Base
from mautrix.types import (UserID, Filter, RoomFilter, RoomEventFilter, StrippedStateEvent, from mautrix.types import (UserID, Filter, RoomFilter, RoomEventFilter, StrippedStateEvent,
EventType, Membership) EventType, Membership)
@ -55,6 +55,8 @@ config = Config(args.config, args.base_config)
config.load() config.load()
try: try:
config.update() config.update()
except BaseMissingError:
print("No example config found, not updating config")
except Exception as e: except Exception as e:
print("Failed to update config:", e) print("Failed to update config:", e)

View file

@ -17,6 +17,12 @@ from mautrix.util.config import BaseFileConfig, ConfigUpdateHelper
class Config(BaseFileConfig): 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: def do_update(self, helper: ConfigUpdateHelper) -> None:
copy, _, base = helper copy, _, base = helper
copy("user.credentials.id") copy("user.credentials.id")