From 83e725fecf8cce7c3e939b6ffc82536600132820 Mon Sep 17 00:00:00 2001
From: anima
Date: Fri, 12 Jul 2024 17:23:19 +0200
Subject: [PATCH] inital setup after poc
---
.gitignore | 1 +
README.md | 61 +++++++++++++++++++++++++++-
docker-compose.yml | 84 +++++++++++++++++++++++++++++++++++++++
env.sample | 16 ++++++++
files/element-config.json | 56 ++++++++++++++++++++++++++
5 files changed, 217 insertions(+), 1 deletion(-)
create mode 100644 .gitignore
create mode 100644 docker-compose.yml
create mode 100644 env.sample
create mode 100644 files/element-config.json
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2eea525
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.env
\ No newline at end of file
diff --git a/README.md b/README.md
index 8af114a..6754ee1 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,62 @@
# compose-matrix
-Matrix Stack bestehend aus Matrix Server "Synapse" sowie dem Frontend "Element".
\ No newline at end of file
+Matrix Stack bestehend aus Matrix Server "Synapse" sowie dem Frontend "Element".
+
+## Inital setup
+1. Copy env file: `cp env.sample .env`
+2. Edit env file: `nano .env`
+ 1. Basedir: Full path to dir with compose file (important for swarm shares)
+ 2. Versionnumbers
+ 3. DB settings
+ 4. Domain! (no default)
+2. Genreate inital config for synapse:
+ 1. `source .env`
+ 2. `docker run -it --rm -v --env-file .env ${BASEDIR:-.}/files/:/data -e SYNAPSE_SERVER_NAME=$DOMAIN -e SYNAPSE_REPORT_STATS=no matrixdotorg/synapse:latest generate`
+ - This generate certs and basic inital config (homeserver.yml) for $DOMAIN only for first setup needed
+
+Postgress by default not in use!
+Default DB is SQLite.
+
+3. (optional) Set db in config: `nano $BASEDIR/files/synapse/homeserver.yaml`
+4. Edit element config: `nano files/element-config.json`
+ 1. set "default_server_name" to your domain for Synapse
+ 2. set "m.homeserver" => "base_url" to your domain for Element
+ 3. Hint: by default connection to main servers of matrix.org is enabled
+ 4. Hint: by default jitsi (cloud!) is uses for **group** videocalls
+ - > [^jitsi]: 1:1 calls, or calls between you and one other person, do not use Jitsi. Instead, those calls work directly between clients or via TURN servers configured on the respective homeservers.
+ - Hint: Jisi can be selfhost (no templace exist atm)
+
+5. Run stack `docker compose up`
+
+## howto
+
+### enable registration
+1. edit `homeserver.yaml`
+ 1. set "enable_registration" to "True"
+ 2. set "enable_registration_without_verification" to "True" # note: maybe not comming soon..
+
+For disable ... well you know, set "enable_registration" to "False"
+
+### create user via cli
+1. Import .env or set $DOMAIN manually
+2. Set env $USERNAME and $USERPASS oder replace it directly
+```
+source .env
+docker exec -it matrix_app_1 register_new_matrix_user -u $USERNAME -p $USERPASS -a -c /data/homeserver.yaml $DOMAIN
+```
+
+## todo
+- setup script to auto edits
+ - db in homeserver.yml
+ - domain in config.json (element)
+
+## sources
+- https://docs.docker.com/reference/cli/docker/container/run/
+- https://adfinis.com/en/blog/how-to-set-up-your-own-matrix-org-homeserver-with-federation/
+- https://zerowidthjoiner.net/2020/03/20/setting-up-matrix-and-riot-with-docker
+- https://linuxhandbook.com/install-matrix-synapse-docker/
+- https://cyberhost.uk/element-matrix-setup/
+- https://raw.githubusercontent.com/vector-im/element-web/v1.5.13/config.sample.json
+- https://github.com/element-hq/element-web/blob/develop/docs/jitsi.md
+
+[^jitsi]: https://github.com/element-hq/element-web/blob/develop/docs/jitsi.md
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..d39af0e
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,84 @@
+services:
+ ## matrix server
+ synapse:
+ image: matrixdotorg/synapse:${SYNAPSETAG:-latest}
+ restart: unless-stopped
+ env_file:
+ - .env
+ depends_on:
+ - db
+ ports:
+ - 8008:8008
+ - 91:91
+ - 92:92
+ deploy:
+ replicas: 1
+ placement:
+ max_replicas_per_node: 1
+ update_config:
+ parallelism: 1
+ delay: 10s
+ volumes:
+ - ${BASEDIR:-.}/files/synapse:/data
+ networks:
+ - backend
+ - matrixnet
+
+ ## server db (optional; default is sqlite3, if not use remove db from depends_on)
+ db:
+ image: postgres:${POSTGRESSTAG:-11} # recommend to set fix version ! db major release can have breaking changes
+ restart: unless-stopped
+ env_file:
+ - .env
+ volumes:
+ - ${BASEDIR:-.}/files/postgresdata:/var/lib/postgresql/data
+ environment:
+ - POSTGRES_DB=${DBNAME:-synapse}
+ - POSTGRES_USER=${DBUSER:-synapse}
+ - POSTGRES_PASSWORD=${DBPASS:-synapse}
+ - POSTGRES_INITDB_ARGS=--lc-collate C --lc-ctype C --encoding UTF8
+ networks:
+ - matrixnet
+
+ ## server (user / channel) managment (optional)
+ # synapse-admin:
+ # image: awesometechnologies/synapse-admin:${SYNAPSEADMINTAG:-latest}
+ # restart: unless-stopped
+ # env_file:
+ # - .env
+ # depends_on:
+ # - synapse
+ # ports:
+ # - 8888:80
+ # networks:
+ # - backend
+ # - matrixnet
+
+ ## webfrontend (optional)
+ element:
+ image: vectorim/element-web:${ELEMENTTAG:-latest}
+ restart: unless-stopped
+ env_file:
+ - .env
+ depends_on:
+ - synapse
+ volumes:
+ - ${BASEDIR:-.}/files/element-config.json:/app/config.json
+ ports:
+ - 8080:80
+ - 8443:8443
+ deploy:
+ replicas: 1
+ placement:
+ max_replicas_per_node: 1
+ update_config:
+ parallelism: 1
+ delay: 10s
+ networks:
+ - backend
+
+networks:
+ backend:
+ name: ${INTRANET:-backend}
+ # external: true
+ matrixnet:
\ No newline at end of file
diff --git a/env.sample b/env.sample
new file mode 100644
index 0000000..1caa24b
--- /dev/null
+++ b/env.sample
@@ -0,0 +1,16 @@
+#BASEDIR=
+#INTRANET=maxtrix-network
+
+# versionen
+#SYNAPSETAG=
+#POSTGRESSTAG=
+#SYNAPSEADMINTAG=
+#ELEMENTTAG=
+
+# db settings
+DBNAME=synapse
+DBUSER=synapse
+DBPASS=STRONGPASSWORD
+
+# application settings
+DOMAIN=
\ No newline at end of file
diff --git a/files/element-config.json b/files/element-config.json
new file mode 100644
index 0000000..0a9aee1
--- /dev/null
+++ b/files/element-config.json
@@ -0,0 +1,56 @@
+{
+ "default_server_config": {
+ "m.homeserver": {
+ "base_url": "https://matrix-client.matrix.org",
+ "server_name": "matrix.org"
+ },
+ "m.identity_server": {
+ "base_url": "https://vector.im"
+ }
+ },
+ "disable_custom_urls": false,
+ "disable_guests": true,
+ "disable_login_language_selector": false,
+ "disable_3pid_login": false,
+ "brand": "Element",
+ "integrations_ui_url": "https://scalar.vector.im/",
+ "integrations_rest_url": "https://scalar.vector.im/api",
+ "integrations_widgets_urls": [
+ "https://scalar.vector.im/_matrix/integrations/v1",
+ "https://scalar.vector.im/api",
+ "https://scalar-staging.vector.im/_matrix/integrations/v1",
+ "https://scalar-staging.vector.im/api",
+ "https://scalar-staging.riot.im/scalar/api"
+ ],
+ "integrations_jitsi_widget_url": "https://scalar.vector.im/api/widgets/jitsi.html",
+ "bug_report_endpoint_url": "https://riot.im/bugreports/submit",
+ "defaultCountryCode": "DE",
+ "showLabsSettings": false,
+ "features": {
+ "feature_pinning": "labs",
+ "feature_custom_status": "labs",
+ "feature_custom_tags": "labs",
+ "feature_state_counters": "labs"
+ },
+ "default_federate": true,
+ "default_theme": "light",
+ "roomDirectory": {
+ "servers": [
+ "matrix.org"
+ ]
+ },
+ "welcomeUserId": "@riot-bot:matrix.org",
+ "piwik": {
+ "url": "https://piwik.riot.im/",
+ "whitelistedHSUrls": ["https://matrix.org"],
+ "whitelistedISUrls": ["https://vector.im", "https://matrix.org"],
+ "siteId": 1
+ },
+ "enable_presence_by_hs_url": {
+ "https://matrix.org": false,
+ "https://matrix-client.matrix.org": false
+ },
+ "settingDefaults": {
+ "breadcrumbs": true
+ }
+}