From d3f5a603e5fce9d7143a849b9a1c4c7757b8cd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Aim=C3=A9e=20Smiseth?= <51710585+SaraSmiseth@users.noreply.github.com> Date: Sat, 1 May 2021 13:04:23 +0200 Subject: [PATCH] WIP Add environment variables for Database configuration. TODO test it with postgres --- CHANGELOG.md | 1 + conf.d/02-storage.cfg.lua | 21 +++++++++++++++++---- docker-entrypoint.sh | 4 ++++ readme.md | 6 ++++++ tests/docker-compose.yml | 14 ++++++++++++++ tests/requirements.txt | 6 +++--- 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77049b1..f9fd989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Updated luarocks to version 3.7.0. +* Create environment variables for database settings. It is now possible to use MariaDB or Postgres instead of SQLite. ## v1.1.4 diff --git a/conf.d/02-storage.cfg.lua b/conf.d/02-storage.cfg.lua index b8cb6d7..175fb3a 100644 --- a/conf.d/02-storage.cfg.lua +++ b/conf.d/02-storage.cfg.lua @@ -1,8 +1,21 @@ default_storage = "sql" -sql = { - driver = "SQLite3"; - database = "prosody.sqlite"; -} + +-- TODO change if +--if DB_DRIVER then + sql = { + driver = os.getenv("DB_DRIVER"); -- May also be "PostgreSQL" or "MySQL" or "SQLite3" (case sensitive!) + database = os.getenv("DB_DATABASE"); -- The database name to use. For SQLite3 this the database filename (relative to the data storage directory). + host = os.getenv("DB_HOST"); -- The address of the database server (delete this line for Postgres) + port = os.getenv("DB_PORT"); -- 3306 - For databases connecting over TCP + username = os.getenv("DB_USERNAME"); -- The username to authenticate to the database + password = os.getenv("DB_PASSWORD"); -- The password to authenticate to the database + } +--else + --sql = { + --driver = "SQLite3"; + --database = "prosody.sqlite"; + --} +--end -- make 0.10-distributed mod_mam use sql store archive_store = "archive2" -- Use the same data store as prosody-modules mod_mam diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index a7090d3..0b8f9fe 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -21,6 +21,10 @@ export SERVER_CONTACT_INFO_SECURITY=${SERVER_CONTACT_INFO_SECURITY:-"xmpp:securi export SERVER_CONTACT_INFO_SUPPORT=${SERVER_CONTACT_INFO_SUPPORT:-"xmpp:support@$DOMAIN"} export PROSODY_ADMINS=${PROSODY_ADMINS:-""} +# TODO sort into above +export DB_DRIVER=${DB_DRIVER:-"SQLite3"} +export DB_DATABASE=${DB_DATABASE:-"prosody.sqlite"} + if [[ "$1" != "prosody" ]]; then exec prosodyctl $* exit 0; diff --git a/readme.md b/readme.md index cc4d04d..6f5210e 100644 --- a/readme.md +++ b/readme.md @@ -194,6 +194,12 @@ Inspect logs: ```docker-compose logs -f```. | **DOMAIN_MUC** | Domain for Multi-user chat (MUC) for allowing you to create hosted chatrooms/conferences for XMPP users | *optional* | conference.**DOMAIN** | | **DOMAIN_PROXY** | Domain for SOCKS5 bytestream proxy for server-proxied file transfers | *optional* | proxy.**DOMAIN** | | **DOMAIN_PUBSUB** | Domain for a XEP-0060 pubsub service | *optional* | pubsub.**DOMAIN** | +|**DB_DRIVER** | May also be "PostgreSQL" or "MySQL" or "SQLite3" (case sensitive!)| +|**DB_DATABASE** | The database name to use. For SQLite3 this the database filename (relative to the data storage directory).| +|**DB_HOST** | The address of the database server (delete this line for Postgres)| +|**DB_PORT** | 3306 - For databases connecting over TCP| +|**DB_USERNAME** | The username to authenticate to the database| +|**DB_PASSWORD** | The password to authenticate to the database| | **E2E_POLICY_CHAT** | Policy for chat messages. Possible values: "none", "optional" and "required". | *optional* | "required" | | **E2E_POLICY_MUC** | Policy for MUC messages. Possible values: "none", "optional" and "required". | *optional* | "required" | | **E2E_POLICY_WHITELIST** | Make this module ignore messages sent to and from this JIDs or MUCs. | *optional* | "" | diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index c04c41b..dede8cb 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -15,6 +15,8 @@ services: E2E_POLICY_WHITELIST: "admin@localhost, user1@localhost" LOG_LEVEL: debug PROSODY_ADMINS: "admin@localhost, admin2@localhost" + #DB_DRIVER: "SQLite3" + #DB_DATABASE: "prosody.sqlite" extra_hosts: - "conference.localhost:127.0.0.1" - "pubsub.localhost:127.0.0.1" @@ -22,3 +24,15 @@ services: - "upload.localhost:127.0.0.1" volumes: - ./certs:/usr/local/etc/prosody/certs + depends_on: + - postgres + + postgres: + image: postgres:13-alpine + restart: unless-stopped + environment: + POSTGRES_DB: prosody + POSTGRES_USER: prosody + POSTGRES_PASSWORD: prosody + #volumes: + #- ./postgres-data:/var/lib/postgresql/data diff --git a/tests/requirements.txt b/tests/requirements.txt index bcd35ba..7bb2363 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,3 +1,3 @@ -aioxmpp==0.11.0 -pip-chill==1.0.0 -pytest-asyncio==0.14.0 +aioxmpp==0.12.2 +pip-chill==1.0.1 +pytest-asyncio==0.15.1