Skip to content

Latest commit

 

History

History
299 lines (250 loc) · 17.3 KB

README.md

File metadata and controls

299 lines (250 loc) · 17.3 KB

Local Infrastructure (Docker Compose)

Compose stacks for local development. Operational rules live in docs/standards/12-infrastructure.md.

dev.yml

Services in order they appear in dev.yml (data plane → identity → media → eventing → secrets → Dapr sidecar → gateway).

Bring it up with make dev from the repo root (the orchestrator copies .env.example → a private .env on first run). Before starting Keycloak, prepare KEYCLOAK_WEB_CLIENT_SECRET and KEYCLOAK_FEDERATION_ADMIN_SECRET in that selected private source; Compose refuses a missing value instead of importing a published fallback. The federation secret is the confined federation admin client's (ADR-0099); the API reads the same value as Federation__ClientSecret. Preserve an existing confidential secret and follow the recovery procedure on mismatch. Existing file permissions require explicit operator correction. The end-to-end overlay adds tmpfs volumes for ephemeral test runs — see e2e.yml below.

Native callback trust

Before starting Keycloak, the owned Compose launcher prepares .data/keycloak-trust (empty when callback delivery is disabled). The directory is mounted read-only into Keycloak's configured truststore path. An explicitly enabled native callback copies only its qualified public root there and uses host.docker.internal:host-gateway to reach the callback-only TLS listener in the existing native child. Follow the single setup and recovery recipe before opt-in; do not mount private CA keys, widen the ordinary native listener, or bypass TLS verification. Use the normal owned launchers: they compute the public-root service identity needed to reload Keycloak trust. Raw docker compose up does not qualify callback activation.

Data plane (Phase 01 packet 3)

Service Image Local endpoint Default credentials
PostgreSQL 18 postgres:18.4-alpine localhost:5432 learnstack / learnstack
Valkey 8 valkey/valkey:8.1-alpine localhost:6379 —
SeaweedFS chrislusf/seaweedfs:3.94 localhost:9000 (S3), localhost:9001 (filer UI), localhost:9333 (master) S3 access learnstack / secret learnstack-dev-secret
Mailpit axllent/mailpit:v1.29.7 localhost:1025 (SMTP), localhost:8025 (UI) accepts any auth
Meilisearch getmeili/meilisearch:v1.44.0 localhost:7700 master key learnstack-dev-master-key

Identity (Phase 01 packet 4)

Service Image Local endpoint Default credentials
Keycloak quay.io/keycloak/keycloak:26.7.5, pinned by index digest sha256:37dbaf6f…a475a85 localhost:8080 master admin admin / admin-dev-secret

