Skip to content

Commit

Permalink
Synapse hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinyanakiev committed Apr 23, 2021
1 parent 417a005 commit 43a2423
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ IPFS_ENDPOINT=http://ct_ipfs_server:5001
IPFS_CLIENT_ENDPOINT=http://localhost:8080/ipfs
IPFS_MAX_FILE_SIZE=1048576

COMPOSE_PROJECT_NAME=cherrytwist-server-dev
COMPOSE_PROJECT_NAME=cherrytwist-server-dev

SYNAPSE_SERVER_NAME=cherrytwist.matrix.host
SYNAPSE_SHARED_SECRET=n#P.uIl8IDOYPR-fiLzDoFw9ZPvTIlYg7*F9*~eaDZFK#;.KRg
SYNAPSE_ENABLE_REGISTRATION=true
SYNAPSE_NO_TLS=true
45 changes: 45 additions & 0 deletions .scripts/bootstrap_synapse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

function read_var() {
if [ -z "$1" ]; then
echo "environment variable name is required"
return 1
fi

local ENV_FILE='.env.docker'
if [ ! -z "$2" ]; then
ENV_FILE="$2"
fi

grep $1 $ENV_FILE | grep -v -P '^\s*#' | cut -d '=' -f 2-
}

function set_yaml_value()
{
yaml_file=$1
key=$2
new_value=$3

sed -r "s/^(\s*${key}\s*:\s*).*/\1${new_value}/" -i "$yaml_file"
}

function enable_registration()
{
pattern="enable_registration: false"
echo $pattern
replacement="enable_registration: true"
echo $replacement
sed -i "s/${pattern}/${replacement}/g" "/var/docker_data/matrix/homeserver.yaml"
sed -i '/enable_registration:/s/^#//g' "/var/docker_data/matrix/homeserver.yaml"
}

docker run -it --rm \
--mount type=volume,src=synapse-data,dst=/data \
-e SYNAPSE_SERVER_NAME=$(read_var SYNAPSE_SERVER_NAME) \
-e SYNAPSE_REPORT_STATS=yes \
matrixdotorg/synapse:latest generate

cp -a /var/lib/docker/volumes/synapse-data/_data/. /var/docker_data/matrix

set_yaml_value "/var/docker_data/matrix/homeserver.yaml" "registration_shared_secret" $(read_var SYNAPSE_SHARED_SECRET)
enable_registration
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,19 @@ services:
ports:
- 3003:3002
command: sh -c "/wait && /create_db.sh && npm run start:prod"

ct_synapse_server:
container_name: ct_synapse_server
image: matrixdotorg/synapse
restart: always
environment:
- SYNAPSE_NO_TLS
- SYNAPSE_SERVER_NAME
- SYNAPSE_ENABLE_REGISTRATION
- SYNAPSE_REGISTRATION_SHARED_SECRET
networks:
- ct_server_dev
ports:
- 8008:8008
volumes:
- /var/docker_data/matrix:/data
7 changes: 7 additions & 0 deletions docs/Running.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ To simplify setting up the Server development environment, a pre-configured dock

- The docker compose script puts the server listening on port 4001 - to avoid conflict with the default port that is used by local development.
- The server will be empty after initially being created. To populate the Server with some sample data please use the [Cherrytwist Populator](http://github.com/cherrytwist/Populator) tool which allows easy population from a local file. Please remember to specify the correct port to connect to!
- In order to use matrix synapse server, run from the root folder:

```bash
sudo bash ./.scripts/bootstrap_synapse.sh
```

It will use the SYNAPSE_XXX from env.docker, create a configuration in /var/lib/docker/volumes/synapse-data/\_data/, copy them to /var/docker_data/matrix and then map the latter to a volume used in docker-compose.

0 comments on commit 43a2423

Please sign in to comment.