Matrix Synapse custom homeserver deploy
In previous post Matrix server with self build Element-Web was described a procedure how to prepare Linux server with local docker images registry. Now we use prepared infrastructure to deploy Synapse server from custom docker image built from source.
Matrix is an open source project that publishes the Matrix open standard for secure, decentralized, real-time communication, and its Apache licensed reference implementations.
Synapse: Matrix homeserver implementation developed by the matrix.org core team written in Python 3/Twisted.
Get Synapse sources from github:
$ git clone https://github.com/matrix-org/synapse
Buildkit
Synapse docker image build using BuildKit: Build images with BuildKit
Download latest BuildKit release from github: BuildKit releases
Unpack release binary archive to ./bin local directory:
Start BuildKit service:
Add DOCKER_BUILDKIT
environment variable to user profile:
Build docker image:
userrepo@repo:~$ cd synapse
userrepo@repo:~/synapse$ docker build -f docker/Dockerfile .
[+] Building 164.5s (17/17) FINISHED
Check built image:
userrepo@repo:~/synapse$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 40ba633c40c9 2 minutes ago 344MB
python 3.9-slim 651ad4293c49 9 hours ago 125MB
Build image with (e.g. Jenkins) automation shell command for pipeline. Build with repo:5000/mysynapse:latest
tag:
date
cd /home/userrepo/synapse
export DOCKER_BUILDKIT=1
docker build -t repo:5000/mysynapse:latest -f docker/Dockerfile .
echo "Synapse build successful!"
Check built tagged image:
userrepo@repo:~/synapse$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
repo:5000/mysynapse latest 40ba633c40c9 10 minutes ago 344MB
Push image to local registry:
$ docker push repo:5000/mysynapse:latest
Ansible playbook
Get matrix ansible deploy scripts from github:
$ git clone https://github.com/spantaleev/matrix-docker-ansible-deploy
$ cd matrix-docker-ansible-deploy
Edit ansible synapse role script config:
$ vim ./roles/matrix-synapse/defaults/main.yml
matrix_synapse_enabled: true
matrix_synapse_container_image_self_build: true
matrix_synapse_container_image_self_build_repo: "ssh://repo/git-server/repos/synapse.git"
matrix_synapse_docker_image: "{{ matrix_synapse_docker_image_name_prefix }}mysynapse:{{ matrix_synapse_docker_image_tag }}"
matrix_synapse_docker_image_name_prefix: 'repo:5000/'
matrix_synapse_version: latest
Change remote host domain and IP in ansible inventory config file:
userrepo@repo:~/$ vim ./matrix-docker-ansible-deploy/inventory/hosts
Run ansible script locally to deploy matrix services on remote host:
$ cd ~/matrix-docker-ansible-deploy/
$ ansible-playbook -K -i inventory/hosts setup.yml --tags=setup-all,start
Ansible script will connect to remote server over SSH using ssh access key. Option -K
was added for request password to get sudo
privileges on remote host.
The script will run several docker containers. Connections to TURN server, Proxy and DB are shown on picture below:
Comments
Post a Comment