Skip to content

Commit 48461df

Browse files
committed
docs: add default Spanner/MySQL config guide and one-shot MySQL compose
Add a short How-To page describing the out-of-the-box configuration for the standard MySQL and Spanner builds, the minimum required settings, and where the full reference lives. Add a one-shot MySQL docker compose recipe (DB + server, migrations applied automatically, sync-1.5 service + node bootstrapped) so the stack comes up ready to serve. The primary recipe builds the image from source (works from a checkout with no published tag); an alternative uses a published image, noting that images are tagged by commit SHA with no `latest` tag, so SYNCSERVER_VERSION must be pinned. Register the new page in the book summary and How-To index. Closes STOR-477
1 parent 5a1f813 commit 48461df

4 files changed

Lines changed: 210 additions & 1 deletion

File tree

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
[Mozilla Accounts Server - FxA](mozilla-accounts.md)
3838

3939
- [How To Guides](how-to/index.md)
40+
- [Default Configuration for Spanner & MySQL Builds](how-to/default-config.md)
4041
- [Run Your Own Sync-1.5 Server with Docker](how-to/how-to-run-with-docker.md)
4142
- [Run Your Own Sync-1.5 Server (legacy)](how-to/how-to-run-sync-server.md)
4243
- [Configure Sync Server for TLS (legacy)](how-to/how-to-config-tls.md)

