diff --git a/Dockerfile b/Dockerfile index be0eb6c..0d6bb28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN apk add --no-cache \ python3 py3-pip py3-setuptools py3-wheel \ ca-certificates \ su-exec \ + yq \ py3-aiohttp \ py3-sqlalchemy \ py3-attrs \ @@ -51,7 +52,8 @@ RUN apk add --virtual .build-deps python3-dev build-base git \ && sed -Ei 's/psycopg2-binary.+//' optional-requirements.txt \ && pip3 install -r requirements.txt -r optional-requirements.txt \ dateparser langdetect python-gitlab pyquery cchardet semver tzlocal cssselect \ - && apk del .build-deps + && apk del .build-deps \ + && cp maubot/example-config.yaml . && rm -rf maubot # TODO also remove dateparser, langdetect and pyquery when maubot supports installing dependencies COPY . /opt/maubot diff --git a/Dockerfile.ci b/Dockerfile.ci index 4350c26..09bdb5f 100644 --- a/Dockerfile.ci +++ b/Dockerfile.ci @@ -4,6 +4,7 @@ RUN apk add --no-cache \ python3 py3-pip py3-setuptools py3-wheel \ ca-certificates \ su-exec \ + yq \ py3-aiohttp \ py3-sqlalchemy \ py3-attrs \ diff --git a/docker/example-config.yaml b/docker/example-config.yaml deleted file mode 100644 index 192a420..0000000 --- a/docker/example-config.yaml +++ /dev/null @@ -1,108 +0,0 @@ -# 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 - -# Database for encryption data. -crypto_database: - # Type of database. Either "default", "pickle" or "postgres". - # When set to default, using SQLite as the main database will use pickle as the crypto database - # and using Postgres as the main database will use the same one as the crypto database. - # - # When using pickle, individual crypto databases are stored in the pickle_dir directory. - # When using non-default postgres, postgres_uri is used to connect to postgres. - type: default - postgres_uri: postgres://username:password@hostname/dbname - pickle_dir: /data/crypto - -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 - # Public base URL where the server is visible. - public_url: https://example.com - # The base management API path. - base_path: /_matrix/maubot/v1 - # The base path for the UI. - ui_base_path: /_matrix/maubot - # The base path for plugin endpoints. The instance ID will be appended directly. - plugin_base_path: /_matrix/maubot/plugin/ - # Override path from where to load UI resources. - # Set to false to using pkg_resources to find the path. - override_resource_path: /opt/maubot/frontend - # 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 - -# Shared registration secrets to allow registering new users from the management UI -registration_secrets: - example.com: - # Client-server API URL - url: https://example.com - # registration_shared_secret from synapse config - secret: synapse_shared_registration_secret - -# 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: "" - -# API feature switches. -api_features: - login: true - plugin: true - plugin_upload: true - instance: true - instance_database: true - client: true - client_proxy: true - client_auth: true - dev_open: true - log: true - -# 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 index 96a60b9..ee82283 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -1,21 +1,45 @@ #!/bin/sh function fixperms { - chown -R $UID:$GID /var/log /data /opt/maubot + chown -R $UID:$GID /var/log /data /opt/maubot +} + +function fixconfig { + # If the DB path is the default relative path, replace it with an absolute /data path + _db_url=$(yq e '.database' /data/config.yaml) + if [[ _db_url == "sqlite:///maubot.db" ]]; then + yq e -i '.database = "sqlite:////data/maubot.db"' /data/config.yaml + fi + _log_path=$(yq e '.logging.handlers.file.filename' /data/config.yaml) + if [[ _log_path == "./maubot.log" ]]; then + yq e -i '.logging.handlers.file.filename = "/var/log/maubot.log"' /data/config.yaml + fi + # Set the correct resource paths + yq e -i ' + .server.override_resource_path = "/opt/maubot/frontend" | + .plugin_directories.upload = "/data/plugins" | + .plugin_directories.load = ["/data/plugins"] | + .plugin_directories.trash = "/data/trash" | + .plugin_directories.db = "/data/dbs" + ' /data/config.yaml } cd /opt/maubot -mkdir -p /var/log/maubot /data/plugins /data/trash /data/dbs /data/crypto +mkdir -p /var/log/maubot /data/plugins /data/trash /data/dbs if [ ! -f /data/config.yaml ]; then - cp docker/example-config.yaml /data/config.yaml + cp example-config.yaml /data/config.yaml + # Apply some docker-specific adjustments to the config 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 + fixconfig exit fi 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 +fixconfig + +exec su-exec $UID:$GID python3 -m maubot -c /data/config.yaml