Skip to content

Commit 01addfc

Browse files
build(dashboard): vendor cozystack-ui into the monorepo (#2963)
## What this PR does Moves the `cozystack-ui` console SPA into this monorepo so the UI versions and ships in lockstep with the platform — removing the cross-repo digest-bump PRs and the version drift between the two repositories. The source is vendored at `packages/system/dashboard/images/console/` via `git subtree`, preserving full upstream history. This mirrors the existing in-tree `images/token-proxy/` pattern, and `.helmignore` already excludes `images/*/*` so the source never enters the Helm chart. **Changes** - **Source**: `cozystack-ui` `main` merged under `packages/system/dashboard/images/console/` (history preserved as a merge parent). - **Build**: `packages/system/dashboard/Makefile` builds the console image from the in-tree context instead of cloning the external repo at build time. Dropped `clone-console`/`clean-console` and the `CONSOLE_REPO`/`CONSOLE_BRANCH` variables. The built digest is still pinned into `values.yaml` by `update-values-console` — now in the same commit as the source change rather than a separate follow-up PR. - **CI**: new `.github/workflows/ui-test.yaml` runs pnpm typecheck + unit tests, path-gated to `images/console/**`. The container image continues to build via `make build`. **Verification** - `pnpm install --frozen-lockfile` → `pnpm typecheck` clean → production build produces `dist/`. - 313 unit tests pass. - `helm template` renders; console + token-proxy image references unchanged. **Follow-ups (after merge)** - Archive the standalone `cozystack-ui` repository and redirect contributions here. - Update remaining documentation pointers that reference the old repo path. ### Screenshots N/A — no UI behavior change. This relocates the UI source and rewires the build; the shipped image and digest are unchanged. ### Release note ```release-note build(dashboard): vendor the cozystack-ui console into the monorepo and build it from in-tree source; the shipped image and digest are unchanged for cluster operators ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents a83612b + ea0c0ab commit 01addfc

202 files changed

Lines changed: 24070 additions & 16 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ui-test.yaml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: UI Test
2+
3+
# Typecheck + unit tests for the in-tree console SPA
4+
# (packages/system/dashboard/images/console, vendored from cozystack-ui).
5+
# The container image itself is built by `make build` in the main build job.
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
paths:
12+
- 'packages/system/dashboard/images/console/**'
13+
pull_request:
14+
paths:
15+
- 'packages/system/dashboard/images/console/**'
16+
17+
defaults:
18+
run:
19+
working-directory: packages/system/dashboard/images/console
20+
21+
jobs:
22+
test:
23+
name: Typecheck and test
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Set up pnpm
30+
uses: pnpm/action-setup@v4
31+
with:
32+
# The monorepo root has no package.json; read the pnpm version from
33+
# the console workspace manifest (packageManager field).
34+
package_json_file: packages/system/dashboard/images/console/package.json
35+
36+
- name: Set up Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: 22
40+
cache: pnpm
41+
cache-dependency-path: packages/system/dashboard/images/console/pnpm-lock.yaml
42+
43+
- name: Install dependencies
44+
run: pnpm install --frozen-lockfile
45+
46+
- name: Typecheck
47+
run: pnpm typecheck
48+
49+
- name: Test
50+
run: pnpm test
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
.tmp-cozystack-ui
21
images/token-proxy/token-proxy
2+
images/*.json

‎packages/system/dashboard/Makefile‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ include ../../../hack/common-envs.mk
55
include ../../../hack/package.mk
66

77
.PHONY: image image-console image-token-proxy test test-go test-helm
8-
.PHONY: clone-console build-console update-values-console clean-console
8+
.PHONY: build-console update-values-console
99
.NOTPARALLEL: image
1010

1111
test: test-helm test-go
@@ -18,18 +18,13 @@ test-go:
1818

1919
image: image-console image-token-proxy
2020

21-
CONSOLE_REPO ?= https://github.com/cozystack/cozystack-ui.git
22-
CONSOLE_BRANCH ?= main
23-
24-
image-console: clone-console build-console update-values-console clean-console
25-
26-
clone-console:
27-
rm -rf .tmp-cozystack-ui
28-
git clone --depth 1 --branch $(CONSOLE_BRANCH) $(CONSOLE_REPO) .tmp-cozystack-ui
21+
image-console: build-console update-values-console
2922

23+
# Console source lives in-tree under images/console (vendored from the former
24+
# cozystack-ui repo). Build from that context directly — no clone step.
3025
build-console:
31-
docker buildx build .tmp-cozystack-ui \
32-
--file .tmp-cozystack-ui/Containerfile \
26+
docker buildx build images/console \
27+
--file images/console/Containerfile \
3328
--provenance false \
3429
--builder=$(BUILDER) \
3530
--platform=linux/amd64 \
@@ -38,15 +33,13 @@ build-console:
3833
--metadata-file images/console.json \
3934
--build-arg APP_VERSION=$(COZYSTACK_VERSION) \
4035
--push=$(PUSH) \
41-
--label "org.opencontainers.image.source=https://github.com/cozystack/cozystack-ui" \
36+
--label "org.opencontainers.image.source=https://github.com/cozystack/cozystack" \
4237
--load=$(LOAD)
4338

4439
update-values-console:
4540
IMAGE="$(REGISTRY)/cozystack-ui:$(IMAGE_TAG)@$$(yq e '."containerimage.digest"' images/console.json -r)" \
4641
yq -i '.console.image = strenv(IMAGE)' values.yaml
47-
48-
clean-console:
49-
rm -rf .tmp-cozystack-ui images/console.json
42+
rm -f images/console.json
5043

5144
image-token-proxy:
5245
docker buildx build images/token-proxy \
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
dist
3+
.DS_Store
4+
*.log
5+
.env
6+
.env.local
7+
.vite
8+
.turbo
9+
tsconfig.tsbuildinfo
10+
**/tsconfig.tsbuildinfo
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
auto-install-peers=true
2+
strict-peer-dependencies=false
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# cozystack-ui
2+
3+
Cozystack Marketplace + Console — a **pure SPA that talks directly to the
4+
Kubernetes API**. No BFF, no backend, no codegen. UI entities are discovered
5+
at runtime from `ApplicationDefinition` CRDs in the cluster.
6+
7+
## Development model
8+
9+
This UI is **developed entirely by Claude**. There is no human author writing
10+
features in parallel. Every file in this repo was produced through a Claude
11+
session and every change should be reviewable as a small, self-contained PR.
12+
Implications:
13+
14+
- Keep modules small and obvious. The next Claude session has no tribal
15+
knowledge — only what's in code, tests, and this file.
16+
- Prefer convention over abstraction. Three similar widgets are better than a
17+
premature factory.
18+
- If you're tempted to write a comment explaining *what* the code does, rename
19+
things instead. Only comment the non-obvious *why* (constraints, k8s quirks,
20+
workarounds) — and keep it to one short line.
21+
- Don't leave half-finished scaffolding behind. If you start a refactor and
22+
bail, revert it.
23+
24+
## Stack
25+
26+
- **pnpm workspace** — `apps/console` is the SPA; `packages/{k8s-client,ui,types}` are workspace deps.
27+
- **React 19 + Vite 8 + TypeScript ~6.0** with `module: esnext`,
28+
`moduleResolution: bundler`, `verbatimModuleSyntax`, `allowImportingTsExtensions`,
29+
`erasableSyntaxOnly`, `noUnusedLocals`, `noUnusedParameters`.
30+
- **Tailwind 4** via `@tailwindcss/vite` + **Base UI** (`@base-ui/react`) for primitives.
31+
- **React Query** for caching; custom watch layer streams chunked JSON events.
32+
- **RJSF** (`@rjsf/core` + `validator-ajv8`) for application config forms.
33+
- **Vitest + jsdom + @testing-library/react** for tests.
34+
- **Monaco** for YAML view, **noVNC** for the VM console tab.
35+
36+
## Dev loop
37+
38+
```sh
39+
pnpm install
40+
kubectl proxy --port 8001 # required — terminates TLS, proxies /api + /apis
41+
pnpm dev # http://localhost:3001
42+
pnpm typecheck # tsc --noEmit across the workspace
43+
pnpm test # vitest run
44+
pnpm lint # eslint
45+
pnpm build # tsc check + vite build into apps/console/dist
46+
```
47+
48+
The Vite dev server proxies `/api`, `/apis`, and `/k8s` (VNC WebSocket prefix)
49+
to `kubectl proxy`. In production, nginx (see `Containerfile`) proxies the
50+
same paths to `kubernetes.default.svc` using the pod's service-account token.
51+
52+
## Code style
53+
54+
- **No semicolons.** Match the surrounding code — every file in the tree
55+
follows this. Don't reformat existing files.
56+
- **Always import with explicit `.ts` / `.tsx` extensions** — required by
57+
`allowImportingTsExtensions` and the way packages re-export.
58+
- **`import type { ... }` for type-only imports** — required by `verbatimModuleSyntax`.
59+
- **Path aliases**: `@/` → `apps/console/src/`, plus the workspace deps
60+
`@cozystack/{k8s-client,ui,types}`. Don't reach into `../../packages/...`.
61+
- **No `any`.** Use `unknown` and narrow, or a precise local interface.
62+
`as any` casts in older files are debt to pay down, not a pattern to extend.
63+
- **No new top-level deps without a reason in the PR description.** This is a
64+
static SPA that ships to every Cozystack cluster — bundle size matters.
65+
66+
## Architecture rules
67+
68+
1. **Talk to the Kubernetes API directly.** Use `@cozystack/k8s-client`
69+
(`useK8sList`, `useK8sGet`, `useK8sCreate`, `useK8sUpdate`, `useK8sDelete`).
70+
Don't add a backend, server route, or proxy of your own.
71+
2. **Discover, don't hardcode.** The marketplace, sidebar, detail pages, and
72+
forms are all driven from `ApplicationDefinition` resources
73+
(`cozystack.io/v1alpha1`). Adding a new application kind to Cozystack
74+
should require zero UI changes — if it doesn't, fix the generic path
75+
instead of adding a special case.
76+
3. **`useK8sList` already does watches.** It seeds with a LIST then upgrades
77+
to a chunked-encoding WATCH against the same `resourceVersion`. Don't
78+
poll. Don't add `refetchInterval`. If you need a one-shot, pass
79+
`{ watch: false }`.
80+
4. **Tenant scoping.** Most resources live in `tenant-<name>` namespaces.
81+
Pull the active tenant from `useTenantContext()` — never read the
82+
namespace from a URL param or guess it.
83+
5. **Auth.** In production the SPA sits behind oauth2-proxy. The client
84+
relies on cookies forwarded by nginx, and `/oauth2/userinfo` returns the
85+
logged-in user. There is no token handling in the SPA itself.
86+
87+
## Forms (RJSF) pipeline
88+
89+
Every application's configure form is built from
90+
`ApplicationDefinition.spec.application.openAPISchema` (a JSON-encoded OpenAPI
91+
schema). The pipeline in `apps/console/src/components/SchemaForm.tsx`:
92+
93+
1. `sanitizeSchema` strips Kubernetes-specific extensions
94+
(`x-kubernetes-int-or-string`, `x-kubernetes-preserve-unknown-fields`) and
95+
renames `"Chart Values"` → `"Parameters"`.
96+
2. `keysOrderToUiSchema` reads `spec.dashboard.keysOrder` and emits per-level
97+
`ui:order` arrays.
98+
3. A chain of `addXxxWidgets(schema, uiSchema)` walks the schema and binds
99+
widgets:
100+
- any field carrying the `x-cozystack-options` schema keyword → `DynamicOptionsWidget`, a runtime dropdown populated from the cluster's `Option` resource (`core.cozystack.io`) keyed by the keyword's `source`; `addDynamicOptionWidgets` (`lib/dynamic-options.ts`) recurses into `properties`, array `items` and `additionalProperties`, and replaces the former field-name-bound `StorageClassWidget` / `BackupClassWidget` / `VMDiskWidget`.
101+
- object with `additionalProperties: <schema>` → `AdditionalPropertiesField`
102+
- credential-shaped fields (`password`, `*token`, `*accessKey`, …) →
103+
`SensitiveStringWidget` — see `lib/sensitive-fields.ts` and its tests for
104+
the exact matching rules.
105+
4. Defaults are emitted to the parent once per schema via `getDefaultFormState`
106+
so the first submit always carries a populated spec.
107+
108+
When you add a new widget binding:
109+
110+
- Add it to the chain in `SchemaForm.tsx` in a deterministic order.
111+
- Walk `properties` *and* `items` for arrays. Do **not** walk
112+
`oneOf`/`anyOf`/`allOf` unless a real chart needs it — there's a
113+
"pin broken behaviour" test that documents this gap intentionally.
114+
- Don't mutate the input `uiSchema`. Return a new object. There are tests
115+
asserting this.
116+
117+
## Project layout
118+
119+
```
120+
apps/console/
121+
src/
122+
App.tsx, main.tsx # entry + routing
123+
routes/ # one file per top-level page
124+
detail/ # ApplicationDetailPage + tabs (Overview, Workloads, …)
125+
components/ # page-level components, form widgets, command palette
126+
lib/ # app-definitions, tenant-context, sensitive-fields, …
127+
hooks/
128+
test/setup.ts # vitest + jest-dom + manual RTL cleanup
129+
packages/
130+
k8s-client/ # K8sClient (list/get/create/update/patch/delete/watch) + React Query hooks
131+
ui/ # AppShell, Sidebar, Header, Button, StatusBadge, Spinner, Dropdown, Section
132+
types/ # ApplicationDefinition, ApplicationInstance, Tenant, TenantNamespace, group/version constants
133+
Containerfile # multi-stage build → nginx-unprivileged on :8080
134+
.github/workflows/ # test.yaml (typecheck + vitest), build.yaml (multi-arch image to ghcr)
135+
```
136+
137+
## Testing
138+
139+
- Tests live next to the code they cover (`SensitiveStringWidget.test.tsx`,
140+
`sensitive-fields.test.ts`). Co-locate; don't centralise.
141+
- `apps/console/test/setup.ts` wires `@testing-library/jest-dom` and registers
142+
`afterEach(cleanup)` manually — vitest is **not** run with `globals: true`,
143+
so `expect`, `describe`, etc. must be imported explicitly.
144+
- When you fix a subtle widget bug, write the test first. The
145+
`addSensitiveStringWidgets` suite is the model: small focused cases, one
146+
invariant per `it`, and a "pin broken behaviour" group for known gaps.
147+
148+
## CI
149+
150+
`test.yaml` runs `pnpm typecheck` + `pnpm test` on every push and PR.
151+
`build.yaml` builds and pushes a multi-arch image to
152+
`ghcr.io/<repo>` on `main` and `v*` tags. Don't add other workflows without a
153+
clear reason — keep CI fast.
154+
155+
## What goes in a good PR here
156+
157+
- One feature or one fix per branch. Small enough that a human can review it
158+
in a few minutes without context.
159+
- A title that follows the conventional-commit style already in use
160+
(`feat(console): …`, `fix(forms): …`, `fix(external-ips): …`).
161+
- If you touched form logic, add or update tests.
162+
- If you added a new application kind to the sidebar/marketplace, double-check
163+
that the generic path handles it instead of special-casing.
164+
- Don't bundle drive-by reformatting with a behavioural change.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
ARG NODE_VERSION=22-alpine
2+
3+
# Stage 1: Install dependencies and build
4+
FROM node:${NODE_VERSION} AS builder
5+
6+
ARG APP_VERSION
7+
ENV VITE_APP_VERSION=${APP_VERSION}
8+
9+
RUN corepack enable && corepack prepare pnpm@latest --activate
10+
11+
WORKDIR /src
12+
13+
# Workspace manifests first for cached installs.
14+
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
15+
COPY apps/console/package.json apps/console/
16+
COPY packages/ui/package.json packages/ui/
17+
COPY packages/types/package.json packages/types/
18+
COPY packages/k8s-client/package.json packages/k8s-client/
19+
20+
RUN pnpm install --frozen-lockfile
21+
22+
COPY apps/console/ apps/console/
23+
COPY packages/ packages/
24+
COPY tsconfig.base.json ./
25+
26+
RUN pnpm --filter @cozystack/console build
27+
28+
# Stage 2: Serve with nginx
29+
FROM nginxinc/nginx-unprivileged:1.29-alpine
30+
31+
COPY --from=builder /src/apps/console/dist /usr/share/nginx/html
32+
33+
COPY <<'EOF' /etc/nginx/conf.d/default.conf
34+
map $http_upgrade $connection_upgrade {
35+
default upgrade;
36+
'' close;
37+
}
38+
39+
server {
40+
listen 8080 default_server;
41+
listen [::]:8080 default_server;
42+
server_name _;
43+
44+
root /usr/share/nginx/html;
45+
index index.html;
46+
47+
# Kubernetes API proxy for both core and aggregated groups.
48+
# Chunked-encoding watches require proxy_buffering off and a long timeout.
49+
location /apis {
50+
proxy_http_version 1.1;
51+
proxy_buffering off;
52+
proxy_set_header Upgrade $http_upgrade;
53+
proxy_set_header Connection $connection_upgrade;
54+
proxy_set_header X-Forwarded-Proto $scheme;
55+
proxy_set_header Host kubernetes.default.svc;
56+
proxy_read_timeout 86400s;
57+
proxy_send_timeout 86400s;
58+
proxy_pass https://kubernetes.default.svc:443;
59+
}
60+
61+
location /api {
62+
proxy_http_version 1.1;
63+
proxy_buffering off;
64+
proxy_set_header Upgrade $http_upgrade;
65+
proxy_set_header Connection $connection_upgrade;
66+
proxy_set_header X-Forwarded-Proto $scheme;
67+
proxy_set_header Host kubernetes.default.svc;
68+
proxy_read_timeout 86400s;
69+
proxy_send_timeout 86400s;
70+
proxy_pass https://kubernetes.default.svc:443;
71+
}
72+
73+
# /k8s prefix for VNC WebSocket compatibility
74+
location /k8s/ {
75+
proxy_http_version 1.1;
76+
proxy_buffering off;
77+
proxy_set_header Upgrade $http_upgrade;
78+
proxy_set_header Connection $connection_upgrade;
79+
proxy_set_header X-Forwarded-Proto $scheme;
80+
proxy_set_header Host kubernetes.default.svc;
81+
proxy_read_timeout 86400s;
82+
proxy_send_timeout 86400s;
83+
rewrite /k8s/(.*) /$1 break;
84+
proxy_pass https://kubernetes.default.svc:443;
85+
}
86+
87+
# SPA fallback: serve index.html for all frontend routes.
88+
location / {
89+
try_files $uri $uri/ /index.html;
90+
}
91+
92+
location /healthcheck {
93+
access_log off;
94+
return 200 "Healthy\n";
95+
}
96+
}
97+
EOF
98+
99+
EXPOSE 8080

0 commit comments

Comments
 (0)