From a97467075de5294f2bd6abfde7236d9e6c5cb669 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 3 Nov 2021 16:15:54 +0100 Subject: [PATCH] Add documentation for synapse-s3-storage-provider --- doc/book/src/connect/apps.md | 109 +++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/doc/book/src/connect/apps.md b/doc/book/src/connect/apps.md index 6ccac409..7bb0fc7f 100644 --- a/doc/book/src/connect/apps.md +++ b/doc/book/src/connect/apps.md @@ -346,13 +346,114 @@ https://docs.joinmastodon.org/admin/config/#cdn ## Matrix -### synapse-s3-storage-provider +Matrix is a chat communication protocol. Its main stable server implementation, [Synapse](https://matrix-org.github.io/synapse/latest/), provides a module to store media on a S3 backend. Additionally, a server independent media store supporting S3 has been developped by the community, it has been made possible thanks to how the matrix API has been designed and will work with implementations like Conduit, Dendrite, etc. -https://github.com/matrix-org/synapse-s3-storage-provider +### synapse-s3-storage-provider (synapse only) -### matrix-media-repo +Supposing you have a working synapse installation, you can add the module with pip: -https://github.com/turt2live/matrix-media-repo +```bash + pip3 install --user git+https://github.com/matrix-org/synapse-s3-storage-provider.git +``` + +Now create a bucket and a key for your matrix instance (note your Key ID and Secret Key somewhere, they will be needed later): + +```bash +garage key new --name matrix-key +garage bucket create matrix +garage bucket allow matrix --read --write --key matrix-key +``` + +Then you must edit your server configuration (eg. `/etc/matrix-synapse/homeserver.yaml`) and add the `media_storage_providers` root key: + +```yaml +media_storage_providers: +- module: s3_storage_provider.S3StorageProviderBackend + store_local: True # do we want to store on S3 media created by our users? + store_remote: True # do we want to store on S3 media created + # by users of others servers federated to ours? + store_synchronous: True # do we want to wait that the file has been written before returning? + config: + bucket: matrix # the name of our bucket, we chose matrix earlier + region_name: garage # only "garage" is supported for the region field + endpoint_url: http://localhost:3900 # the path to the S3 endpoint + access_key_id: "GKxxx" # your Key ID + secret_access_key: "xxxx" # your Secret Key +``` + +Note that uploaded media will also be stored locally and this behavior can not be deactivated, it is even required for +some operations like resizing images. +In fact, your local filesysem is considered as a cache but without any automated way to garbage collect it. + +We can build our garbage collector with `s3_media_upload`, a tool provided with the module. +If you installed the module with the command provided before, you should be able to bring it in your path: + +``` +PATH=$HOME/.local/bin/:$PATH +command -v s3_media_upload +``` + +Now we can write a simple script (eg `~/.local/bin/matrix-cache-gc`): + +```bash +#!/bin/bash + +## CONFIGURATION ## +AWS_ACCESS_KEY_ID=GKxxx +AWS_SECRET_ACCESS_KEY=xxxx +S3_ENDPOINT=http://localhost:3900 +S3_BUCKET=matrix +MEDIA_STORE=/var/lib/matrix-synapse/media +PG_USER=matrix +PG_PASS=xxxx +PG_DB=synapse +PG_HOST=localhost +PG_PORT=5432 + +## CODE ## +PATH=$HOME/.local/bin/:$PATH +cat > database.yaml < matrix-org/synapse-s3-storage-provider](https://github.com/matrix-org/synapse-s3-storage-provider) + +### matrix-media-repo (server independent) + +*External link:* [matrix-media-repo Documentation > S3](https://docs.t2bot.io/matrix-media-repo/configuration/s3-datastore.html) ## Pixelfed