Skip to content

Commit de08b03

Browse files
committed
docs: add how-to on deploying with docker compose
1 parent 25c852a commit de08b03

5 files changed

Lines changed: 122 additions & 130 deletions

File tree

docs/src/SUMMARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
[Mozilla Accounts Server - FxA](mozilla-accounts.md)
3030

3131
- [How To Guides](how-to/index.md)
32-
- [Run Your Own FxA Server](how-to/how-to-run-fxa.md)
32+
- [Run Your Own Sync-1.5 Server with Docker](how-to/how-to-run-with-docker.md)
3333
- [Run Your Own Sync-1.5 Server (legacy)](how-to/how-to-run-sync-server.md)
3434
- [Configure Sync Server for TLS (legacy)](how-to/how-to-config-tls.md)
3535

3636
[Documentation and MdBook Notes](doc-notes.md)
3737
[Glossary of Terms](glossary.md)
3838
[Response Codes](response-codes.md)
39-
[Terms of Service](terms-of-service.md)
39+
[Terms of Service](terms-of-service.md)

docs/src/how-to-run-with-docker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Run Your Own Sync-1.5 Server with Docker

docs/src/how-to/how-to-run-fxa.md

Lines changed: 0 additions & 126 deletions
This file was deleted.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Use Docker to Deploy Your Own Sync Server
2+
3+
Mozilla publishes Docker images of its
4+
[`syncstorage-rs`](https://github.com/mozilla-services/syncstorage-rs) builds
5+
on ghcr.io. This guide provides a simple `docker compose` setup that can act as
6+
a starting point to self-host Sync.
7+
8+
Images are available for both
9+
[MySQL](https://github.com/mozilla-services/syncstorage-rs/pkgs/container/syncstorage-rs%2Fsyncstorage-rs-mysql)
10+
and
11+
[PostgreSQL](https://github.com/mozilla-services/syncstorage-rs/pkgs/container/syncstorage-rs%2Fsyncstorage-rs-postgres)
12+
as the database. The sample code will focus on MySQL. Differences in
13+
configuration or deployment steps will be noted.
14+
15+
> **Note:** At the time of writing, there are no tagged release builds
16+
> available on ghcr.io. This guide will use a build from the main development
17+
> branch.
18+
19+
## Prerequisites and Presumptions
20+
- The reader has a MySQL or PostgreSQL database up and running.
21+
- The reader is familiar with the command line interface and `docker`.
22+
- The reader is going to use [Mozilla accounts](https://accounts.firefox.com/)
23+
for authentication and authorization.
24+
- The service will be deployed at http://localhost:8000/.
25+
26+
## Docker Compose
27+
28+
Save the yaml below into a file, e.g. `docker-compose.yaml`.
29+
30+
```yaml
31+
services:
32+
syncserver:
33+
image: ghcr.io/mozilla-services/syncstorage-rs/syncstorage-rs-mysql:b16ef5064b
34+
platform: linux/amd64
35+
container_name: syncserver
36+
ports:
37+
- "8000:8000"
38+
environment:
39+
SYNC_HOST: "0.0.0.0"
40+
SYNC_PORT: "8000"
41+
SYNC_MASTER_SECRET: "${SYNC_MASTER_SECRET}"
42+
SYNC_SYNCSTORAGE__DATABASE_URL: "${SYNC_SYNCSTORAGE__DATABASE_URL}"
43+
SYNC_TOKENSERVER__DATABASE_URL: "${SYNC_TOKENSERVER__DATABASE_URL}"
44+
SYNC_TOKENSERVER__ENABLED: "true"
45+
SYNC_TOKENSERVER__RUN_MIGRATIONS: "true"
46+
SYNC_TOKENSERVER__FXA_EMAIL_DOMAIN: "api.accounts.firefox.com"
47+
SYNC_TOKENSERVER__FXA_OAUTH_SERVER_URL: "https://oauth.accounts.firefox.com"
48+
restart: unless-stopped
49+
healthcheck:
50+
test: ["CMD", "curl", "-f", "http://localhost:8000/__heartbeat__"]
51+
interval: 30s
52+
timeout: 10s
53+
retries: 3
54+
start_period: 60s
55+
```
56+
57+
Note that multiple values will be read from the environment:
58+
- `SYNC_MASTER_SECRET`: a secret used in cryptographic operationsk a passphrase or random character string, e.g. `use_your_own_secret_4d3d3d3d`
59+
- `SYNC_SYNCSTORAGE__DATABASE_URL`: database URL for syncstorage, e.g. `mysql://sync:test@example.io/syncstorage` or `postgres://testo:@localhost/syncdb`
60+
- `SYNC_TOKENSERVER__DATABASE_URL`: database URL for tokenserver, e.g. `mysql://sync:test@example.io/tokenserver` or `postgres://testo:@localhost/syncdb`
61+
62+
The values can be directly written into the yaml as well.
63+
64+
Next, start the service with `docker compose`:
65+
66+
```sh
67+
SYNC_MASTER_SECRET=use_your_own_secret_4d3d3d3d \
68+
SYNC_SYNCSTORAGE__DATABASE_URL="mysql://sync:test@example.io/syncstorage" \
69+
SYNC_TOKENSERVER__DATABASE_URL="mysql://sync:test@example.io/tokenserver" \
70+
docker compose -f docker-compose.yaml up -d
71+
```
72+
73+
### Database Bootstrapping
74+
75+
After starting the service on a clean, uninitialized database, some bootstrapping records need to be inserted.
76+
77+
For MySQL, run
78+
```sql
79+
INSERT INTO tokenserver.services (service, pattern) VALUES ('sync-1.5', '{node}/1.5/{uid}');
80+
81+
INSERT INTO tokenserver.nodes (service, node, available, current_load, capacity, downed, backoff)
82+
VALUES (
83+
(SELECT id FROM services WHERE service = 'sync-1.5'),
84+
'http://localhost:8000',
85+
1, 0, 1000, 0, 0
86+
);
87+
```
88+
89+
For PostgreSQL, run
90+
```sql
91+
INSERT INTO nodes (service, node, available, current_load, capacity, downed, backoff)
92+
VALUES (
93+
(SELECT id FROM services WHERE service = 'sync-1.5'),
94+
'http://localhost:8000',
95+
1, 0, 1000, 0, 0
96+
);
97+
```
98+
99+
Note that `http://localhost:8000` above needs to be replaced with the actual
100+
service URL.
101+
102+
Restart the service with
103+
```sh
104+
docker compose -f docker-compose.yaml restart
105+
```
106+
107+
## Configuring Firefox
108+
109+
Firefox itself needs to be configured to use the self-hosted Sync server.
110+
111+
1. Go to `about:config` in Firefox.
112+
1. Find the `identity.sync.tokenserver.uri` configuration.
113+
1. Change the value to `http://localhost:8000/1.0/sync/1.5`.
114+
1. Restart Firefox.
115+
116+
Firefox should be using the self-hosted Sync server at this point. That can be
117+
verified by checking the logs in `about:sync-log`.

docs/src/how-to/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
Collection of How To guides for various Sync-related operations.
44

5-
- [Run Your Own FxA Server](how-to-run-fxa.md)
5+
- [Run Your Own Sync-1.5 Server with Docker](how-to-run-with-docker.md)
66
- [Run Your Own Sync-1.5 Server (legacy)](how-to-run-sync-server.md)
7-
- [Configure Sync Server for TLS (legacy)](how-to-config-tls.md)
7+
- [Configure Sync Server for TLS (legacy)](how-to-config-tls.md)

0 commit comments

Comments
 (0)