Skip to content

[M0.5] Configurable dev stack ports - #26

Merged
samuelmbabhazi merged 2 commits into
mainfrom
fix/m0.5-dev-postgres-port
Nov 3, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
fix/m0.5-dev-postgres-port

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Task

[M0.5] Local dev environment, follow-up. Refs #5

What changed

  • deploy/dev/compose.yml: host ports read SHIPKEEP_DEV_POSTGRES_PORT, SHIPKEEP_DEV_VICTORIALOGS_PORT, SHIPKEEP_DEV_VICTORIAMETRICS_PORT and SHIPKEEP_DEV_REGISTRY_PORT with the previous values as defaults. Still bound to 127.0.0.1.
  • pnpm dev:infra* run Compose with --project-directory . so the root .env (gitignored) is read when present.
  • .env.example documents the four variables; README explains the override.

Why

First real run of the stack on a developer machine: PostgreSQL 5432 was already taken by another local database. The M0.5 PR could not be exercised with Docker at the time; this run closes that gap.

How it was tested

  • pnpm dev:infra with SHIPKEEP_DEV_POSTGRES_PORT=5433 in .env: all four containers healthy (--wait returned), pg_isready accepting connections, VictoriaLogs and VictoriaMetrics /health OK, registry /v2/ HTTP 200.
  • Without .env the defaults are unchanged.

Security considerations

None. Ports stay loopback-only; .env remains ignored by git.

Checklist

  • Acceptance criteria from docs/PLAN.md are met (stack now verified with Docker)
  • Lint and formatting pass
  • Tests: infrastructure configuration, verified by running it
  • No new shell invocation and no new secret exposure path
  • Audit events: not applicable
  • README and .env.example updated

@samuelmbabhazi
samuelmbabhazi merged commit 890e676 into main Nov 3, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/m0.5-dev-postgres-port branch November 3, 2026 11:49
@samuelmbabhazi samuelmbabhazi mentioned this pull request Nov 3, 2026
6 tasks done
samuelmbabhazi added a commit that referenced this pull request Nov 3, 2026
## Task

[M2.1a] API skeleton (first half of M2.1, split recorded in
`docs/PLAN.md`). Refs #20

## What changed

**Domain (`packages/domain`)**
- `Secret<T>`: wraps credentials and renders `[REDACTED]` through
`String()`, template literals, `JSON.stringify`, `util.inspect`; the
value is reachable only via `expose()`. Constant-time `equals`.
TypeScript counterpart of Go `lib/secret` (CLAUDE.md rule 8).
- `DomainError` base (kind + stable `code` + optional details) with
`InvalidInputError`, `NotFoundError`, `ConflictError`. Pure, no
framework imports.

**Control plane (`apps/api`), NestJS 12**
- `platform/config`: zod schema for the environment (`DATABASE_URL`
becomes a `Secret`, ports and URLs validated, every problem reported at
once without echoing values), `AppConfig` typed accessor, `.env` read in
development only.
- `platform/logging`: pino JSON request logs through nestjs-pino. One
line per request with request id (honours a safe `x-request-id`),
method, URL, status, duration. `authorization`, `cookie`, `set-cookie`,
`x-api-key`, join-token headers and token query parameters are redacted;
bodies are never logged; health probes are not logged.
- `platform/http`: global `ProblemDetailsFilter` producing RFC 9457
`application/problem+json` with `type` =
`https://shipkeep.dev/problems/<code>`, `code`, `instance`, `requestId`,
field `errors` for validation. Domain error kinds map to
400/401/403/404/409/412; unknown errors become an opaque 500 (internal
messages never leak). Validation pipe: whitelist, forbid unknown
properties, transform.
- `platform/prisma`: Prisma 7 with the `pg` driver adapter; the
connection string is exposed only into the driver. `ping()` for
readiness. Schema and `prisma.config.ts` in place; the first models
arrive with M2.1b. The generated client is not committed; `pnpm install`
regenerates it.
- `platform/health`: `GET /api/v1/health` (liveness) and `GET
/api/v1/ready` (database probe, 503 problem when down).
- `platform/openapi`: OpenAPI 3.1 document at `/api/v1/openapi.json`,
bearer and session-cookie security schemes, UI at `/api/v1/docs` when
`OPENAPI_UI` is on (default outside production). `helmet` on every
response.
- `bootstrap.ts` builds the app once for `main.ts`, the OpenAPI
generator and the tests.

**Contract and client**
- `apps/api/openapi.json` generated by `pnpm gen:openapi` (document-only
run of the built API, no port, no database). `packages/api-client`
exposes `createShipkeepClient()` over openapi-fetch with types generated
by openapi-typescript (`pnpm gen:api-client`), plus
`isProblemDetails()`. `pnpm gen` runs the whole chain; CI fails on
drift.

**Tooling**
- NestJS 12 is ESM-only, which Jest (CJS) cannot load: the API now tests
with vitest like every other project (swc plugin for decorator
metadata). Jest is removed from the workspace. `pnpm test:integration`
runs `api:test:integration` (vitest, Testcontainers PostgreSQL or
`DATABASE_URL`).
- `@nx/nest` removed (generator only, pinned to Nest <12).

## Why

Every control plane module (identity, fleet, audit...) needs
configuration, logging, error mapping, the database client and the
OpenAPI contract in place first. SPEC section 8 fixes the base path, the
problem-details format and the OpenAPI location.

## How it was tested

- `pnpm nx run-many -t lint typecheck test build`: all 7 projects green.
Unit tests: 13 domain, 15 api (config schema, filter mapping, HTTP
pipeline with security headers, 404 problem, readiness 503, OpenAPI
document and UI), 3 api-client, 86 config-schema, 3 proto-ts.
- `pnpm test:integration`: the API starts against a real PostgreSQL 17
started by Testcontainers and `GET /api/v1/ready` returns
`{"status":"ok","checks":{"database":"ok"}}`.
- `pnpm gen` twice: no drift. `prettier --check`: clean.
- Local `pnpm dev:infra` stack verified earlier today (PR #26).

## Security considerations

- Secrets: `DATABASE_URL` is a `Secret`; the only `expose()` is the
Prisma adapter constructor. Request logs redact credential headers and
never include bodies. Internal errors are not echoed to clients.
- `helmet` defaults; `x-powered-by` removed.
- Validation rejects unknown properties (`forbidNonWhitelisted`).
- No authentication yet (M2.2); the only routes are health, readiness
and the OpenAPI document. The `security-review` label is set because
this PR defines the error, logging and configuration foundations every
later module inherits.

## Checklist

- [x] Acceptance criteria from `docs/PLAN.md` are met and M2.1a is
ticked
- [x] Lint, TS tests, Go tests and `buf lint` pass
- [x] Tests added, including redaction and unknown-property tests
- [x] No new shell invocation in product code (`tools/gen/openapi.mjs`
runs the built API with fixed arguments and carries a justified
`nosemgrep`)
- [x] Audit events: not applicable yet (no state changes; M2.1b adds the
audit writer)
- [x] CLAUDE.md and README updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant