Files
collective-lists/infra/docker-compose.dev.yml
Oier Bravo Urtasun cb07f67a69 feat(realtime): full Fase 2b.0 test suite + infra hardening
Extend the 2b.0 red-phase coverage: presence, RLS isolation, offline-queue
contract, and Playwright scaffolds for the shopping-session UX. Only the
presence test is blocked on an upstream Realtime bug (documented below); all
other Realtime paths are proven end-to-end.

Tests
- realtime-postgres-changes.test.ts: now uses afterEach socket disconnect
  (Vitest singleFork kept Phoenix sockets alive between files, leaking state)
- realtime-isolation.test.ts (new): R-I-01 David (guest, same collective)
  receives events; R-I-02 Eva (non-member) receives NONE — RLS is enforced
  server-side per subscribed JWT
- realtime-presence.test.ts (new, describe.skip): two-client roster + leave
  assertions ready, gated on upstream bug
- sync-queue.test.ts (new, describe.skip): 7 placeholders pinning the
  apps/web/src/lib/sync/queue.ts contract (Q-01..Q-04 enqueue / in-order
  flush / retry; F-01..F-03 online-event flush + last-write-wins)
- apps/web/tests/e2e/{session,realtime,offline}.test.ts (new, describe.skip):
  S-01..S-03, R-E-01, R-E-02, O-01, O-02 pinning the Modo Compra UI contract
- vitest.config.ts: fileParallelism=false, drop singleFork so each file gets
  a fresh worker fork — prevents RealtimeClient singleton leakage

Infra
- db-init/00-role-passwords.sh: pre-create `realtime` schema with
  AUTHORIZATION supabase_admin. Realtime's per-tenant migrator creates tables
  INSIDE the schema but does not create the schema itself; without this the
  first tenant connect fails with "schema realtime does not exist"
- docker-compose.dev.yml: adopt the upstream supabase/supabase Realtime env
  shape — SEED_SELF_HOST=true + RUN_JANITOR=true + RLIMIT_NOFILE=10000 +
  drop the custom `command: eval seeds` (that bypasses the normal supervisor
  startup and was observed to cause GenServer crashes under load).
  Version pinned to v2.76.5 to match the official docker-compose.

