Skip to content

Commit 646e516

Browse files
authored
docs: add one-shot docker compose yaml to how-to (#2025)
1 parent 11659d9 commit 646e516

1 file changed

Lines changed: 100 additions & 6 deletions

File tree

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

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,29 @@ Images are available for both
99
[MySQL](https://github.com/mozilla-services/syncstorage-rs/pkgs/container/syncstorage-rs%2Fsyncstorage-rs-mysql)
1010
and
1111
[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.
12+
as the database. Differences in configuration or deployment steps will be
13+
noted.
1414

1515
> **Note:** At the time of writing, there are no tagged release builds
1616
> available on ghcr.io. This guide will use a build from the main development
1717
> branch.
1818
1919
## Prerequisites and Presumptions
20-
- The reader has a MySQL or PostgreSQL database up and running.
2120
- The reader is familiar with the command line interface and `docker`.
2221
- The reader is going to use [Mozilla accounts](https://accounts.firefox.com/)
2322
for authentication and authorization.
2423
- The service will be deployed at http://localhost:8000/.
2524

26-
## Docker Compose
25+
## Docker Compose, Sync Services Only
2726

28-
Save the yaml below into a file, e.g. `docker-compose.yaml`.
27+
With a MySQL or PostgreSQL database is already up and running, save the yaml
28+
below into a file, e.g. `docker-compose.yaml`, and ensure the `image` field is
29+
using the correct MySQL or PostgreSQL build for the database.
2930

3031
```yaml
3132
services:
3233
syncserver:
33-
image: ghcr.io/mozilla-services/syncstorage-rs/syncstorage-rs-mysql:b16ef5064b
34+
image: ghcr.io/mozilla-services/syncstorage-rs/syncstorage-rs-mysql:${SYNCSERVER_VERSION:-b16ef5064b}
3435
platform: linux/amd64
3536
container_name: syncserver
3637
ports:
@@ -104,6 +105,99 @@ Restart the service with
104105
docker compose -f docker-compose.yaml restart
105106
```
106107

108+
## Docker Compose, One-Shot with PostgreSQL
109+
110+
Alternatively, the database can be started through `docker compose` as well. The real service URL can be set with the `NODE_URL` environment variable.
111+
112+
Save the yaml below into a file, e.g. `docker-compose.one-shot.yaml`.
113+
114+
```yaml
115+
services:
116+
syncserver:
117+
image: ghcr.io/mozilla-services/syncstorage-rs/syncstorage-rs-postgres:${SYNCSERVER_VERSION:-11659d98f9}
118+
platform: linux/amd64
119+
container_name: syncserver
120+
ports:
121+
- "8000:8000"
122+
environment:
123+
SYNC_HOST: "0.0.0.0"
124+
SYNC_PORT: "8000"
125+
SYNC_MASTER_SECRET: "${SYNC_MASTER_SECRET:-changeme_secret_key}"
126+
SYNC_SYNCSTORAGE__DATABASE_URL: "postgres://sync:sync@postgres:5432/syncserver"
127+
SYNC_TOKENSERVER__DATABASE_URL: "postgres://sync:sync@postgres:5432/syncserver"
128+
SYNC_TOKENSERVER__ENABLED: "true"
129+
SYNC_TOKENSERVER__RUN_MIGRATIONS: "true"
130+
SYNC_TOKENSERVER__FXA_EMAIL_DOMAIN: "api.accounts.firefox.com"
131+
SYNC_TOKENSERVER__FXA_OAUTH_SERVER_URL: "https://oauth.accounts.firefox.com"
132+
SYNC_HUMAN_LOGS: "${SYNC_HUMAN_LOGS:-false}"
133+
RUST_LOG: "${RUST_LOG:-info}"
134+
depends_on:
135+
postgres:
136+
condition: service_healthy
137+
restart: unless-stopped
138+
healthcheck:
139+
test: ["CMD", "curl", "-f", "http://localhost:8000/__heartbeat__"]
140+
interval: 30s
141+
timeout: 10s
142+
retries: 3
143+
start_period: 60s
144+
145+
postgres:
146+
image: postgres:18
147+
container_name: syncserver-postgres
148+
environment:
149+
POSTGRES_USER: sync
150+
POSTGRES_PASSWORD: sync
151+
POSTGRES_DB: syncserver
152+
volumes:
153+
- postgres_data:/var/lib/postgresql
154+
healthcheck:
155+
test: ["CMD-SHELL", "pg_isready -U sync -d syncserver"]
156+
interval: 10s
157+
timeout: 5s
158+
retries: 5
159+
start_period: 30s
160+
restart: unless-stopped
161+
162+
# insert record for the storage node
163+
bootstrap:
164+
image: postgres:18
165+
container_name: syncserver-bootstrap
166+
environment:
167+
PGHOST: postgres
168+
PGPORT: 5432
169+
PGUSER: sync
170+
PGPASSWORD: sync
171+
PGDATABASE: syncserver
172+
NODE_URL: "${NODE_URL:-http://localhost:8000}"
173+
depends_on:
174+
syncserver:
175+
condition: service_healthy
176+
command: >
177+
sh -c "
178+
echo 'Waiting for migrations to complete...';
179+
sleep 5;
180+
echo 'Inserting storage node record...';
181+
psql -c \"INSERT INTO nodes (service, node, available, current_load, capacity, downed, backoff)
182+
VALUES ((SELECT id FROM services WHERE service = 'sync-1.5'), '\$\${NODE_URL}', 1, 0, 1000, 0, 0)
183+
ON CONFLICT (service, node) DO NOTHING;\";
184+
echo 'DB bootstrap complete';
185+
"
186+
restart: "no"
187+
188+
volumes:
189+
postgres_data:
190+
driver: local
191+
```
192+
193+
Next, start the service with `docker compose`:
194+
195+
```sh
196+
SYNC_MASTER_SECRET=use_your_own_secret_4d3d3d3d \
197+
NODE_URL=http://localhost:8000 \
198+
docker compose -f docker-compose.one-shot.yaml up -d
199+
```
200+
107201
## Configuring Firefox
108202

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

0 commit comments

Comments
 (0)