mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-17 16:37:43 +00:00
fix(infra): close db-startup race in supersync e2e stack
pg_isready -U supersync without -d returned OK as soon as postgres accepted connections to the default database, but during first-run initdb the server briefly bounced while POSTGRES_DB was created. supersync's prisma db push then race-failed with P1001. - Healthcheck now runs psql -d supersync_db -c 'SELECT 1' so it only passes once the app's db is queryable. - Dockerfile.test entrypoint retries prisma db push up to 15x before giving up — defense in depth if anything else ever races.
This commit is contained in:
parent
db329ec5ff
commit
add56d818c
2 changed files with 21 additions and 5 deletions
|
|
@ -11,11 +11,22 @@ services:
|
|||
- '55432:5432'
|
||||
volumes:
|
||||
- db_data:/var/lib/postgresql/data
|
||||
# Gate on supersync_db existing AND accepting queries from the app user.
|
||||
# Plain `pg_isready -U supersync` returns OK as soon as postgres accepts
|
||||
# connections to the default `postgres` database — but during first-run
|
||||
# initdb the server briefly bounces while POSTGRES_DB is created, so
|
||||
# supersync's `prisma db push` race-fails with P1001. Querying
|
||||
# supersync_db directly closes that window.
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', 'pg_isready -U supersync']
|
||||
interval: 5s
|
||||
test:
|
||||
[
|
||||
'CMD-SHELL',
|
||||
'pg_isready -U supersync -d supersync_db && psql -U supersync -d supersync_db -c "SELECT 1" > /dev/null 2>&1',
|
||||
]
|
||||
interval: 3s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
retries: 20
|
||||
start_period: 10s
|
||||
|
||||
# SuperSync server for E2E testing
|
||||
# Start with: docker compose up -d supersync
|
||||
|
|
|
|||
|
|
@ -50,5 +50,10 @@ ENV TEST_MODE_CONFIRM=yes-i-understand-the-risks
|
|||
ENV CORS_ORIGINS=*
|
||||
ENV JWT_SECRET=e2e-test-secret-minimum-32-chars-long-for-security
|
||||
|
||||
# Push schema to DB and start server
|
||||
CMD sh -c "npx prisma db push && node dist/src/index.js"
|
||||
# Push schema to DB and start server.
|
||||
# Retry `prisma db push` for up to ~30s on transient connection failures
|
||||
# (postgres can briefly bounce during first-run initdb even after the db's
|
||||
# healthcheck passes). Without this, the container exits on first P1001
|
||||
# and depends on docker's restart policy to recover, which can't be relied
|
||||
# on across compose invocations.
|
||||
CMD sh -c "for i in $(seq 1 15); do npx prisma db push && break; echo \"prisma db push failed (attempt $i/15), retrying in 2s...\"; sleep 2; done && node dist/src/index.js"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue