Files
templates/blueprints/powersync/template.toml
Mauricio Siu 8480130401 fix: bundle Postgres so the service can actually start
The template pointed PS_DATA_SOURCE_URI at a placeholder connection
string (postgresql://user:password@host:5432/db), so the PowerSync
service could never connect and crash-looped, leaving the domain
returning Traefik 404s.

Changes:
- Add a bundled Postgres 17 service with wal_level=logical, a
  healthcheck, and a persistent volume; powersync waits for it to be
  healthy before starting.
- Replace the base64-encoded config env var with a readable
  powersync.yaml mounted via [[config.mounts]]. Replication reads from
  the powersync database and bucket storage uses a separate
  powersync_storage database (Postgres storage requires a database
  distinct from the replication source).
- Add an init SQL mount that creates the storage database, a demo
  "lists" table synced by the default sync rules, and the powersync
  publication required for logical replication.
- Replace the unsupported sync_config block with standard sync_rules,
  and add an HS256 dev key so client auth works out of the box.
- Remove host port mapping (Traefik routes to the container port) and
  point the template domain at /probes/liveness since PowerSync has no
  route on "/".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 02:05:00 -06:00

89 lines
2.4 KiB
TOML
Executable File

[variables]
main_domain = "${domain}"
# Password for the bundled PostgreSQL (used as replication source and bucket storage).
postgres_password = "${password:32}"
# Auto-generated token for the PowerSync API (used in Authorization header).
admin_token = "${password:32}"
# HS256 secret used to sign development JWTs for clients (base64url encoded).
jwks_key = "${password:48}"
[config]
[[config.domains]]
serviceName = "powersync"
port = 8080
host = "${main_domain}"
# PowerSync has no route on "/"; the liveness probe returns 200.
path = "/probes/liveness"
[config.env]
POSTGRES_PASSWORD = "${postgres_password}"
# PowerSync service configuration.
# Docs: https://docs.powersync.com/self-hosting/installation/powersync-service-setup
[[config.mounts]]
filePath = "powersync.yaml"
content = """
telemetry:
disable_telemetry_sharing: true
# Replication source: the bundled Postgres (wal_level=logical).
# Point this at your own database to sync real data.
replication:
connections:
- type: postgresql
uri: postgresql://powersync:${postgres_password}@postgres:5432/powersync
sslmode: disable
# Bucket storage. Must be a different database than the replication source.
storage:
type: postgresql
uri: postgresql://powersync:${postgres_password}@postgres:5432/powersync_storage
sslmode: disable
port: 8080
# Sync rules: syncs the demo "lists" table to all clients.
# Edit these for your own schema: https://docs.powersync.com/usage/sync-rules
sync_rules:
content: |
bucket_definitions:
global:
data:
- SELECT * FROM lists
client_auth:
# HS256 key for signing development tokens.
# See https://docs.powersync.com/installation/authentication-setup/custom
jwks:
keys:
- kty: oct
alg: HS256
kid: powersync-dev
k: ${jwks_key}
audience: ["powersync"]
api:
tokens:
- ${admin_token}
"""
# Runs once on the first Postgres startup (empty data volume).
[[config.mounts]]
filePath = "init-powersync.sql"
content = """
-- Separate database for PowerSync bucket storage.
CREATE DATABASE powersync_storage OWNER powersync;
-- Demo table synced by the default sync rules.
CREATE TABLE lists (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
name text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now()
);
INSERT INTO lists (name) VALUES ('Welcome to PowerSync');
-- Publication used by PowerSync logical replication.
CREATE PUBLICATION powersync FOR ALL TABLES;
"""