Skip to content

Commit 8462f72

Browse files
committed
Add some introductory docs for deploying the appservice.
1 parent 5948453 commit 8462f72

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

docs/appservice.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Mjolnir can be run as an appservice, allowing users you trust or on your homeserver to run their own Mjolnir without hosting anything themselves.
2+
This module is currently alpha quality and is subject to rapid changes,
3+
it is not recommended currently and support will be limited.
4+
5+
# Prerequisites
6+
7+
This guide assumes you will be using Docker and that you are able to provide a postgres database for Mjolnir to connect to in application service mode.
8+
9+
# Setup
10+
11+
1. Create a new Matrix room that will act as a policy list for who can use the appservice.
12+
FIXME: Currently required to be aliased.
13+
FIXME: Should really be created and managed by the admin room, but waiting for command refactor before doing that.
14+
15+
2. Decide on a spare local TCP port number to use that will listen for messages from the matrix homeserver. Take care to configure firewalls appropriately. This port will be notated as `$MATRIX_PORT` in the remaining instructions.
16+
17+
3. Create a config/config.appservice.yaml file that can be copied from the example in `src/appservice/config/config.example.yaml`. Your config file needs to be accessible to the docker container later on.
18+
19+
4. Generate the appservice registration file. This will be used by both the appservice and your homeserver.
20+
Here, you must specify the direct link the Matrix Homserver can use to access the appservice, including the Matrix port it will send messages through (if this bridge runs on the same machine you can use localhost as the $HOST name):
21+
22+
`docker run -rm -v /mjolnir/data/path:/data matrixdotorg/mjolnir appservice -r -u "http://$HOST:$MATRIX_PORT" -f /data/config/mjolnir-registration.yaml`
23+
24+
5. Invite the application service bot (specified in the registration) to the access control room you made earlier.
25+
26+
6. Start the application service `docker run -v /path/to/data/:/data/ matrixdotorg/mjolnir appservice -c /data/config/config.appservice.yaml -f /data/config/mjolnir-registration.yaml -p $MATRIX_PORT`
27+
28+
7. Copy the `mjolnir-registration.yaml` to your matrix homeserver and refer to it in `homeserver.yaml`.

src/appservice/AppService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export class MjolnirAppService {
3535
this.api = new Api(config.homeserver.url, mjolnirManager);
3636
}
3737

38-
public static async makeMjolnirAppService(config: IConfig, dataStore: DataStore) {
38+
public static async makeMjolnirAppService(config: IConfig, dataStore: DataStore, registrationFilePath: string) {
3939
const bridge = new Bridge({
4040
homeserverUrl: config.homeserver.url,
4141
domain: config.homeserver.domain,
42-
registration: "mjolnir-registration.yaml",
42+
registration: registrationFilePath,
4343
// We lazily initialize the controller to avoid null checks
4444
// It also allows us to combine constructor/initialize logic
4545
// to make the code base much simpler. A small hack to pay for an overall less hacky code base.
@@ -112,10 +112,10 @@ export class MjolnirAppService {
112112
callback(reg);
113113
}
114114

115-
public static async run(port: number, config: IConfig) {
115+
public static async run(port: number, config: IConfig, registrationFilePath: string) {
116116
const dataStore = new PgDataStore(config.db.connectionString);
117117
await dataStore.init();
118-
const service = await MjolnirAppService.makeMjolnirAppService(config, dataStore);
118+
const service = await MjolnirAppService.makeMjolnirAppService(config, dataStore, registrationFilePath);
119119
// Can't stress how important it is that listen happens last.
120120
await service.start(port);
121121
}

src/appservice/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const cli = new Cli({
1717
if (config === null) {
1818
throw new Error("Couldn't load config");
1919
}
20-
await MjolnirAppService.run(port, config);
20+
await MjolnirAppService.run(port, config, cli.getRegistrationFilePath());
2121
}
2222
});
2323

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
homeserver:
3+
# The Matrix server name, this will be the name of the server in your matrix id.
4+
domain: "localhost:9999"
5+
# The url for the appservice to call the client server API from.
6+
url: http://localhost:8081
7+
8+
# Database configuration for storing which Mjolnirs have been provisioned.
9+
db:
10+
engine: "postgres"
11+
connectionString: "postgres://mjolnir-tester:mjolnir-test@localhost:8083/mjolnir-test-db"
12+
13+
# A room you have created that scopes who can access the appservice.
14+
# See docs/access_control.md
15+
accessControlList: "#access-control-list:localhost:9999"
16+
17+
# This is a web api that the widget connects to in order to interact with the appservice.
18+
webAPI:
19+
port: 9001

test/appservice/utils/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function setupHarness(): Promise<MjolnirAppService> {
1616
await ensureAliasedRoomExists(utilityUser, config.accessControlList);
1717
const dataStore = new PgDataStore(config.db.connectionString);
1818
await dataStore.init();
19-
const appservice = await MjolnirAppService.makeMjolnirAppService(config, dataStore);
19+
const appservice = await MjolnirAppService.makeMjolnirAppService(config, dataStore, "mjolnir-registration.yaml");
2020
await appservice.start(9000);
2121
return appservice;
2222
}

0 commit comments

Comments
 (0)