Files
openwork/packaging/docker/Dockerfile.gateway
T
ben 94359f1439 feat(features): roll out features by deployment and organization, with a kill switch (#5702)
* feat(den): declare features once in a registry stored per organization

Adds packages/types/src/den/features.ts as the single place a feature is
declared. Each entry decides, separately for OpenWork Cloud and self-hosted,
whether the feature exists (unavailable / off / on) or is controlled per
organization by platform admins, with a default.

- Storage moves from organization.metadata.capabilities to a new
  organization_feature table (migration 0129 copies existing overrides and
  the old Connect aliases). Better Auth never writes it, so creating an
  organization can no longer turn features on; metadata.capabilities is
  stripped at creation and no longer sent to members. Writes are mirrored
  into metadata for one release so a rollback keeps working.
- den-api reads features only through features.ts (getOrganizationFeatures,
  organizationFeatureEnabled, requireFeature). The three hand-written
  capability helper modules are deleted.
- DEN_DEPLOYMENT (default self_hosted) and DEN_FEATURE_* locks, rendered
  from a generated Helm config.features block with a values schema. A lock
  outranks a stored override.
- /admin schemas and the Den admin panel are generated from the registry,
  with Default / override / locked states and "Use default".
- GET /v1/org adds features; capabilities stays frozen for published clients.
- pnpm features:sync / features:check plus a CI job keep the chart in step
  and reject new DEN_*_ENABLED switches or metadata.capabilities reads.
- add-a-feature skill and an AGENTS.md line: flag first, before feature code.

No behavior change: every existing feature keeps its current default and
stays platform-controlled on both deployments.

* refactor(features): move the registry into its own @openwork/features package

The registry and resolver were runtime logic living in @openwork/types.
They now live in packages/features:

- src/registry.ts: the one file you edit to declare a feature
- src/resolve.ts: precedence rules, env parsing, key schema (pure, no I/O)
- src/resolve.test.ts: node:test coverage of the precedence rules, env
  parsing, key schema and DEN_FEATURE_* names, run in features-check CI

Files import each other through package self-references, so the TypeScript
source runs as-is under Node (verified in the node:22 production image) and
typechecks in every consumer without a build step.

Also adds the package to the den, gateway and den-web Docker images and to
the den-contract CI path filters, and pins azure/setup-helm to a commit SHA
(Warden finding).

* ci(features): check that Dockerfiles copy every workspace package they need

The den, gateway, den-web and den-gateway images copy workspace packages one
by one for layer caching, and only publish-ee-images builds them, so a missed
COPY line surfaced at release time. scripts/check-docker-workspace-packages.mjs
reads the manifests and Dockerfiles (about 10 ms) and fails when a copied
package.json depends on a workspace package whose package.json is not copied
(pnpm install fails) or a copied source folder imports one at runtime that is
not copied. It runs inside pnpm features:check, and the workflow now also
triggers on Dockerfile, workspace and package.json changes.

* ci(features): name the exact setup-helm version in its pin comment

* feat(features): roll features out by deployment, percentage, organization and kill switch

A feature is no longer "per organization". Each registry entry declares only
what is fixed in code: its subject (organization, or person so signed-out
desktop users are included), the deployments it exists on, and its starting
percentage. Everything else is runtime state, resolved by one function in
@openwork/features, in this order: not part of this deployment, kill switch,
operator lock (DEN_FEATURE_*), organization override, percentage of the
subject (stable FNV-1a bucket; raising it only adds subjects).

- feature_rollout table (migration 0129 now creates it alongside
  organization_feature) holds percentage and kill switch per feature.
- /admin › Features page and GET/PUT /v1/admin/features change them without
  a deploy; organization rows show why a feature is on or off.
- Admin MCP tools den_list_features and den_set_feature_rollout.
- Public GET /v1/features/rollouts for clients that resolve person features
  themselves, including signed-out desktops.
- /v1/org resolves person features for the signed-in member.
- The nine existing features keep today's behaviour: organization subject,
  starting at 100% (install links, Connect) or 0% (the rest).
- Skill, AGENTS.md, Helm comments and README describe the one model;
  features:check asks for a decision on rollouts older than six months
  unless marked permanent.

* refactor(features): drop percentage rollouts; on or off for everyone, per organization, or killed

Removes percentage rollouts and the organization/person subject they needed.
A feature is now rolled out by deployment (fixed in code), on or off for
everyone (/admin, starting from the registry default), per-organization
overrides, operator locks, and the kill switch. feature_rollout stores
enabled and killed; GET /v1/features gives people without an organization
the deployment-wide answer.
2026-10-06 07:38:34 -07:00

48 lines
2.0 KiB
Docker

FROM node:22-bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends g++ make python3 \
&& rm -rf /var/lib/apt/lists/*
RUN corepack enable
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=8791
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml /app/
COPY patches /app/patches
COPY packages/types/package.json /app/packages/types/package.json
COPY packages/features/package.json /app/packages/features/package.json
COPY packages/free-auto/package.json /app/packages/free-auto/package.json
COPY ee/packages/utils/package.json /app/ee/packages/utils/package.json
COPY ee/packages/den-db/package.json /app/ee/packages/den-db/package.json
COPY ee/packages/telemetry-contracts/package.json /app/ee/packages/telemetry-contracts/package.json
COPY ee/packages/telemetry/package.json /app/ee/packages/telemetry/package.json
COPY ee/apps/gateway/package.json /app/ee/apps/gateway/package.json
RUN pnpm install --frozen-lockfile --trust-lockfile
COPY packages/types /app/packages/types
COPY packages/features /app/packages/features
COPY packages/free-auto /app/packages/free-auto
COPY ee/packages/utils /app/ee/packages/utils
COPY ee/packages/den-db /app/ee/packages/den-db
COPY ee/packages/telemetry-contracts /app/ee/packages/telemetry-contracts
COPY ee/packages/telemetry /app/ee/packages/telemetry
COPY ee/apps/gateway /app/ee/apps/gateway
RUN pnpm --dir /app/packages/types run build
RUN pnpm --dir /app/packages/free-auto run build
RUN pnpm --dir /app/ee/packages/utils run build
RUN pnpm --dir /app/ee/packages/den-db run build
RUN pnpm --dir /app/ee/packages/telemetry run build
RUN pnpm --dir /app/ee/apps/gateway run build
EXPOSE 8791
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 CMD node -e "fetch('http://127.0.0.1:' + (process.env.PORT || '8791') + '/health').then((res) => process.exit(res.ok ? 0 : 1)).catch(() => process.exit(1))"
CMD ["node", "--import", "/app/ee/apps/gateway/dist/instrumentation.js", "/app/ee/apps/gateway/dist/server.js"]