From 4bc78996c1e60c9200c4a92fffe6c9265d03c67b Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 4 Nov 2018 23:05:39 +0200 Subject: [PATCH] Add UID/GID option and custom config base for docker Closes #13 --- Dockerfile | 6 +++- docker-run.sh | 25 --------------- docker/example-config.yaml | 66 ++++++++++++++++++++++++++++++++++++++ docker/run.sh | 21 ++++++++++++ 4 files changed, 92 insertions(+), 26 deletions(-) delete mode 100755 docker-run.sh create mode 100644 docker/example-config.yaml create mode 100755 docker/run.sh diff --git a/Dockerfile b/Dockerfile index d9a43f9..710b778 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM alpine:3.8 +ENV UID=1337 \ + GID=1337 + COPY . /opt/maubot WORKDIR /opt/maubot RUN apk add --no-cache \ @@ -9,8 +12,9 @@ RUN apk add --no-cache \ py3-bcrypt \ py3-cffi \ ca-certificates \ + su-exec \ && pip3 install -r requirements.txt VOLUME /data -CMD ["/opt/maubot/docker-run.sh"] +CMD ["/opt/maubot/docker/run.sh"] diff --git a/docker-run.sh b/docker-run.sh deleted file mode 100755 index 424953a..0000000 --- a/docker-run.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -cd /opt/maubot - -# Replace database path in config. -sed -i "s#sqlite:///maubot.db#sqlite:////data/maubot.db#" /data/config.yaml -sed -i "s#- ./plugins#- /data/plugins#" /data/config.yaml -sed -i "s#upload: ./plugins#upload: /data/plugins#" /data/config.yaml -sed -i "s#trash: ./trash#trash: /data/trash#" /data/config.yaml -sed -i "s#db: ./plugins#trash: /data/dbs#" /data/config.yaml -sed -i "s#./logs/maubot.log#/var/log/maubot/maubot.log#" /data/config.yaml - -mkdir -p /var/log/maubot /data/plugins /data/trash /data/dbs - -# Check that database is in the right state -alembic -x config=/data/config.yaml upgrade head - -if [ ! -f /data/config.yaml ]; then - cp example-config.yaml /data/config.yaml - echo "Config file not found. Example config copied to /data/config.yaml" - echo "Please modify the config file to your liking and restart the container." - exit -fi - -python3 -m maubot -c /data/config.yaml diff --git a/docker/example-config.yaml b/docker/example-config.yaml new file mode 100644 index 0000000..77f97f0 --- /dev/null +++ b/docker/example-config.yaml @@ -0,0 +1,66 @@ +# The full URI to the database. SQLite and Postgres are fully supported. +# Other DBMSes supported by SQLAlchemy may or may not work. +# Format examples: +# SQLite: sqlite:///filename.db +# Postgres: postgres://username:password@hostname/dbname +database: sqlite:////data/maubot.db + +plugin_directories: + # The directory where uploaded new plugins should be stored. + upload: /data/plugins + # The directories from which plugins should be loaded. + # Duplicate plugin IDs will be moved to the trash. + load: + - /data/plugins + # The directory where old plugin versions and conflicting plugins should be moved. + # Set to "delete" to delete files immediately. + trash: /data/trash + # The directory where plugin databases should be stored. + db: /data/plugins + +server: + # The IP and port to listen to. + hostname: 0.0.0.0 + port: 29316 + # The base management API path. + base_path: /_matrix/maubot/v1 + # The base appservice API path. Use / for legacy appservice API and /_matrix/app/v1 for v1. + appservice_base_path: /_matrix/app/v1 + # The shared secret to sign API access tokens. + # Set to "generate" to generate and save a new token at startup. + unshared_secret: generate + +# List of administrator users. Plaintext passwords will be bcrypted on startup. Set empty password +# to prevent normal login. Root is a special user that can't have a password and will always exist. +admins: + root: "" + +# Python logging configuration. +# +# See section 16.7.2 of the Python documentation for more info: +# https://docs.python.org/3.6/library/logging.config.html#configuration-dictionary-schema +logging: + version: 1 + formatters: + precise: + format: "[%(asctime)s] [%(levelname)s@%(name)s] %(message)s" + handlers: + file: + class: logging.handlers.RotatingFileHandler + formatter: precise + filename: /var/log/maubot.log + maxBytes: 10485760 + backupCount: 10 + console: + class: logging.StreamHandler + formatter: precise + loggers: + maubot: + level: DEBUG + mautrix: + level: DEBUG + aiohttp: + level: INFO + root: + level: DEBUG + handlers: [file, console] diff --git a/docker/run.sh b/docker/run.sh new file mode 100755 index 0000000..24c8f60 --- /dev/null +++ b/docker/run.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +function fixperms { + chown -R $UID:$GID /var/log /data /opt/maubot +} + +cd /opt/maubot + +if [ ! -f /data/config.yaml ]; then + cp docker/example-config.yaml /data/config.yaml + mkdir -p /var/log /data/plugins /data/trash /data/dbs + echo "Config file not found. Example config copied to /data/config.yaml" + echo "Please modify the config file to your liking and restart the container." + fixperms + exit +fi + +mkdir -p /var/log/maubot /data/plugins /data/trash /data/dbs +#alembic -x config=/data/config.yaml upgrade head +fixperms +exec su-exec $UID:$GID python3 -m maubot -c /data/config.yaml -b docker/example-config.yaml