Skip to content

Commit 63fb37a

Browse files
authored
feat(demo): self-refreshing console demo + Resources nav grouping (#670)
Two changes. ## Self-refreshing demo The mocked `/demo/` console shipped as a prebuilt bundle. This adds its source as a small overlay on `cozystack-ui` (`demo-src/`: the mock layer, MSW worker, smoke test, and patches to `main.tsx`/`vite.config`/manifests) plus `demo-src/build.sh`, which clones upstream fresh, applies the overlay, **smoke-checks** a build (Playwright walks every sidebar/tab screen; fails on any un-mocked Kubernetes call or page error), and regenerates `static/demo`. `.github/workflows/demo-refresh.yml` runs that weekly and opens a PR when the demo changes — using the built-in `GITHUB_TOKEN`, no fork and no external secrets. This repo is public, so the run is free. Needs **Settings → Actions → General → Allow GitHub Actions to create and approve pull requests** enabled once. (`static/demo` itself is unchanged here — the rebuild reproduces the current bundle byte-for-byte.) ## Resources nav grouping The top nav had grown to seven items and wrapped. OSS Health, Community and Enterprise support fold into a single **Resources** dropdown, leaving Docs, Compliance, Resources, Live Demo and GitHub on the top row.
2 parents 87f784a + c6eee80 commit 63fb37a

43 files changed

Lines changed: 17123 additions & 9 deletions

Some content is hidden

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

‎.github/workflows/demo-refresh.yml‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Rebuilds the mocked console demo (static/demo) from upstream cozystack-ui and
2+
# opens a PR with the result. Self-contained: the demo overlay lives in
3+
# demo-src/, the build clones upstream fresh, and the PR is opened in THIS repo
4+
# with the built-in GITHUB_TOKEN — no external tokens, no forks.
5+
#
6+
# Requires: Settings → Actions → General → "Allow GitHub Actions to create and
7+
# approve pull requests" (enabled once). This repo is public, so Actions
8+
# minutes are free.
9+
10+
name: Refresh console demo
11+
12+
on:
13+
workflow_dispatch:
14+
schedule:
15+
- cron: "0 3 * * 1" # Mondays 03:00 UTC
16+
17+
concurrency:
18+
group: demo-refresh
19+
cancel-in-progress: false
20+
21+
permissions:
22+
contents: write
23+
pull-requests: write
24+
25+
jobs:
26+
refresh:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: pnpm/action-setup@v4
31+
- uses: actions/setup-node@v4
32+
with:
33+
node-version: 22
34+
cache: pnpm
35+
36+
- name: Build demo from upstream (with smoke gate)
37+
run: bash demo-src/build.sh main
38+
39+
- name: Open a PR if the demo changed
40+
env:
41+
GH_TOKEN: ${{ github.token }}
42+
run: |
43+
if git diff --quiet -- static/demo; then
44+
echo "No demo changes — nothing to do."
45+
exit 0
46+
fi
47+
BR="demo/refresh-${GITHUB_RUN_ID}"
48+
git config user.name "github-actions[bot]"
49+
git config user.email "github-actions[bot]@users.noreply.github.com"
50+
git checkout -b "$BR"
51+
git add static/demo
52+
git commit --signoff -m "chore(demo): refresh mocked console demo from cozystack-ui"
53+
git push origin "$BR"
54+
gh pr create --base main --head "$BR" --draft \
55+
--title "chore(demo): refresh mocked console demo" \
56+
--body "Automated rebuild of the /demo/ bundle from the current cozystack-ui. The Playwright smoke check (every sidebar/tab screen, no un-mocked API call or page error) passed on this build. Review the Netlify deploy preview, then merge. Not auto-merged."

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ static/docs/*/cozystack-api/
2727

2828
# Claude Code local settings
2929
.claude/
30+
.demo-build-uidir

‎demo-src/build.sh‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
# Builds the mocked Cozystack console demo into ../static/demo.
3+
#
4+
# The demo is a thin overlay on cozystack/cozystack-ui: a few new files
5+
# (demo/ mock layer, MSW worker, smoke test) plus small patches to main.tsx,
6+
# vite.config and the manifests. This fetches upstream fresh, lays the overlay
7+
# on top, smoke-checks a root build, then produces the /demo/ bundle.
8+
#
9+
# demo-src/build.sh [cozystack-ui-ref] # ref defaults to "main"
10+
# SKIP_SMOKE=1 demo-src/build.sh # regenerate the bundle only
11+
#
12+
set -euo pipefail
13+
14+
REF="${1:-main}"
15+
HERE="$(cd "$(dirname "$0")" && pwd)"
16+
SITE="$(cd "$HERE/.." && pwd)"
17+
WORK="$(mktemp -d)"
18+
trap 'rm -rf "$WORK"' EXIT
19+
UI="$WORK/ui"
20+
21+
echo "==> cloning cozystack-ui @ $REF"
22+
git clone --depth 1 --branch "$REF" https://github.com/cozystack/cozystack-ui.git "$UI"
23+
24+
echo "==> applying demo overlay"
25+
cp -R "$HERE/overlay/." "$UI/"
26+
27+
echo "==> applying patches"
28+
( cd "$UI"
29+
for p in "$HERE"/patches/*.patch; do
30+
echo " $(basename "$p")"
31+
git apply --3way "$p" || { echo "PATCH FAILED: $(basename "$p") — upstream drifted, needs a human"; exit 3; }
32+
done )
33+
34+
echo "==> installing deps"
35+
corepack enable >/dev/null 2>&1 || true
36+
( cd "$UI" && pnpm install --frozen-lockfile=false )
37+
38+
if [ "${SKIP_SMOKE:-0}" != "1" ]; then
39+
echo "==> smoke: root build + walk every screen"
40+
( cd "$UI"
41+
VITE_DEMO=1 DEMO_BASE_PATH=/ pnpm --filter @cozystack/console build
42+
cp apps/console/dist/index.html apps/console/dist/404.html
43+
PW_FLAGS=""; [ "${CI:-}" = "true" ] && PW_FLAGS="--with-deps"
44+
pnpm --filter @cozystack/console exec playwright install $PW_FLAGS chromium
45+
SMOKE_DIST="$UI/apps/console/dist" node apps/console/demo-smoke.mjs )
46+
fi
47+
48+
echo "==> building demo (base /demo/)"
49+
( cd "$UI"
50+
VITE_DEMO=1 DEMO_BASE_PATH=/demo/ pnpm --filter @cozystack/console build
51+
cp apps/console/dist/index.html apps/console/dist/404.html )
52+
53+
echo "==> publishing to static/demo"
54+
rm -rf "$SITE/static/demo"
55+
mkdir -p "$SITE/static/demo"
56+
cp -R "$UI/apps/console/dist/." "$SITE/static/demo/"
57+
echo "==> done: $(find "$SITE/static/demo" -type f | wc -l) files in static/demo"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Demo smoke check for the mocked console. Serves nothing itself — point it at
2+
// a running static server of the VITE_DEMO build (SPA fallback required):
3+
//
4+
// VITE_DEMO=1 pnpm --filter @cozystack/console build
5+
// cp apps/console/dist/index.html apps/console/dist/404.html
6+
// (serve apps/console/dist on $SMOKE_BASE with SPA fallback)
7+
// node apps/console/demo-smoke.mjs
8+
//
9+
// It walks every sidebar/tab destination reachable from the three top sections,
10+
// visits each, and fails on any un-mocked Kubernetes call (4xx/5xx to /api or
11+
// /apis), any page error. Exit code is non-zero on
12+
// failure so CI can gate a deploy on it.
13+
14+
import { chromium } from "@playwright/test"
15+
import http from "node:http"
16+
import fs from "node:fs"
17+
import path from "node:path"
18+
19+
// Self-contained: serve the built demo (SPA fallback) so CI just runs
20+
// VITE_DEMO=1 pnpm --filter @cozystack/console build && node demo-smoke.mjs
21+
const DIST = process.env.SMOKE_DIST || "dist"
22+
const TYPES = { ".html":"text/html", ".js":"text/javascript", ".css":"text/css", ".json":"application/json", ".svg":"image/svg+xml", ".ico":"image/x-icon", ".woff2":"font/woff2", ".png":"image/png" }
23+
const server = http.createServer((req, res) => {
24+
const url = req.url.split("?")[0]
25+
let file = path.join(DIST, url)
26+
if (!fs.existsSync(file) || fs.statSync(file).isDirectory()) file = path.join(DIST, "index.html")
27+
res.setHeader("Content-Type", TYPES[path.extname(file)] || "application/octet-stream")
28+
fs.createReadStream(file).pipe(res)
29+
})
30+
await new Promise((r) => server.listen(0, r))
31+
const PORT = server.address().port
32+
33+
const BASE = `http://localhost:${PORT}`
34+
const ENTRIES = ["/marketplace", "/console", "/admin/capacity/cluster"]
35+
36+
// Deliberately un-mocked, handled gracefully by the app — not failures.
37+
const ALLOWED_404 = [
38+
"cozy-dashboard-console-config", // config configmap, swallowed to {}
39+
"buckets/cozy-backups", // optional backup bucket
40+
]
41+
42+
const browser = await chromium.launch()
43+
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
44+
45+
const badApi = new Set()
46+
const pageErrors = []
47+
page.on("response", (r) => {
48+
const u = new URL(r.url()).pathname
49+
if (!/^\/(api|apis)\b/.test(u) && !u.startsWith("/api/") && !u.startsWith("/apis/")) return
50+
if (r.status() < 400) return
51+
if (ALLOWED_404.some((a) => u.includes(a))) return
52+
badApi.add(`${r.status()} ${u}`)
53+
})
54+
page.on("pageerror", (e) => pageErrors.push(String(e).slice(0, 160)))
55+
56+
const routes = new Set(ENTRIES)
57+
for (const entry of ENTRIES) {
58+
await page.goto(BASE + entry, { waitUntil: "domcontentloaded" })
59+
await page.waitForTimeout(1500)
60+
for (const href of await page
61+
.locator("aside a, nav a, [role=tablist] a, a[href^='/console'], a[href^='/admin'], a[href^='/marketplace']")
62+
.evaluateAll((as) => as.map((a) => a.getAttribute("href"))))
63+
if (href && href.startsWith("/") && !href.startsWith("//")) routes.add(href)
64+
}
65+
66+
console.log(`\n########## visiting ${routes.size} destinations\n`)
67+
for (const route of [...routes].sort()) {
68+
await page.goto(BASE + route, { waitUntil: "domcontentloaded" })
69+
await page.waitForTimeout(1200)
70+
}
71+
// This console has no distinct "not found" screen (an unknown route just
72+
// renders the shell), so a broken screen shows up as an un-mocked API call or
73+
// a page error, both collected above — not as body text.
74+
75+
await browser.close()
76+
server.close()
77+
78+
const fail = badApi.size || pageErrors.length
79+
console.log("un-mocked API calls:", badApi.size ? [...badApi] : "none")
80+
console.log("page errors:", pageErrors.length ? pageErrors : "none")
81+
console.log(fail ? "\nSMOKE FAILED" : "\nsmoke OK")
82+
process.exit(fail ? 1 : 0)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { setupWorker } from "msw/browser"
2+
import { handlers } from "./handlers.ts"
3+
4+
// Запускается только в demo-сборке (VITE_DEMO=1). unhandled-запросы пропускаем
5+
// молча — часть путей k8s UI может дёргать опционально.
6+
export async function startDemo() {
7+
const worker = setupWorker(...handlers)
8+
// worker + его scope должны жить под base-путём (напр. /demo/), иначе на
9+
// под-путях моки не перехватываются.
10+
await worker.start({
11+
onUnhandledRequest: "bypass",
12+
quiet: true,
13+
serviceWorker: { url: `${import.meta.env.BASE_URL}mockServiceWorker.js` },
14+
})
15+
}

‎demo-src/overlay/apps/console/src/demo/fixtures/apis-discovery.json‎

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

‎demo-src/overlay/apps/console/src/demo/fixtures/applicationdefinitions.json‎

Lines changed: 4604 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"apiVersion": "v1", "items": [{"apiVersion": "backups.cozystack.io/v1alpha1", "kind": "BackupClass", "metadata": {"creationTimestamp": "2026-08-12T10:14:33Z", "generation": 1, "labels": {"app.kubernetes.io/managed-by": "Helm", "helm.toolkit.fluxcd.io/name": "backupstrategy-controller", "helm.toolkit.fluxcd.io/namespace": "cozy-backup-controller"}, "name": "cozy-default", "resourceVersion": "38140", "uid": "2cf068c8-bbcc-4511-b829-87dfb2edefd8"}, "spec": {"strategies": [{"application": {"apiGroup": "apps.cozystack.io", "kind": "Postgres"}, "strategyRef": {"apiGroup": "strategy.backups.cozystack.io", "kind": "CNPG", "name": "cozy-default-cnpg"}}, {"application": {"apiGroup": "apps.cozystack.io", "kind": "MariaDB"}, "strategyRef": {"apiGroup": "strategy.backups.cozystack.io", "kind": "MariaDB", "name": "cozy-default-mariadb"}}, {"application": {"apiGroup": "apps.cozystack.io", "kind": "Etcd"}, "strategyRef": {"apiGroup": "strategy.backups.cozystack.io", "kind": "Etcd", "name": "cozy-default-etcd"}}, {"application": {"apiGroup": "apps.cozystack.io", "kind": "ClickHouse"}, "strategyRef": {"apiGroup": "strategy.backups.cozystack.io", "kind": "Altinity", "name": "cozy-default-altinity"}}, {"application": {"apiGroup": "apps.cozystack.io", "kind": "VMInstance"}, "strategyRef": {"apiGroup": "strategy.backups.cozystack.io", "kind": "Velero", "name": "cozy-default-velero-vminstance"}}, {"application": {"apiGroup": "apps.cozystack.io", "kind": "VMDisk"}, "strategyRef": {"apiGroup": "strategy.backups.cozystack.io", "kind": "Velero", "name": "cozy-default-velero-vmdisk"}}]}}], "kind": "List", "metadata": {"resourceVersion": ""}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"apiVersion": "v1",
3+
"items": [],
4+
"kind": "List",
5+
"metadata": {
6+
"resourceVersion": ""
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"apiVersion": "v1",
3+
"items": [],
4+
"kind": "List",
5+
"metadata": {
6+
"resourceVersion": ""
7+
}
8+
}

0 commit comments

Comments
 (0)