Known upstream bug
- Realtime v2.76.5 and v2.83.0 both crash on presence_diff:
  `(UndefinedFunctionError) RealtimeChannel.handle_out/3 is undefined`.
  postgres_changes + isolation unaffected (they don't traverse handle_out).
  Presence tests stay `describe.skip` until a fixed upstream is released.

Totals: 59 Vitest passed (+ 9 skipped awaiting implementation/upstream),
16 pgTAP, 15 Playwright (+ 7 E2E scaffolded for 2b UI) = 90 green.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:55:55 +02:00

262 lines
11 KiB
YAML

name: colectivo-dev
# Self-hosted Supabase stack + Keycloak for local development.
# Based on: https://github.com/supabase/supabase/tree/master/docker
#
# Start: just dev
# Stop: just dev-stop
# Reset: just dev-clean (drops volumes)
services:
# ── PostgreSQL 15 ───────────────────────────────────────────────────────────
db:
image: supabase/postgres:15.1.1.78
restart: unless-stopped
healthcheck:
test: pg_isready -U postgres -h localhost
interval: 5s
timeout: 5s
retries: 10
ports:
- "5432:5432"
environment:
POSTGRES_HOST: /var/run/postgresql
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
JWT_SECRET: ${SUPABASE_JWT_SECRET}
JWT_EXP: 3600
volumes:
- db-data:/var/lib/postgresql/data
# Sets internal role passwords to POSTGRES_PASSWORD on first init.
- ./db-init:/docker-entrypoint-initdb.d:ro
# ── GoTrue (Supabase Auth) ──────────────────────────────────────────────────
auth:
image: supabase/gotrue:v2.158.1
restart: unless-stopped
depends_on:
db:
condition: service_healthy
environment:
GOTRUE_API_HOST: "0.0.0.0"
GOTRUE_API_PORT: 9999
API_EXTERNAL_URL: ${PUBLIC_APP_URL:-http://localhost:5173}
GOTRUE_API_EXTERNAL_URL: ${PUBLIC_APP_URL:-http://localhost:5173}
GOTRUE_DB_DRIVER: postgres
GOTRUE_DB_DATABASE_URL: postgres://supabase_auth_admin:${POSTGRES_PASSWORD:-postgres}@db:5432/postgres
GOTRUE_SITE_URL: ${PUBLIC_APP_URL:-http://localhost:5173}
GOTRUE_JWT_SECRET: ${SUPABASE_JWT_SECRET}
GOTRUE_JWT_EXP: 3600
# Allow OIDC-based user creation (Keycloak is the gatekeeper).
# Direct email/password signup is blocked at the Kong level (no /auth/v1/signup route exposed).
GOTRUE_DISABLE_SIGNUP: "false"
# OIDC: Keycloak as external provider
GOTRUE_EXTERNAL_KEYCLOAK_ENABLED: "true"
GOTRUE_EXTERNAL_KEYCLOAK_CLIENT_ID: ${PUBLIC_KEYCLOAK_CLIENT_ID:-colectivo-web}
# colectivo-web is a confidential client in Keycloak (required for GoTrue code exchange).
# Dev value matches keycloak/realm-export.json. Override in .env for prod.
GOTRUE_EXTERNAL_KEYCLOAK_SECRET: ${KEYCLOAK_CLIENT_SECRET:-gotrue-dev-secret}
# openid is required so the access token is an OIDC token and the userinfo endpoint accepts it.
GOTRUE_EXTERNAL_KEYCLOAK_SCOPES: "openid profile email"
# GoTrue fetches Keycloak's OIDC discovery doc at this URL (Docker-internal hostname).
# The browser also uses this hostname — add "127.0.0.1 keycloak" to /etc/hosts.
GOTRUE_EXTERNAL_KEYCLOAK_URL: http://keycloak:8080/realms/colectivo
# Keycloak redirects the browser here after login; GoTrue exchanges the code.
GOTRUE_EXTERNAL_KEYCLOAK_REDIRECT_URI: http://localhost:8001/auth/v1/callback
GOTRUE_MAILER_AUTOCONFIRM: "true"
# ── PostgREST ───────────────────────────────────────────────────────────────
rest:
image: postgrest/postgrest:v12.2.0
restart: unless-stopped
depends_on:
db:
condition: service_healthy
environment:
PGRST_DB_URI: postgres://authenticator:${POSTGRES_PASSWORD:-postgres}@db:5432/postgres
PGRST_DB_SCHEMAS: public,storage,graphql_public
PGRST_DB_ANON_ROLE: anon
PGRST_JWT_SECRET: ${SUPABASE_JWT_SECRET}
PGRST_DB_USE_LEGACY_GUCS: "false"
PGRST_APP_SETTINGS_JWT_SECRET: ${SUPABASE_JWT_SECRET}
PGRST_APP_SETTINGS_JWT_EXP: 3600
# ── Realtime ─────────────────────────────────────────────────────────────────
realtime:
# Pinned to match the version in supabase/supabase's official docker-compose.
# v2.83.0 had a runtime crash on presence_diff: `RealtimeWeb.RealtimeChannel.handle_out/3
# is undefined` — presence events were published but couldn't be delivered.
image: supabase/realtime:v2.76.5
restart: unless-stopped
depends_on:
db:
condition: service_healthy
environment:
PORT: 4000
DB_HOST: db
DB_PORT: 5432
# Realtime auto-creates the `realtime` schema (messages, subscription, etc.)
# on first connect per tenant. It needs CREATE ON DATABASE + ownership, which
# only supabase_admin (superuser) reliably has. Using
# supabase_replication_admin fails with `permission denied for schema realtime`.
DB_USER: supabase_admin
DB_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
DB_NAME: postgres
DB_AFTER_CONNECT_QUERY: SET search_path TO _realtime
DB_ENC_KEY: supabaserealtime
API_JWT_SECRET: ${SUPABASE_JWT_SECRET}
# supabase-js resolves the tenant from the URL subdomain; for bare
# localhost with no subdomain it defaults to "realtime". We override the
# default tenant name so the seed creates the tenant the client will look up.
SELF_HOST_TENANT_NAME: realtime
# `SEED_SELF_HOST: true` enables the built-in seeding path used by the
# upstream supabase/supabase docker-compose. This is the canonical
# startup flow; a custom `command: ... eval Realtime.Release.seeds ...`
# starts the seed OUTSIDE the normal supervisor tree and was observed
# to crash the `RealtimeChannel` on presence_diff broadcasts with an
# "UndefinedFunctionError: handle_out/3" once clients connected.
SEED_SELF_HOST: "true"
RUN_JANITOR: "true"
APP_NAME: realtime
SECRET_KEY_BASE: UpNVntn3cDxHJpq99YMc1T1AQgQpc8kfYTuRgBiYa15BLrx8etQoXz3bhZkeYTvU
ERL_AFLAGS: -proto_dist inet_tcp
DNS_NODES: "''"
RLIMIT_NOFILE: "10000"
METRICS_JWT_SECRET: ${SUPABASE_JWT_SECRET}
# ── Storage ──────────────────────────────────────────────────────────────────
storage:
image: supabase/storage-api:v1.11.13
restart: unless-stopped
depends_on:
db:
condition: service_healthy
rest:
condition: service_started
environment:
ANON_KEY: ${PUBLIC_SUPABASE_ANON_KEY}
SERVICE_KEY: ${SUPABASE_SERVICE_ROLE_KEY}
POSTGREST_URL: http://rest:3000
PGRST_JWT_SECRET: ${SUPABASE_JWT_SECRET}
DATABASE_URL: postgres://supabase_storage_admin:${POSTGRES_PASSWORD:-postgres}@db:5432/postgres
FILE_SIZE_LIMIT: 52428800
STORAGE_BACKEND: file
FILE_STORAGE_BACKEND_PATH: /var/lib/storage
TENANT_ID: stub
REGION: local
GLOBAL_S3_BUCKET: stub
ENABLE_IMAGE_TRANSFORMATION: "true"
IMGPROXY_URL: http://imgproxy:5001
volumes:
- storage-data:/var/lib/storage
# ── ImgProxy (image transformations for Storage) ──────────────────────────
imgproxy:
image: darthsim/imgproxy:v3.8.0
restart: unless-stopped
environment:
IMGPROXY_BIND: ":5001"
IMGPROXY_LOCAL_FILESYSTEM_ROOT: /
IMGPROXY_USE_ETAG: "true"
IMGPROXY_ENABLE_WEBP_DETECTION: "true"
volumes:
- storage-data:/var/lib/storage:ro
# ── Kong (API Gateway) ────────────────────────────────────────────────────
kong:
image: kong:2.8.1
restart: unless-stopped
# kong.yml uses ${SUPABASE_ANON_KEY} / ${SUPABASE_SERVICE_KEY} placeholders.
# Kong 2.8 does NOT substitute env vars in declarative config automatically.
# kong-start.sh uses perl to substitute ${VAR} from the container environment
# before Kong loads the config.
entrypoint: ["/bin/bash", "/home/kong/kong-start.sh"]
ports:
- "8001:8000" # HTTP API (8000 may conflict; use http://localhost:8001)
- "8443:8443" # HTTPS API
depends_on:
db:
condition: service_healthy
environment:
KONG_DATABASE: "off"
KONG_DECLARATIVE_CONFIG: /home/kong/kong.yml
KONG_DNS_ORDER: LAST,A,CNAME
KONG_PLUGINS: request-transformer,cors,key-auth,acl,basic-auth
KONG_NGINX_PROXY_PROXY_BUFFER_SIZE: 160k
KONG_NGINX_PROXY_PROXY_BUFFERS: 64 160k
SUPABASE_ANON_KEY: ${PUBLIC_SUPABASE_ANON_KEY}
SUPABASE_SERVICE_KEY: ${SUPABASE_SERVICE_ROLE_KEY}
volumes:
- ./kong.yml:/home/kong/temp.yml:ro
- ./kong-start.sh:/home/kong/kong-start.sh:ro
# ── Supabase Studio ───────────────────────────────────────────────────────
studio:
image: supabase/studio:2026.04.08-sha-205cbe7
restart: unless-stopped
ports:
- "54323:3000"
# Override the built-in healthcheck (it uses node fetch which fails inside the container).
# The studio works fine; this just prevents a misleading "unhealthy" status.
healthcheck:
test: ["CMD-SHELL", "curl -sf http://localhost:3000/api/platform/profile || exit 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 20s
depends_on:
db:
condition: service_healthy
environment:
STUDIO_PG_META_URL: http://meta:8080
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
DEFAULT_ORGANIZATION_NAME: Colectivo
DEFAULT_PROJECT_NAME: colectivo-dev
SUPABASE_URL: http://kong:8000
SUPABASE_PUBLIC_URL: ${PUBLIC_SUPABASE_URL:-http://localhost:8001}
SUPABASE_ANON_KEY: ${PUBLIC_SUPABASE_ANON_KEY}
SUPABASE_SERVICE_KEY: ${SUPABASE_SERVICE_ROLE_KEY}
AUTH_JWT_SECRET: ${SUPABASE_JWT_SECRET}
LOGFLARE_API_KEY: ""
LOGFLARE_URL: http://analytics:4000
NEXT_PUBLIC_ENABLE_LOGS: "true"
NEXT_ANALYTICS_BACKEND_PROVIDER: postgres
# ── pg-meta (metadata API for Studio) ───────────────────────────────────
meta:
image: supabase/postgres-meta:v0.83.2
restart: unless-stopped
depends_on:
db:
condition: service_healthy
environment:
PG_META_PORT: 8080
PG_META_DB_HOST: db
PG_META_DB_PORT: 5432
PG_META_DB_NAME: postgres
PG_META_DB_USER: supabase
PG_META_DB_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
# ── Keycloak 24 ──────────────────────────────────────────────────────────
keycloak:
image: quay.io/keycloak/keycloak:24.0.5
restart: unless-stopped
ports:
- "8080:8080"
command: start-dev --import-realm
environment:
KC_DB: dev-file
KEYCLOAK_ADMIN: ${KEYCLOAK_ADMIN:-admin}
KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD:-admin}
KC_HTTP_PORT: 8080
KC_HOSTNAME_STRICT: "false"
KC_HOSTNAME_STRICT_HTTPS: "false"
volumes:
- keycloak-data:/opt/keycloak/data
- ../keycloak/realm-export.json:/opt/keycloak/data/import/realm-export.json:ro
volumes:
db-data:
storage-data:
keycloak-data: