From 3323dd8a38cbd4fd0b7451d8a9830a83de25e2c7 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 15 Jan 2025 21:24:08 +0100 Subject: [PATCH] Add base containers --- .gitignore | 1 + README.md | 17 ++++++ docker-compose.yml | 65 +++++++++++++++++++++ docker/dex/dex.config.yaml | 26 +++++++++ docker/element/config.json | 49 ++++++++++++++++ docker/synapse/delayed_accounts_creation.sh | 2 + docker/synapse/homeserver.yaml | 35 +++++++++++ docker/synapse/localhost.log.config | 39 +++++++++++++ docker/synapse/localhost.signing.key | 1 + 9 files changed, 235 insertions(+) create mode 100644 .gitignore create mode 100644 docker-compose.yml create mode 100644 docker/dex/dex.config.yaml create mode 100644 docker/element/config.json create mode 100755 docker/synapse/delayed_accounts_creation.sh create mode 100644 docker/synapse/homeserver.yaml create mode 100644 docker/synapse/localhost.log.config create mode 100644 docker/synapse/localhost.signing.key diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5d252d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +storage \ No newline at end of file diff --git a/README.md b/README.md index 7ccdde4..66e8d83 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ # Matrix Gateway WIP project + + +## Setup dev environment +``` +mkdir -p storage/postgres storage/synapse +docker compose up +``` + +URLs: +* Element: http://localhost:8080/ +* Synapse: http://localhost:8448/ +* OpenID configuration: http://127.0.0.1:9001/dex/.well-known/openid-configuration + +Auto-created Matrix accounts: + +* `admin1` : `admin1` +* `user1` : `user1` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..311780d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,65 @@ +# This compose file is compatible with Compose itself, it might need some +# adjustments to run properly with stack. + +version: "3" + +services: + synapse: + image: docker.io/matrixdotorg/synapse:latest + user: "1000" + # Since synapse does not retry to connect to the database, restart upon + # failure + restart: unless-stopped + entrypoint: /bin/bash + command: > + -c "nohup bash -c 'sleep 10; /config/delayed_accounts_creation.sh' \& + ./start.py" + + # See the readme for a full documentation of the environment settings + # NOTE: You must edit homeserver.yaml to use postgres, it defaults to sqlite + environment: + - SYNAPSE_CONFIG_PATH=/config/homeserver.yaml + volumes: + # You may either store all the files in a local folder + - ./storage/synapse:/data + - ./docker/synapse:/config:ro + # .. or you may split this between different storage points + # - ./files:/data + # - /path/to/ssd:/data/uploads + # - /path/to/large_hdd:/data/media + depends_on: + - db + # In order to expose Synapse, remove one of the following, you might for + # instance expose the TLS port directly: + ports: + - 8448:8448/tcp + + db: + image: docker.io/postgres:12-alpine + user: "1000" + environment: + - POSTGRES_USER=synapse + - POSTGRES_PASSWORD=changeme + # ensure the database gets created correctly + # https://element-hq.github.io/synapse/latest/postgres.html#set-up-database + - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C + volumes: + # You may store the database tables in a local folder.. + - ./storage/postgres:/var/lib/postgresql/data + # .. or store them on some high performance storage for better results + # - /path/to/ssd/storage:/var/lib/postgresql/data + + element: + image: docker.io/vectorim/element-web + ports: + - 8080:80/tcp + volumes: + - ./docker/element/config.json:/app/config.json:ro + + oidc: + image: dexidp/dex + ports: + - 9001:9001 + volumes: + - ./docker/dex:/conf:ro + command: ["dex", "serve", "/conf/dex.config.yaml"] diff --git a/docker/dex/dex.config.yaml b/docker/dex/dex.config.yaml new file mode 100644 index 0000000..dbbdb8c --- /dev/null +++ b/docker/dex/dex.config.yaml @@ -0,0 +1,26 @@ +issuer: http://127.0.0.1:9001/dex + +storage: + type: memory + +web: + http: 0.0.0.0:9001 + +oauth2: + # Automate some clicking + # Note: this might actually make some tests pass that otherwise wouldn't. + skipApprovalScreen: false + +connectors: + # Note: this might actually make some tests pass that otherwise wouldn't. + - type: mockCallback + id: mock + name: Example + +# Basic OP test suite requires two clients. +staticClients: + - id: foo + secret: bar + redirectURIs: + - http://localhost:3000/oidc_cb + name: Project diff --git a/docker/element/config.json b/docker/element/config.json new file mode 100644 index 0000000..4f12c6c --- /dev/null +++ b/docker/element/config.json @@ -0,0 +1,49 @@ +{ + "default_server_config": { + "m.homeserver": { + "base_url": "http://localhost:8448", + "server_name": "devserver" + }, + "m.identity_server": { + "base_url": "https://vector.im" + } + }, + "disable_custom_urls": false, + "disable_guests": false, + "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" + ], + "default_country_code": "GB", + "show_labs_settings": false, + "features": {}, + "default_federate": true, + "default_theme": "light", + "room_directory": { + "servers": ["matrix.org"] + }, + "enable_presence_by_hs_url": { + "https://matrix.org": false, + "https://matrix-client.matrix.org": false + }, + "setting_defaults": { + "breadcrumbs": true + }, + "jitsi": { + "preferred_domain": "meet.element.io" + }, + "element_call": { + "url": "https://call.element.io", + "participant_limit": 8, + "brand": "Element Call" + }, + "map_style_url": "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx" +} diff --git a/docker/synapse/delayed_accounts_creation.sh b/docker/synapse/delayed_accounts_creation.sh new file mode 100755 index 0000000..0b72cb9 --- /dev/null +++ b/docker/synapse/delayed_accounts_creation.sh @@ -0,0 +1,2 @@ +register_new_matrix_user -a --user admin1 --password admin1 --config /config/homeserver.yaml; +register_new_matrix_user --no-admin --user user1 --password user1 --config /config/homeserver.yaml; \ No newline at end of file diff --git a/docker/synapse/homeserver.yaml b/docker/synapse/homeserver.yaml new file mode 100644 index 0000000..fbe5822 --- /dev/null +++ b/docker/synapse/homeserver.yaml @@ -0,0 +1,35 @@ +# Configuration file for Synapse. +# +# This is a YAML file: see [1] for a quick introduction. Note in particular +# that *indentation is important*: all the elements of a list or dictionary +# should have the same indentation. +# +# [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html +# +# For more information on how to configure Synapse, including a complete accounting of +# each option, go to docs/usage/configuration/config_documentation.md or +# https://element-hq.github.io/synapse/latest/usage/configuration/config_documentation.html +server_name: "localhost" +pid_file: /data/homeserver.pid +listeners: + - port: 8448 + tls: false + type: http + x_forwarded: true + resources: + - names: [client, federation] + compress: false +database: + name: sqlite3 + args: + database: /data/homeserver.db +log_config: "/config/localhost.log.config" +media_store_path: /data/media_store +registration_shared_secret: "+oJd9zgvkQpXN-tt;95Wy,AFAdRH+FSTg&LxUXh6ZSvwMJHT;h" +report_stats: false +macaroon_secret_key: "d@ck1QkQLxlRg^aB#c#oZeII.oxOS6E2DX;YobP^Vm#iB5pQpd" +form_secret: "P.uleBJUYc6AM.UOrFF1q7OKH2N5T*Ae2;fGh46;vIHLIQ#JBP" +signing_key_path: "/config/localhost.signing.key" +trusted_key_servers: + - server_name: "matrix.org" +# vim:ft=yaml diff --git a/docker/synapse/localhost.log.config b/docker/synapse/localhost.log.config new file mode 100644 index 0000000..832f0fa --- /dev/null +++ b/docker/synapse/localhost.log.config @@ -0,0 +1,39 @@ +version: 1 + +formatters: + precise: + + format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s' + + +handlers: + + + console: + class: logging.StreamHandler + formatter: precise + +loggers: + # This is just here so we can leave `loggers` in the config regardless of whether + # we configure other loggers below (avoid empty yaml dict error). + _placeholder: + level: "INFO" + + + + synapse.storage.SQL: + # beware: increasing this to DEBUG will make synapse log sensitive + # information such as access tokens. + level: INFO + + + + +root: + level: INFO + + + handlers: [console] + + +disable_existing_loggers: false \ No newline at end of file diff --git a/docker/synapse/localhost.signing.key b/docker/synapse/localhost.signing.key new file mode 100644 index 0000000..9d67d45 --- /dev/null +++ b/docker/synapse/localhost.signing.key @@ -0,0 +1 @@ +ed25519 a_HEcG Q2iG1Yy5WTiZ/VIy+zHPyHCRUpqyE3qrVttGULrVQK4