4 Bridge setup with Docker
Lasath Fernando edited this page 2020-04-16 01:47:30 -07:00

Requirements

  • Docker
  • A Matrix homeserver that supports application services (e.g. Synapse)

Setup

Docker images are hosted on dock.mau.dev

  1. Create a directory for the bridge and cd into it: mkdir mautrix-hangouts && cd mautrix-hangouts.
    N.B. The docker image will chown its /data directory to UID 1337. The commands below mount the working directory as /data, so make sure you always run them in the correct directory.
  2. Pull the docker image with docker pull dock.mau.dev/tulir/mautrix-hangouts:latest.
  3. Run the container for the first time, so it can create a config file for you:
    docker run --rm -v `pwd`:/data:z dock.mau.dev/tulir/mautrix-hangouts:latest
    
  4. Update the config to your liking. Don't forget to change the address and domain to match those of your server. Don't change the database URI if using SQLite.
  5. Generate the appservice registration by running the container again, same command as above.
  6. Add the path to the registration file to your Synapse's homeserver.yaml under the app_service_config_files section: app_service_config_files: ["/path/to/your/mautrix-hangouts/registration.yaml"]
  7. Restart Synapse to apply changes.
  8. Run the bridge:
    docker run --restart unless-stopped -p 29320:29320 -v `pwd`:/data:z dock.mau.dev/tulir/mautrix-hangouts:latest
    

Upgrading

  1. Pull the new version (setup step 1)
  2. Start the new version (setup step 7)

Docker compose

Create a directory as in step #0 and create docker-compose.yml that contains something like this:

version: "3.7"

services:
  mautrix-hangouts:
    container_name: mautrix-hangouts
    image: dock.mau.dev/tulir/mautrix-hangouts:latest
    restart: unless-stopped
    volumes:
    - .:/data

Use docker-compose up -d to start, docker-compose stop to stop and docker-compose pull to update.

Troubleshooting

Invalid user localpart for this application

After following the Docker instructions and logging in, the bot wasn't creating puppet users as expected and a lot of errors like these showed up a lot in the logs:

hangouts-bridge_1         | [2020-04-12 23:23:17,125] [ERROR@mau.portal.UgyaXTN22ZQSsupiHPR4AaABAQ-106066428763677257525] Failed to create portal
hangouts-bridge_1         | Traceback (most recent call last):
hangouts-bridge_1         |   File "/usr/lib/python3.8/site-packages/mautrix/appservice/api/intent.py", line 392, in ensure_registered
hangouts-bridge_1         |     await self._register()
hangouts-bridge_1         |   File "/usr/lib/python3.8/site-packages/mautrix/api/http.py", line 205, in request
hangouts-bridge_1         |     return await self._send(method, endpoint, content, query_params, headers or {})
hangouts-bridge_1         |   File "/usr/lib/python3.8/site-packages/mautrix/api/http.py", line 144, in _send
hangouts-bridge_1         |     raise make_request_error(http_status=response.status,
hangouts-bridge_1         | mautrix.errors.request.MExclusive: Invalid user localpart for this application service.
hangouts-bridge_1         | 
hangouts-bridge_1         | During handling of the above exception, another exception occurred:
hangouts-bridge_1         | 
hangouts-bridge_1         | Traceback (most recent call last):
hangouts-bridge_1         |   File "/opt/mautrix-hangouts/mautrix_hangouts/portal.py", line 229, in create_matrix_room
hangouts-bridge_1         |     return await self._create_matrix_room(source, info)
hangouts-bridge_1         |   File "/opt/mautrix-hangouts/mautrix_hangouts/portal.py", line 248, in _create_matrix_room
hangouts-bridge_1         |     await puppet.update_info(source=source, info=info.get_user(self.other_user_id))
hangouts-bridge_1         |   File "/opt/mautrix-hangouts/mautrix_hangouts/puppet.py", line 152, in update_info
hangouts-bridge_1         |     changed = await self._update_name(info)
hangouts-bridge_1         |   File "/opt/mautrix-hangouts/mautrix_hangouts/puppet.py", line 168, in _update_name
hangouts-bridge_1         |     await self.default_mxid_intent.set_displayname(self.name)
hangouts-bridge_1         |   File "/usr/lib/python3.8/site-packages/mautrix/appservice/api/intent.py", line 74, in wrapper
hangouts-bridge_1         |     await __self.ensure_registered()
hangouts-bridge_1         |   File "/usr/lib/python3.8/site-packages/mautrix/appservice/api/intent.py", line 395, in ensure_registered
hangouts-bridge_1         |     raise IntentError(f"Failed to register {self.mxid}", e)
hangouts-bridge_1         | mautrix.errors.base.IntentError: ('Failed to register @hangouts_108154547180811754848:lasath.org', MExclusive('Invalid user localpart for this application service.'))

The workaround that fixed this was:

  1. Re-run the alembic command to upgrade the database. (This is the command that's in docker-run.sh)
    alembic is available in the docker image. You can run it like so:
docker-compose exec hangouts-bridge alembic -x config=/data/config.yaml upgrade head

Because I used a docker-compose.yml file to specify all my docker args, and hangouts-bridge was the entry for this. If you used plain docker (as described above), your command will probably look more like:

docker exec -it -v `pwd`:/data:z dock.mau.dev/tulir/mautrix-hangouts:latest
  1. Re-run the registration command (step 4) above
  2. Restart both synapse and mautrix-hangouts