Two realms imported on first boot from infra/keycloak/realms/:

  • learnstack (tenant users) — confidential API and code/S256 web clients, with four declared tenant personas. The realm guide owns the exact identities, private secret source and callbacks.
  • learnstack-hub (operators) — clients learnstack-hub-web (the portal, public PKCE) and learnstack-operator (LearnStack's platform surface, public PKCE with MFA step-up); demo user demo-operator@learnstack.test (demo-dev-secret). CONFIGURE_TOTP is a required action, so the first login sets up the authenticator the step-up needs. A Keycloak volume from before the operator client keeps its old realm; recreate it to import the new one.

See ../keycloak/README.md for the realm-isolation invariant, non-destructive reconciliation and the Phase 02b/03 wiring notes.

Two Postgres init scripts run, in name order, only on the first start of a fresh postgres-data volume:

Script Creates
postgres-init/01-create-keycloak-db.sql the keycloak database Keycloak stores its realm state in
postgres-init/02-create-roles.sql the four baseline database roles plus ADR-0097’s confined learnstack_identity_ingress and ADR-0104’s confined learnstack_identity_rebind logins, reading passwords from LEARNSTACK_*_PW in the environment

A volume created before Phase 02a Packet 6 has no roles, and nothing will tell you: init scripts do not re-run, make dev reports healthy, and the first make migrate fails with password authentication failed for user "learnstack_migration". Either run make clean (destructive — drops every volume) and make dev, or apply the script by hand:

docker compose --env-file .env -f infra/compose/dev.yml exec -T postgres   sh -c 'psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB"'   < infra/compose/postgres-init/02-create-roles.sql

The script converges passwords, attributes and memberships on every run; it is not a no-op. P03-6's forward Identity migration requires the fifth role to exist, and the P03-9 Step 3 Identity migration requires the sixth. For a warm volume, set LEARNSTACK_IDENTITY_INGRESS_PW and LEARNSTACK_IDENTITY_REBIND_PW in the selected private environment, recreate the postgres container with the existing volume to pass the new environment values, then apply the roles script above before make migrate. Do not delete a volume to add a role. The sixth role's connection string is never a compose or host setting: it exists only in the environment of the offline rebind tool. No runtime process receives the migration password. The database contract owns the private machine source and its bounds; installing storage alone does not activate provider polling.

The P03-2 source contract uses two backend-only configuration keys, ConnectionStrings:IdentityAuthorization and ConnectionStrings:AuthorizationEvidence, as a guarded pair alongside Default. Infrastructure Standards § Authorization and evidence topology owns the Development-only direct-PostgreSQL derivation, fixed 4/2 lane bounds and explicit non-Development/PgBouncer setup. The owned seed/demo runtime helper passes the selected pair and installed authority to Seeder children, with the existing Deployment__Mode=Development selection for this direct local stack. The Seeder qualifies one process-owned evidence source against the business source's actual database and installed authority, then shares it across all per-act providers. Restore/build and projection children receive no runtime authority or database credentials. Neither matching authority nor these client pools proves reserved backend capacity. The phase Status block owns current implementation/review state; production aliases, downstream reserves and admitted instance count require Phase 11 qualification.

Fresh imports do not upgrade an existing realm. P02b-6's bounded warm-realm reconciler is shared by make seed and make demo after application seed. Both entries validate the selected private source before infrastructure work; older files must add the BFF secret key explicitly. Existing credentials and provider IDs are preserved. The realm guide owns exact behavior, refusals and current qualification status; a database wipe is not an upgrade.

Live media (Phase 01 packet 5)

Service Image Local endpoint Default credentials
LiveKit OSS livekit/livekit-server:v1.12.0 ws://localhost:7880 (signaling), tcp/7881 (TCP fallback), tcp/7882 (TURN/TLS), udp/50000-50100 (media) API key devkey / secret devsecret-32-byte-min-length-padding-xyz
Coturn coturn/coturn:4.11.0 udp+tcp/3478 (STUN/TURN), tcp/5349 (TURN/TLS), udp/49152-49200 (relay range) TURN user devuser / password devsecret

LiveKit config at infra/livekit/livekit.yaml; Coturn config at infra/coturn/turnserver.conf. See ../livekit/README.md for the ILiveClassProvider integration plan (Phase 08c) + the recording / consent / cost-tracking story.

Eventing + secrets + Dapr sidecar + gateway (Phase 01 packet 6) — profile gated

These do not start with make dev. Nothing the backend runs today calls any of them: IEventBus resolves to InProcessEventBus, ICacheService to InMemoryCacheService, ISecretProvider to ConfigurationSecretProvider, and the edge concerns APISIX would take are ASP.NET middleware. Their adapters land in Phase 11 against the written triggers in ADR-0035, so until then they are seven containers of carrying cost. make dev starts 7 services; make dev-gated starts all 14.

Valkey is here too, though it is listed under the data plane above: it is the Dapr state component, and the same trigger governs it — more than one application instance running concurrently.

Service Image Local endpoint Default credentials
Kafka (KRaft) confluentinc/cp-kafka:8.2.1 in-cluster only — no host port; use kafka-ui none (PLAINTEXT, authType: none)
kafka-ui ghcr.io/kafbat/kafka-ui:v1.5.0 localhost:8081 open UI (dev only)
Vault hashicorp/vault:1.21.4 localhost:8200 root token learnstack-dev-root-token
Dapr placement daprio/placement:1.17.7 in-cluster only (sidecars reach it over the compose network) —
Dapr sidecar (api) daprio/daprd:1.17.7 localhost:3500 (HTTP), localhost:50001 (gRPC) —
APISIX apache/apisix:3.16.0-debian localhost:9080 (HTTP), localhost:9443 (HTTPS), localhost:9091 (metrics) none (file-driven standalone — no Admin API)

Configs:

  • Kafka runs in KRaft mode (no ZooKeeper); cluster id is pinned so the log dir survives restarts without re-format. Only the in-cluster PLAINTEXT://kafka:9092 listener is advertised; host-side tools (kcat, kafka-topics from the workstation) will resolve the bootstrap address as kafka:9092, and no host port is published at all. Use kafka-ui (127.0.0.1:8081) for workstation-side browsing — Phase 01 packet 7 shipped that as the canonical workstation path. An EXTERNAL listener for host-side kcat / kafka-topics is a Phase 11 production-hardening item.
  • Vault runs in -dev mode with the root token baked in — production runs HA + auto-unseal + AppRole.
  • Dapr components live under infra/dapr/components/ (pubsub-kafka.yaml, statestore-redis.yaml, secretstore-vault.yaml); runtime config at infra/dapr/config/dapr-config.yaml. The sidecar is wired to call back to host.docker.internal:5080 via the -app-channel-address flag (daprd's default 127.0.0.1 would resolve inside the sidecar container and break subscription deliveries). See ../dapr/README.md for the IEventBus / ICacheService / ISecretProvider consumption pattern.
  • APISIX runs in file-driven standalone mode (deployment.role: data_plane) per ADR-0015 — no etcd, no Admin API, no companion dashboard. Main config at infra/apisix/config.yaml; route table at infra/apisix/apisix.yaml. See ../apisix/README.md for the plugin chain, route table walk-through, and the /api/internal/* mTLS-via-SSL-object placeholder reserved for Phase 02c.

The .NET API host runs OUTSIDE the compose network during active dev; both the Dapr sidecar and APISIX target host.docker.internal:5080 so they can reach the workstation-local dotnet run process. The host.docker.internal:host-gateway alias is wired via a YAML anchor in dev.yml so Linux developers don't need a manual override.

# Repo-root orchestrator (preferred):
make dev                                            # 7 services — the daily loop
make dev-gated                                      # all 14, gated ones included
make ps                                             # confirm healthchecks pass
make down                                           # stop, keep volumes
make clean                                          # stop, wipe local data

# Owned launcher equivalents when `make` is unavailable:
node scripts/compose.mjs selected up -d
node scripts/compose.mjs selected --profile gated up -d
node scripts/compose.mjs selected --profile '*' ps
node scripts/compose.mjs selected --profile '*' down
node scripts/compose.mjs selected --profile '*' down -v

--profile '*' on every teardown is not tidiness. Measured: docker compose down without it LEAVES a running profiled container behind — down -v too, and --remove-orphans does not help, because a profiled service is not an orphan, merely unselected. Verified against this stack: after make dev-gated, a profile-less down left exactly the seven gated containers running while make ps would have reported the stack down. The make targets all carry it.

The reverse direction is a harder failure and the reason no default service may ever depends_on a gated one: measured, that combination is not a warning but a whole-project validation error — config, up, down and ps all refuse to run, not just the service involved. Today every edge into a gated service comes from another gated service, and it has to stay that way.

e2e.yml — end-to-end overlay

Layered on top of dev.yml to swap durable named volumes for tmpfs. By default, make e2e-up starts the same seven services as make dev, so Postgres, SeaweedFS and Meilisearch start clean; the Valkey and Kafka overrides are conditional because those services remain behind COMPOSE_PROFILES=gated. Images, ports, and credentials are identical to dev — only the operational posture (data persistence + Mailpit retention) changes.

make e2e-up                                         # tmpfs-backed stack up
node scripts/compose.mjs e2e --profile gated up -d  # explicit gated selection
make e2e-down                                       # stop; tmpfs evaporates

# Owned launcher equivalents when `make` is unavailable:
node scripts/compose.mjs e2e up -d
node scripts/compose.mjs e2e --profile gated up -d

P02d-7's isolated demo lifecycle uses this overlay with a unique project and private configuration. The delivered Playwright library walkthrough covers nine seeded product pages, followed by 27 Lighthouse audits over the same production API/build/database with its Keycloak stopped. From a fresh checkout without root .env, web .env.local or artifacts/public-demo:

(cd frontend && pnpm install --frozen-lockfile)
(cd frontend && pnpm exec playwright install --with-deps chromium)
make demo DEMO_MODE=ci

Fixed ports must be free. The lifecycle owns disposable TLS/configuration, certificate-specific browser trust and cleanup, without modifying system hosts or trust. Review the sanitized artifacts/public-demo/receipt.json, all 27 JSON/HTML report pairs and browser screenshots; proof and cleanup must both pass. See Running tests locally for the complete workflow and branch protection for actual required-check activation. Local success alone does not establish it. Human make demo retains manual hosts/CA/leaf setup and persistent local data.

The full Playwright Test/axe suite remains Phase 06. Explicit Compose selection ignores ambient COMPOSE_* overrides; use an explicit --profile gated for that opt-in. Host ports remain fixed, so a foreign stack/listener is refused rather than stopped.

Dev credentials are dev credentials

The shared credentials above are checked into the repo intentionally — they are only acceptable in Development deployment mode. Production secrets come from Vault via ISecretProvider (Standards 12 § Secrets Management; Standards 20). Do not reuse these strings anywhere except local Docker.

Tenant isolation in SeaweedFS S3

Tenant isolation in object storage is enforced by key prefix ({tenant_id}/...), never bucket-per-tenant — see Standards 12 § Object Storage Operations and docs/architecture/16-media-pipeline.md. A single bucket per environment is created at first use by the IStorageProvider adapter. The rule is backend-independent — it applied to MinIO, it applies to SeaweedFS, it will apply to any future S3-compatible swap-in.

See ../seaweedfs/README.md for the SeaweedFS- specific dev access surface (filer UI, S3 identity config, re-seed).

What this file deliberately does NOT bring up yet

Phase 01 is complete; the remaining deferrals belong to later phases and NOT to this compose stack:

  • The .NET API host (LearnStack.Api) runs outside the compose network via the production make demo supervisor or make public-api on the workstation. Moving it inside compose is a Phase 11 (production hardening) decision — the dapr-sidecar-api service is already pointed at host.docker.internal:5080 so the swap is a one-line upstream change.
  • livekit-egress (recording / consent) — Phase 08c.
  • OpenTelemetry Collector — Phase 11.
  • Production-grade Vault (HA + auto-unseal + AppRole) — Phase 11.