docs/src/how-to/default-config.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Default Configuration for Spanner & MySQL Builds
2+
3+
This page describes the out-of-the-box configuration needed to run the two
4+
standard `syncstorage-rs` builds:
5+
6+
- **MySQL build** — the default `cargo build` / `make run_mysql` target and the
7+
`syncstorage-rs-mysql` Docker image. Both Syncstorage and Tokenserver run
8+
against MySQL.
9+
- **Spanner build**`make run_spanner` and the `syncstorage-rs-spanner`
10+
Docker image. This mirrors production: Syncstorage runs against Google Cloud
11+
Spanner while Tokenserver runs against MySQL.
12+
13+
Annotated, copy-paste-ready templates live in the repo:
14+
15+
| Build | Template |
16+
| --- | --- |
17+
| MySQL | [`config/local.example.toml`](https://github.com/mozilla-services/syncstorage-rs/blob/master/config/local.example.toml) |
18+
| Spanner | [`config/local.example.spanner.toml`](https://github.com/mozilla-services/syncstorage-rs/blob/master/config/local.example.spanner.toml) |
19+
20+
Copy one to `config/local.toml` and edit the values marked `REQUIRED`:
21+
22+
```sh
23+
cp config/local.example.toml config/local.toml # MySQL
24+
# or
25+
cp config/local.example.spanner.toml config/local.toml # Spanner
26+
```
27+
28+
Every setting can also be supplied as an environment variable prefixed with
29+
`SYNC_` (nested keys use `__`). For example `syncstorage.database_url` becomes
30+
`SYNC_SYNCSTORAGE__DATABASE_URL`. Environment variables take precedence over the
31+
config file. The complete list of options and their defaults is in the
32+
[Application Configuration](../config.md) reference, and the source of truth is
33+
the doc-commented `Settings` structs in the `*-settings` crates.
34+
35+
## Minimum required settings
36+
37+
Most settings have sensible defaults. Regardless of backend you must supply:
38+
39+
| Setting | Why |
40+
| --- | --- |
41+
| [`master_secret`](../config.md#SYNC_MASTER_SECRET) | Derives the Hawk signing/token secrets. No default. |
42+
| [`syncstorage.database_url`](../config.md#SYNC_SYNCSTORAGE__DATABASE_URL) | No usable default; the server fails fast at startup if unset. |
43+
| [`tokenserver.database_url`](../config.md#SYNC_TOKENSERVER__DATABASE_URL) | Required when `tokenserver.enabled = true` (fails fast if unset). |
44+
45+
Backend-specific notes:
46+
47+
- **MySQL:** set `tokenserver.node_type = "mysql"`. Syncstorage MySQL schema
48+
migrations run automatically at startup; set
49+
`tokenserver.run_migrations = true` to apply the Tokenserver schema too.
50+
- **Spanner:** `syncstorage.database_url` must use the
51+
`spanner://projects/.../instances/.../databases/...` form — the `spanner://`
52+
scheme is what selects the Spanner backend. Leave `tokenserver.node_type` at
53+
its default (`"spanner"`). To run against the local emulator instead of GCP,
54+
set `syncstorage.spanner_emulator_host` (e.g. `localhost:9010`); for real
55+
Spanner, point `GOOGLE_APPLICATION_CREDENTIALS` at a service-account key.
56+
57+
## Run it out of the box with Docker
58+
59+
For a zero-to-running MySQL stack (database + server, schema applied
60+
automatically, ready to serve), see the
61+
[one-shot MySQL `docker compose`](how-to-run-with-docker.md#docker-compose-one-shot-with-mysql)
62+
recipe. It brings up MySQL and the server, runs migrations, and bootstraps the
63+
storage node so that `curl http://localhost:8000/__heartbeat__` succeeds with no
64+
further setup.
65+
66+
A Spanner stack cannot be fully zero-config: real Spanner requires GCP
67+
credentials, and the local emulator requires extra wiring (see
68+
`docker/docker-compose.spanner.yaml` and `make run_spanner`).

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

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Images are available for both
1010
and
1111
[PostgreSQL](https://github.com/mozilla-services/syncstorage-rs/pkgs/container/syncstorage-rs%2Fsyncstorage-rs-postgres)
1212
as the database. Differences in configuration or deployment steps will be
13-
noted.
13+
noted.
1414

1515
Tagged release builds are available on ghcr.io. To pin to a specific version,
1616
set `SYNCSERVER_VERSION` to the desired release tag (e.g., `SYNCSERVER_VERSION=v1.45.0`)
@@ -142,6 +142,145 @@ Next, start the service with `docker compose`:
142142
docker compose -f docker-compose.one-shot.yaml up -d
143143
```
144144

145+
## Docker Compose, One-Shot with MySQL
146+
147+
This recipe brings up everything needed for a working MySQL-backed server in a
148+
single command: a MySQL database for Syncstorage and one for Tokenserver, plus
149+
the server itself. Syncstorage applies its schema migrations automatically at
150+
startup, `SYNC_TOKENSERVER__RUN_MIGRATIONS` applies the Tokenserver schema, and
151+
`SYNC_TOKENSERVER__INIT_NODE_URL` bootstraps the `sync-1.5` service and storage
152+
node records — so the stack is ready to serve with no manual database setup.
153+
154+
### Option A: build from source (works from a checkout)
155+
156+
Run this from a clone of the repository; the build `context` is the repo root,
157+
so the MySQL build of the server is compiled locally and the recipe does not
158+
depend on any published image. Save the yaml below into a file, e.g.
159+
`docker-compose.one-shot.yaml`.
160+
161+
```yaml
162+
services:
163+
syncserver:
164+
build:
165+
context: .
166+
args:
167+
SYNCSTORAGE_DATABASE_BACKEND: mysql
168+
TOKENSERVER_DATABASE_BACKEND: mysql
169+
container_name: syncserver
170+
ports:
171+
- "8000:8000"
172+
environment:
173+
SYNC_HOST: "0.0.0.0"
174+
SYNC_PORT: "8000"
175+
SYNC_MASTER_SECRET: "${SYNC_MASTER_SECRET:-changeme_secret_key}"
176+
SYNC_SYNCSTORAGE__DATABASE_URL: "mysql://sync:sync@sync-db:3306/syncstorage"
177+
SYNC_TOKENSERVER__DATABASE_URL: "mysql://sync:sync@tokenserver-db:3306/tokenserver"
178+
SYNC_TOKENSERVER__ENABLED: "true"
179+
SYNC_TOKENSERVER__NODE_TYPE: "mysql"
180+
SYNC_TOKENSERVER__RUN_MIGRATIONS: "true"
181+
SYNC_TOKENSERVER__FXA_EMAIL_DOMAIN: "api.accounts.firefox.com"
182+
SYNC_TOKENSERVER__FXA_OAUTH_SERVER_URL: "https://oauth.accounts.firefox.com"
183+
SYNC_HUMAN_LOGS: "${SYNC_HUMAN_LOGS:-false}"
184+
RUST_LOG: "${RUST_LOG:-info}"
185+
SYNC_TOKENSERVER__INIT_NODE_URL: "${SYNC_TOKENSERVER__INIT_NODE_URL:-http://localhost:${SYNC_PORT:-8000}}"
186+
depends_on:
187+
sync-db:
188+
condition: service_healthy
189+
tokenserver-db:
190+
condition: service_healthy
191+
restart: unless-stopped
192+
healthcheck:
193+
test: ["CMD", "curl", "-f", "http://localhost:8000/__heartbeat__"]
194+
interval: 30s
195+
timeout: 10s
196+
retries: 3
197+
start_period: 60s
198+
199+
sync-db:
200+
image: docker.io/library/mysql:8.0
201+
container_name: syncserver-sync-db
202+
command: --explicit_defaults_for_timestamp
203+
environment:
204+
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
205+
MYSQL_DATABASE: syncstorage
206+
MYSQL_USER: sync
207+
MYSQL_PASSWORD: sync
208+
volumes:
209+
- sync_db_data:/var/lib/mysql
210+
healthcheck:
211+
test: ["CMD-SHELL", "mysqladmin -h 127.0.0.1 -usync -psync ping"]
212+
interval: 10s
213+
timeout: 5s
214+
retries: 5
215+
start_period: 30s
216+
restart: unless-stopped
217+
218+
tokenserver-db:
219+
image: docker.io/library/mysql:8.0
220+
container_name: syncserver-tokenserver-db
221+
command: --explicit_defaults_for_timestamp
222+
environment:
223+
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
224+
MYSQL_DATABASE: tokenserver
225+
MYSQL_USER: sync
226+
MYSQL_PASSWORD: sync
227+
volumes:
228+
- tokenserver_db_data:/var/lib/mysql
229+
healthcheck:
230+
test: ["CMD-SHELL", "mysqladmin -h 127.0.0.1 -usync -psync ping"]
231+
interval: 10s
232+
timeout: 5s
233+
retries: 5
234+
start_period: 30s
235+
restart: unless-stopped
236+
237+
volumes:
238+
sync_db_data:
239+
driver: local
240+
tokenserver_db_data:
241+
driver: local
242+
```
243+
244+
Next, build and start the service with `docker compose`:
245+
246+
```sh
247+
docker compose -f docker-compose.one-shot.yaml up -d --build
248+
```
249+
250+
Once the `syncserver` container reports healthy, confirm it is serving:
251+
252+
```sh
253+
curl http://localhost:8000/__heartbeat__
254+
```
255+
256+
### Option B: use a published image
257+
258+
Mozilla also publishes prebuilt images on ghcr.io. Note that these are
259+
currently tagged by commit SHA — there is **no `latest` or semver tag** — so
260+
you must pin `SYNCSERVER_VERSION` to a tag listed on the
261+
[`syncstorage-rs-mysql` packages page](https://github.com/mozilla-services/syncstorage-rs/pkgs/container/syncstorage-rs%2Fsyncstorage-rs-mysql).
262+
To use a published image, replace the `syncserver` service's `build:` block with
263+
an `image:` reference; the `sync-db`, `tokenserver-db`, and `volumes` sections
264+
are unchanged:
265+
266+
```yaml
267+
services:
268+
syncserver:
269+
image: ghcr.io/mozilla-services/syncstorage-rs/syncstorage-rs-mysql:${SYNCSERVER_VERSION:?set SYNCSERVER_VERSION to a published tag}
270+
platform: linux/amd64
271+
container_name: syncserver
272+
# ...the remaining syncserver settings are identical to Option A
273+
```
274+
275+
Then start it with the tag pinned (published images are `linux/amd64`):
276+
277+
```sh
278+
SYNCSERVER_VERSION=<published-tag> docker compose -f docker-compose.one-shot.yaml up -d
279+
```
280+
281+
> Set `SYNC_MASTER_SECRET` to your own value for anything beyond local
282+
> experimentation; the default above is a placeholder.
283+
145284
## Configuring Firefox (Desktop)
146285

147286
Firefox itself needs to be configured to use the self-hosted Sync server.

docs/src/how-to/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

5+
- [Default Configuration for Spanner & MySQL Builds](default-config.md)
56
- [Run Your Own Sync-1.5 Server with Docker](how-to-run-with-docker.md)
67
- [Run Your Own Sync-1.5 Server (legacy)](how-to-run-sync-server.md)
78
- [Configure Sync Server for TLS (legacy)](how-to-config-tls.md)

0 commit comments

Comments
 (0)