Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve doc for docker installations #305

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/305.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add some documentation about PostgreSQL, for installing with docker, fix typos
12 changes: 11 additions & 1 deletion docs/datastores.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ Datastores
==========

Version 1.0+ supports using PostgreSQL as a storage backend instead of the
deprecated NeDB storage backend.
deprecated NeDB storage backend.
The required version of PostgreSQL is at least 9.5, but we recommend using the lastest stable version
available to you. Follow the installation instructions on the [official website](https://www.postgresql.org/download/)
or pull a [docker container](https://hub.docker.com/_/postgres).

Using PostgreSQL
----------------
Expand All @@ -28,6 +31,13 @@ db:

Ensure that `dbdir` is not included in the config.

Note: depending on your environment, the default PostgreSQL configuration might be set up such that it can be
reached only from localhost. Make sure it is reachable from your bridge installation. If necessary, set up
[`listen_addresses`](https://www.postgresql.org/docs/current/runtime-config-connection.html) and
[authentication](https://www.postgresql.org/docs/current/auth-pg-hba-conf.html) for your needs.

Remember to choose conservative options to ensure security of your database!

NeDB End-of-life
--------

Expand Down
15 changes: 12 additions & 3 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ the `config.sample.yaml` file.

These instructions assume you are using Synapse 1.4.0+. They should
work for older releases and other homeservers, but configuration may vary.
The bridge also requires a database, for more information see [datastores](datastores.md).

### From source

Expand Down Expand Up @@ -59,6 +60,9 @@ ever stuck, you can post a question in the
3. Create a `config.yaml` file for global configuration. There is a sample
one to begin with in `config/config.sample.yaml`. You should copy and
edit as appropriate. The required and optional values are flagged in the config.

If using docker, put this file in a new `config` directory which we will later
mount to the container.

4. See [datastores](datastores.md) on how to setup a database with the bridge.

Expand All @@ -72,16 +76,21 @@ ever stuck, you can post a question in the
or with docker:

```sh
$ docker run -v /path/to/config/:/config/ matrixdotorg/matrix-appservice-slack \
-r -c /config/config.yaml -u "http://$HOST:$MATRIX_PORT" -f /config/slack.yaml
$ docker run --network=host -v /path/to/config/:/config/ matrixdotorg/matrix-appservice-slack \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about opening up the docker image to the hosts' network. I think I would rather suggest creating a seperate postgres contaienr and using --link?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, and I note and explain this later. But afaik the communication also needs to be able to reach the homeserver (which might be in another container, host, or other) and vice versa. I do not know of a stable way to route this, except outgoing via domain. Can you reserve/bind an IP to a container?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have continued experimenting and created this docker-compose.yaml for setups running the bridge with docker, but postgres and homeserver natively.
It works for me right now, except for receiving messages from slack (however when i call the webhook url manually, it shows up in log).
This configuration can be started using docker-compose up -d.

version: "2.4" # version 2 is needed to support setting gateway

services:

  slack:
    container_name: appservice-slack
    image: matrixdotorg/matrix-appservice-slack
    restart: always
    volumes:
      - "~synapse/bridges/slack/:/config/" # mount your config folder (where you keep config.yaml)
    ports:
      - "127.0.0.1:5858:5858" # must be reachable from homeserver, so variate this accordingly
      - "9898:9898" # must be reachable from the internet. remember to open your firewall
    networks:
      default:
        ipv4_address: 172.19.0.2 # bind to this ip to allow precise psql config and firewalling

# this network setup is for dockered appservice + native homeserver and db.
# if you docker these or other matrix services, you should consider joining them on the same virtual network.
networks:
  default:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: "172.19.0.0/16"
          gateway: 172.19.0.1
# note the absence of a dash on the gateway line
# https://github.com/docker/compose/issues/4456

In addition to this, postgres must be configured to listen and allow connections from docker.
edit postgresql.conf:

listen_addresses = 'localhost,172.19.0.1' # include docker slack: this is the gateway IP from docker-compose.yaml
# also check the configured port to use in config.yaml connectionString

append to pg_hba.conf:

# allow password authenticated connections from docker: this is the subnet from docker-compose.yaml
host    all             all             172.19.0.1/16           md5

Notable changes in appservice-slack config.yaml:

homeserver:
  url: http://172.19.0.1:8008 # can also use the public facing IP and port, e.g. https://homeserver.domain:8448
db:
# connectionString: "postgresql://user:password@gateway:port/slack_bridge?sslmode=require" # A postgres connection string
# for example:
  connectionString: "postgresql://slackbridge_user:password@172.19.0.1:5433/slack_bridge?sslmode=require" # A postgres connection string

-r -c /config/config.yaml -u "http://$HOST:$MATRIX_PORT" -f /config/slack-registration.yaml
```

6. Start the actual application service:

`$ npm start -c config.yaml -p $MATRIX_PORT`
or with docker:

`$ docker run -v /path/to/config/:/config/ matrixdotorg/matrix-appservice-slack`
`$ docker run --network=host -d -v /path/to/config/:/config/ matrixdotorg/matrix-appservice-slack`

(Note: `--network=host` will expose the container directly to the host's network, i.e. you will be able to use
localhost just as if you're running the node app. If you want to use the default network bridge mode,
you will have to configure the config files, port forwarding, firewalls and your database server to
traverse the network bridge.)

7. Copy the newly-generated `slack-registration.yaml` file to your Matrix
homeserver. Add the registration file to your homeserver config (default
Expand Down
2 changes: 1 addition & 1 deletion src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ export class Main {
teamId = await this.clientFactory.upsertTeamByToken(opts.slack_bot_token);
log.info(`Found ${teamId} for token`);
} catch (ex) {
log.error("Failed to action link because the token couldn't used:", ex);
log.error("Failed to action link because the token couldn't be used:", ex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let you off, but this should have been a seperate PR because it's not really relevant to the context :p

throw Error("Token did not work, unable to get team");
}
}
Expand Down