M-MIG-7 (ERP/02, decisions 3, 12, 13, 18):
- migration 0004: subscriptions, usage_events, erp_outbox,
erp_webhook_receipts, licences; tenants.status_changed_at (trigger)
- internal/erp: Frappe REST client (Customer upsert by tenant_id,
Subscription list, Usage Record, Lead) + webhook signing/verification
- internal/erpmock + cmd/erpmock: ERPNext stand-in for staging —
/api/resource/{doctype} with token auth, request log, /_mock/fire/*
triggers that mutate docs and deliver signed webhooks
- POST /v1/internal/erp/webhook (HMAC, idempotent by event id):
sales_order.submit → subscriptions + entitlements (SKU → product/plan,
add-on SKUs → limits) + active; sales_invoice.overdue → warning /
restricted / halted by days overdue; payment_entry.submit → active;
subscription.cancel → halted
- outbox worker (customer.upsert on tenant create, usage.record,
lead.create on catalog request) with backoff; reconcile job mirrors
ERP subscriptions and applies the time-based ladder (trial expiry,
warning→restricted 14 d, restricted→halted 30 d, halted→archived 30 d)
- POST/GET /v1/usage/events (idempotency_key, batch), GET
/v1/subscriptions, GET /v1/internal/erp/status, POST
/v1/internal/erp/reconcile
- CLI licences: Ed25519 signer (LICENCE_SIGNING_KEY), POST /v1/licences
(entitlement-gated, expiry capped by the entitlement), GET
/.well-known/licence-keys.json, POST /v1/licences/heartbeat (grace
ladder, renewal past half-life, revoked), revoke/list
- authn Principal carries tenant-context claims (user tokens scope usage
and licence calls to their own tenant); authz groups usage(.read)
- tests for every path (both stores), erpmock, erp client, licence pkg;
openapi.yaml + README updated; Dockerfile ships /erpmock
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
24 lines
940 B
Docker
24 lines
940 B
Docker
# Multi-stage build for tenant-registry.
|
|
# Produces two binaries:
|
|
# /tenant-registry — long-running API server
|
|
# /migrate — one-shot schema migrator (Orca init container in prod)
|
|
# /erpmock — ERPNext stand-in for staging (decision 18; cmd/erpmock)
|
|
|
|
FROM golang:1.25-alpine AS build
|
|
WORKDIR /src
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
COPY . .
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/tenant-registry ./cmd/server && \
|
|
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/migrate ./cmd/migrate && \
|
|
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/erpmock ./cmd/erpmock
|
|
|
|
FROM gcr.io/distroless/static-debian12:nonroot
|
|
WORKDIR /
|
|
COPY --from=build /out/tenant-registry /tenant-registry
|
|
COPY --from=build /out/migrate /migrate
|
|
COPY --from=build /out/erpmock /erpmock
|
|
USER nonroot:nonroot
|
|
EXPOSE 8090
|
|
ENTRYPOINT ["/tenant-registry"]
|