Skip to content

Commit a0f08c2

Browse files
committed
add dev-postgres-powersync environment
1 parent ec159f0 commit a0f08c2

File tree

6 files changed

+291
-0
lines changed

6 files changed

+291
-0
lines changed

dev-postgres-powersync/.env

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ==================== Postgres credentials ================================
2+
PG_DATABASE_NAME=wger
3+
PG_DATABASE_PORT=5432
4+
PG_DATABASE_USER=wger
5+
PG_DATABASE_PASSWORD=wger
6+
7+
# ==================== Demo config =========================================
8+
DEMO_BACKEND_PORT=6061
9+
# The front-end demo application is accessible at this port on the host machine
10+
DEMO_CLIENT_PORT=3030
11+
PS_JWKS_URL=http://demo-backend:${DEMO_BACKEND_PORT}/api/get_keys/
12+
13+
# These can be generated by following the instructions in the `key-generator` folder
14+
# A temporary key will be used if these are not specified
15+
DEMO_JWKS_PUBLIC_KEY=
16+
DEMO_JWKS_PRIVATE_KEY=
17+
18+
# ==================== PowerSync variables ====================
19+
# The PowerSync API is accessible via this port
20+
PS_PORT=8080
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# yaml-language-server: $schema=../schema/schema.json
2+
3+
# Note that this example uses YAML custom tags for environment variable substitution.
4+
# Using `!env [variable name]` will substitute the value of the environment variable named
5+
# [variable name].
6+
#
7+
# Only environment variables with names starting with `PS_` can be substituted.
8+
#
9+
# e.g. With the environment variable `export PS_MONGO_URI=mongodb://localhost:27017`
10+
# and YAML code:
11+
# uri: !env PS_MONGO_URI
12+
# The YAML will resolve to:
13+
# uri: mongodb://localhost:27017
14+
#
15+
# If using VS Code see the `.vscode/settings.json` definitions which define custom tags.
16+
17+
# migrations:
18+
# # Migrations run automatically by default.
19+
# # Setting this to true will skip automatic migrations.
20+
# # Migrations can be triggered externally by altering the container `command`.
21+
# disable_auto_migration: true
22+
23+
# Settings for telemetry reporting
24+
# See https://docs.powersync.com/self-hosting/telemetry
25+
telemetry:
26+
# Opt out of reporting anonymized usage metrics to PowerSync telemetry service
27+
disable_telemetry_sharing: false
28+
29+
# Settings for source database replication
30+
replication:
31+
# Specify database connection details
32+
# Note only 1 connection is currently supported
33+
# Multiple connection support is on the roadmap
34+
connections:
35+
- type: postgresql
36+
# The PowerSync server container can access the Postgres DB via the DB's service name.
37+
# In this case the hostname is db
38+
39+
# The connection URI or individual parameters can be specified.
40+
# Individual params take precedence over URI params
41+
uri: !env PS_PG_URI
42+
43+
# Or use individual params
44+
45+
# hostname: db # From the Docker Compose service name
46+
# port: 5432
47+
# database: postgres
48+
# username: postgres
49+
# password: mypassword
50+
51+
# SSL settings
52+
sslmode: disable # 'verify-full' (default) or 'verify-ca' or 'disable'
53+
# 'disable' is OK for local/private networks, not for public networks
54+
55+
# Required for verify-ca, optional for verify-full
56+
# cacert: ${PS_PG_CA_CERT}
57+
58+
# Include a certificate here for HTTPs
59+
# client_certificate: ${PS_PG_CLIENT_CERT}
60+
# client_private_key: ${PS_PG_CLIENT_PRIVATE_KEY}
61+
62+
# This is valid if using the `mongo` service defined in `ps-mongo.yaml`
63+
64+
# Connection settings for sync bucket storage
65+
storage:
66+
type: mongodb
67+
uri: !env PS_MONGO_URI
68+
# Use these if authentication is required. The user should have `readWrite` and `dbAdmin` roles
69+
# username: my-mongo-user
70+
# password: my-password
71+
72+
# The port which the PowerSync API server will listen on
73+
port: !env PS_PORT
74+
75+
# Specify sync rules
76+
sync_rules:
77+
path: sync_rules.yaml
78+
79+
# Client (application end user) authentication settings
80+
client_auth:
81+
# Enable this if using Supabase Auth
82+
# supabase: true
83+
84+
# JWKS URIs can be specified here
85+
jwks_uri: !env PS_JWKS_URL
86+
87+
# Optional static collection of public keys for JWT verification
88+
# jwks:
89+
# keys:
90+
# - kty: 'RSA'
91+
# n: '${PS_JWK_N}'
92+
# e: '${PS_JWK_E}'
93+
# alg: 'RS256'
94+
# kid: '${PS_JWK_KID}'
95+
96+
# JWKS audience
97+
audience: ["powersync-dev", "powersync"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# See Documentation for more information:
2+
# https://docs.powersync.com/usage/sync-rules
3+
# Note that changes to this file are not watched.
4+
# The service needs to be restarted for changes to take effect.
5+
bucket_definitions:
6+
user_lists:
7+
# Separate bucket per todo list
8+
parameters: select id as list_id from lists where owner_id = token_parameters.user_id
9+
data:
10+
- select * from lists where id = bucket.list_id
11+
- select * from todos where list_id = bucket.list_id
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: wger-dev-postgres-powersync
2+
3+
services:
4+
web:
5+
image: wger/server:powersync
6+
depends_on:
7+
db:
8+
condition: service_healthy
9+
env_file:
10+
- ../config/prod.env
11+
- ../config/dev.env
12+
# django backend should do some powersync stuff..
13+
environment:
14+
# From the PowerSync service name
15+
# This is just used to populate the JWT audience
16+
POWERSYNC_URL: powersync-dev
17+
18+
# Keys here for demonstration
19+
POWERSYNC_PUBLIC_KEY: ${DEMO_JWKS_PUBLIC_KEY}
20+
POWERSYNC_PRIVATE_KEY: ${DEMO_JWKS_PRIVATE_KEY}
21+
volumes:
22+
- type: bind
23+
source: /home/dieter/code/wger-wger
24+
target: /home/wger/src
25+
ports:
26+
- "8000:8000"
27+
28+
cache:
29+
image: redis
30+
expose:
31+
- 6379
32+
healthcheck:
33+
test: redis-cli ping
34+
interval: 10s
35+
timeout: 5s
36+
retries: 5
37+
start_period: 30s
38+
restart: unless-stopped
39+
40+
db:
41+
image: postgres:15-alpine
42+
environment:
43+
- POSTGRES_USER=wger
44+
- POSTGRES_PASSWORD=wger
45+
- POSTGRES_DB=wger
46+
volumes:
47+
- postgres-data:/var/lib/postgresql/data/
48+
ports:
49+
- "5432:5432"
50+
expose:
51+
- 5432
52+
command: ["postgres", "-c", "wal_level=logical"]
53+
healthcheck:
54+
test: pg_isready -U wger
55+
interval: 10s
56+
timeout: 5s
57+
retries: 5
58+
start_period: 30s
59+
restart: unless-stopped
60+
61+
volumes:
62+
postgres-data:
63+
64+
include:
65+
- path: powersync-services/mongo.yaml
66+
- path: powersync-services/powersync.yaml
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
# MongoDB Service used internally
3+
mongo:
4+
image: mongo:7.0
5+
command: --replSet rs0 --bind_ip_all --quiet
6+
restart: unless-stopped
7+
ports:
8+
- 27017:27017
9+
volumes:
10+
- mongo_storage:/data/db
11+
12+
# Initializes the MongoDB replica set. This service will not usually be actively running
13+
mongo-rs-init:
14+
image: mongo:7.0
15+
depends_on:
16+
- mongo
17+
restart: on-failure
18+
entrypoint:
19+
- bash
20+
- -c
21+
- 'mongosh --host mongo:27017 --eval ''try{rs.status().ok && quit(0)} catch {} rs.initiate({_id: "rs0", version: 1, members: [{ _id: 0, host : "mongo:27017" }]})'''
22+
23+
volumes:
24+
mongo_storage:
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
services:
2+
powersync:
3+
depends_on:
4+
mongo-rs-init:
5+
condition: service_completed_successfully
6+
restart: unless-stopped
7+
image: journeyapps/powersync-service:latest
8+
# The unified service runs an API server and replication worker in the same container.
9+
# These services can be executed in different containers by using individual entry commands e.g.
10+
# Start only the API server with
11+
# command: ['start', '-r', 'api']
12+
# Start only the replication worker with
13+
# command: ['start', '-r', 'sync']
14+
15+
# Migations occur automatically by default. Default migrations can be disabled in `powersync.yaml`:
16+
# migrations:
17+
# disable_auto_migration: true
18+
#
19+
# Service migrations can be manually triggered by starting a container with the
20+
# following command:
21+
# command: ['migrate', 'up']
22+
# Note that this container must finish executing before starting the sync or unified container.
23+
command: ["start", "-r", "unified"]
24+
volumes:
25+
# Mounts the specified config folder to the container
26+
# This folder should contain `powersync.yaml and sync_rules.yaml
27+
- ../config-powersync:/config
28+
environment:
29+
# This is the path (inside the container) to the YAML config file
30+
# Alternatively the config path can be specified in the command
31+
# e.g:
32+
# command: ['start', '-r', 'unified', '-c', '/config/powersync.yaml']
33+
#
34+
# The config file can also be specified in Base 64 encoding
35+
# e.g.: Via an environment variable
36+
# POWERSYNC_CONFIG_B64: [base64 encoded content]
37+
# or e.g.: Via a command line parameter
38+
# command: ['start', '-r', 'unified', '-c64', '[base64 encoded content]']
39+
POWERSYNC_CONFIG_PATH: /config/powersync.yaml
40+
41+
# Sync rules can be specified as base 64 encoded YAML
42+
# e.g: Via an environment variable
43+
# POWERSYNC_SYNC_RULES_B64: "[base64 encoded sync rules]"
44+
# or e.g.: Via a command line parameter
45+
# command: ['start', '-r', 'unified', '-sync64', '[base64 encoded content]']
46+
47+
# The following will be inserted into the powersync.yaml file via templating
48+
# Templates are used for filesystem and base64 configuration files
49+
PS_PG_URI: postgres://${PG_DATABASE_USER}:${PG_DATABASE_PASSWORD}@db:${PG_DATABASE_PORT}/${PG_DATABASE_NAME}
50+
PS_MONGO_URI: mongodb://mongo:27017/powersync_demo
51+
52+
# Note that powersync.yaml->client_auth->allow_local_jwks must be true for local URLs to work
53+
PS_JWKS_URL: ${PS_JWKS_URL}
54+
55+
# The port which the PowerSync API server should run on
56+
PS_PORT: ${PS_PORT}
57+
58+
# CA certificate for Postgres connection
59+
# PS_PG_CA_CERT:
60+
61+
# Client certificate for Postgres connection
62+
# PS_PG_CLIENT_CERT:
63+
64+
# Client private key for Postgres connection
65+
# PS_PG_CLIENT_PRIVATE_KEY:
66+
67+
# Potential JWKs public key template
68+
# PS_JWK_N:
69+
# PS_JWK_E:
70+
# PS_JWK_KID:
71+
72+
ports:
73+
- ${PS_PORT}:${PS_PORT}

0 commit comments

Comments
 (0)