Skip to content

Commit d408673

Browse files
committed
docs: add one-shot docker compose yaml to how-to
1 parent 11659d9 commit d408673

1 file changed

Lines changed: 96 additions & 3 deletions

File tree

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

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ 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
@@ -23,7 +23,7 @@ configuration or deployment steps will be noted.
2323
for authentication and authorization.
2424
- The service will be deployed at http://localhost:8000/.
2525

26-
## Docker Compose
26+
## Docker Compose, Sync Services Only
2727

2828
Save the yaml below into a file, e.g. `docker-compose.yaml`.
2929

@@ -104,6 +104,99 @@ Restart the service with
104104
docker compose -f docker-compose.yaml restart
105105
```
106106

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

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

0 commit comments

Comments
 (0)