railyard/apps/insights/docker-compose.test.yml
caelum0x 1bc04fa81b feat(insights): the Insights fork behind the add-on, site entries, tenant summaries, caps that say what happens (PY1.3)
Railyard side of PY1.3 (RYP-D2, RYP-E1, SC-E3). Acceptance:
1. apps/insights: umami-software/umami v3.4.0 (MIT, commit ec0ff503),
   vendored --depth 1, LICENSE kept, NOTICE added. Fork additions only:
   src/railyard/{ingest,summary,tenancy,api-only}.ts, /v1/ingest/batch (the
   edge collector contract v1, bearer INSIGHTS_INGEST_TOKEN, no IP ever,
   retried batches de-duplicated by migration 90_railyard_ingest_receipts),
   /api/v1/tenants/{org}/summary (bearer INSIGHTS_API_TOKEN), src/proxy.ts
   (INSIGHTS_API_ONLY=1 serves only the Railyard API and the heartbeat).
   Tenant isolation is tested at the API level (an app id owned by another org
   is refused) and at the SQL level (upstream migrations 01-26 plus 90 on a
   throwaway cluster: org B never reads org A's rows, even naming its app).
   Upstream vitest suite: not run on the Mac (pnpm 12.3.4 pinned upstream,
   disk floor); it runs in the image build on box 2 or CI.
2. No upstream product name in anything a customer loads: the page tag, the
   console pages and the fork's additions (tests); the upstream dashboard is
   never served in API-only mode.
3. The console writes the collector's site entry on "Add app", on
   auto-created apps from deploys, and rewrites every entry on add-on, plan or
   pause changes (lib/sites.ts, SITES KV binding). The bridge gains
   `sites` (the project's app, site key, page tag and collector URLs, entry
   written) and the analytics proof is the first event from Insights. The
   console's Insights page shows visitors, events, first event and the
   visit -> signup -> first action funnel.
5. insights-edge/src/caps.ts: at 100% of the cap events are still counted and
   not stored until the next UTC month; the console shows the same message
   from a byte-identical copy (lib/caps.ts, tested).
4 (384 MB at 50 events a second for 10 min) is measured on staging before deploy.

Env: INSIGHTS_API_URL, INSIGHTS_API_TOKEN, SITES KV binding (console);
INSIGHTS_INGEST_TOKEN, INSIGHTS_API_TOKEN, INSIGHTS_API_ONLY (Insights).

Tests: console 54/54 (tsc clean), insights fork 7/7 (incl. SQL isolation),
insights-edge caps + collector + sim 14/14, tests/contract 3/3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:23:38 +03:00

109 lines
3.5 KiB
YAML

# Compose stack for the API integration test suite (`pnpm test:api`).
#
# This is NOT the deployable stack — see docker-compose.yml for that. Databases
# run on tmpfs and are discarded on `down`, so every run starts from an empty
# schema (migrations + the default admin user are applied by the umami image on
# boot via scripts/start-docker.sh).
#
# Profiles:
# postgres umami + Postgres -> pnpm test:api
# clickhouse umami + Postgres + ClickHouse -> pnpm test:api:clickhouse
#
# Environment overrides:
# UMAMI_TEST_PORT host port for the app (default 3100, avoids the dev server on 3000)
# UMAMI_TEST_IMAGE image tag to run/build (default umami-test:local)
# SKIP_BUILD_GEO "1" (default) skips the MaxMind download during the image build
x-umami-service: &umami-service
image: ${UMAMI_TEST_IMAGE:-umami-test:local}
build:
context: .
args:
SKIP_BUILD_GEO: ${SKIP_BUILD_GEO:-1}
ports:
- "${UMAMI_TEST_PORT:-3100}:3000"
init: true
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://localhost:3000/api/heartbeat || exit 1"]
interval: 2s
timeout: 5s
retries: 90
start_period: 20s
x-umami-env: &umami-env
DATABASE_URL: postgresql://umami:umami@db:5432/umami
APP_SECRET: umami-api-test-secret
TWO_FACTOR_ENCRYPTION_KEY: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
# Playwright/curl user agents are classified as bots; without this /api/send silently drops events.
DISABLE_BOT_CHECK: "1"
DISABLE_TELEMETRY: "1"
DISABLE_UPDATES: "1"
MCP_ENABLED: "1"
services:
db:
image: postgres:15-alpine
environment:
POSTGRES_DB: umami
POSTGRES_USER: umami
POSTGRES_PASSWORD: umami
tmpfs:
- /var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U umami -d umami"]
interval: 2s
timeout: 5s
retries: 30
umami:
<<: *umami-service
profiles: [postgres]
environment: *umami-env
depends_on:
db:
condition: service_healthy
clickhouse:
# Pinned to an LTS release. 26.7+ rejects db/clickhouse/schema.sql because
# website_event_stats_hourly has dimension columns outside the sorting key
# (see allow_dimensions_outside_sorting_key).
image: clickhouse/clickhouse-server:25.8
profiles: [clickhouse]
environment:
CLICKHOUSE_DB: umami
CLICKHOUSE_USER: umami
CLICKHOUSE_PASSWORD: umami
ulimits:
nofile:
soft: 262144
hard: 262144
tmpfs:
- /var/lib/clickhouse
volumes:
# The image runs /docker-entrypoint-initdb.d/*.sql on first start (empty data dir).
- ./tests/api/docker/clickhouse-init/00-create-db.sql:/docker-entrypoint-initdb.d/00-create-db.sql:ro
- ./db/clickhouse/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
healthcheck:
# Healthy only once schema.sql has been applied (session_link is the last table it creates).
test:
[
"CMD-SHELL",
"clickhouse-client --user umami --password umami --query \"SELECT throwIf(count() = 0) FROM system.tables WHERE database = 'umami' AND name = 'session_link'\"",
]
interval: 2s
timeout: 5s
retries: 90
start_period: 10s
umami-clickhouse:
<<: *umami-service
profiles: [clickhouse]
environment:
<<: *umami-env
CLICKHOUSE_URL: http://umami:umami@clickhouse:8123/umami
depends_on:
db:
condition: service_healthy
clickhouse:
condition: service_healthy