From 07222aa83c370de455f8095cb38c0c1751214fe3 Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Thu, 12 Nov 2026 10:09:32 +0000 Subject: [PATCH 1/2] Render GitOps Reverser docs at /reverser The operator repo stays the source of truth: README, quickstart and configuration are rendered unedited from the submodule, now at v0.56.0. Co-Authored-By: Claude Opus 5.5 --- README.md | 19 +++++ astro.config.mjs | 2 + external/gitops-reverser | 2 +- package-lock.json | 1 + package.json | 3 + public/llms.txt | 1 + scripts/reverser-pin.mjs | 42 ++++++++++ src/components/Footer.astro | 2 +- src/components/Nav.astro | 2 +- src/lib/reverser-pin.json | 4 + src/lib/reverser.ts | 116 ++++++++++++++++++++++++++ src/pages/gitops.astro | 1 + src/pages/index.astro | 2 +- src/pages/open-source.astro | 4 +- src/pages/reverser/[...slug].astro | 129 +++++++++++++++++++++++++++++ src/pages/sitemap.xml.ts | 4 +- tests/e2e/reverser.spec.ts | 65 +++++++++++++++ 17 files changed, 392 insertions(+), 7 deletions(-) create mode 100644 scripts/reverser-pin.mjs create mode 100644 src/lib/reverser-pin.json create mode 100644 src/lib/reverser.ts create mode 100644 src/pages/reverser/[...slug].astro create mode 100644 tests/e2e/reverser.spec.ts diff --git a/README.md b/README.md index 64b6aea..39c5f30 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,25 @@ npm run test:e2e # Playwright end-to-end tests against the production build SSH commit signing through the host agent). It follows the gitops-reverser devcontainer; see [`.devcontainer/README.md`](.devcontainer/README.md). +## GitOps Reverser docs + +`/reverser` renders Markdown from the [gitops-reverser](https://github.com/ConfigButler/gitops-reverser) +submodule at build time, unedited. The operator repo is the single source of truth; fix content there. + +- Which files get a route: `docs` in [`src/lib/reverser.ts`](src/lib/reverser.ts). Links to any + other file open on GitHub at the pinned commit. +- Clone with `--recurse-submodules`, or run `git submodule update --init`. The build fails without it. + +Move to a new release: + +```sh +git -C external/gitops-reverser fetch --tags +git -C external/gitops-reverser checkout v0.57.0 +npm run reverser:pin # records the commit in src/lib/reverser-pin.json (read by builds without .git) +npm run build # prebuild fails if the pin and the submodule disagree +git add external/gitops-reverser src/lib/reverser-pin.json +``` + ## Container image [`.github/workflows/image.yml`](.github/workflows/image.yml) builds the site into an nginx image diff --git a/astro.config.mjs b/astro.config.mjs index eaf2e24..843f4c0 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -3,4 +3,6 @@ import { defineConfig } from 'astro/config'; // https://astro.build/config export default defineConfig({ site: 'https://configbutler.ai', + // Listen on all interfaces: "localhost" can bind ::1 only, which the devcontainer port forward misses. + server: { host: true }, }); diff --git a/external/gitops-reverser b/external/gitops-reverser index 2686da2..e09a9f5 160000 --- a/external/gitops-reverser +++ b/external/gitops-reverser @@ -1 +1 @@ -Subproject commit 2686da2698792e7af8bb29c8d37a4df641e77357 +Subproject commit e09a9f5987bb53b4587a88327a5fe286e7ba5660 diff --git a/package-lock.json b/package-lock.json index 046cb7a..66edf68 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "simple-astro-website", "version": "0.0.1", "dependencies": { + "@astrojs/markdown-remark": "^7.2.0", "astro": "^6.4.8" }, "devDependencies": { diff --git a/package.json b/package.json index 703de6d..70ad509 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,15 @@ "scripts": { "dev": "astro dev", "start": "astro dev", + "prebuild": "node scripts/reverser-pin.mjs check", "build": "astro build", "preview": "astro preview", "astro": "astro", + "reverser:pin": "node scripts/reverser-pin.mjs write", "test:e2e": "playwright test" }, "dependencies": { + "@astrojs/markdown-remark": "^7.2.0", "astro": "^6.4.8" }, "devDependencies": { diff --git a/public/llms.txt b/public/llms.txt index 3e953c9..f51ed53 100644 --- a/public/llms.txt +++ b/public/llms.txt @@ -13,6 +13,7 @@ partnerships are available; contact runs through the about page. - [For Applications](https://configbutler.ai/applications/): Give an application a typed configuration API without building and operating a configuration backend yourself. - [For GitOps](https://configbutler.ai/gitops/): A realtime API in front of an existing Git repository, where writes become reviewable pull requests and existing workflows are preserved. - [Technology](https://configbutler.ai/technology/): Architecture — a managed Kubernetes-style control plane as operational truth, synchronized to a customer-owned Git repository. +- [GitOps Reverser](https://configbutler.ai/reverser/): The open-source Kubernetes operator that turns cluster activity into YAML commits. Its README, quick start, and configuration guide, rendered from the operator repository. - [Open source](https://configbutler.ai/open-source/): The work developed in public — GitOps Reverser, KRM Stream, and the Reverse GitOps operating model. - [About](https://configbutler.ai/about/): The company, the founder, and how to get in touch. diff --git a/scripts/reverser-pin.mjs b/scripts/reverser-pin.mjs new file mode 100644 index 0000000..f362275 --- /dev/null +++ b/scripts/reverser-pin.mjs @@ -0,0 +1,42 @@ +// The submodule is the pin; src/lib/reverser-pin.json carries it into builds without .git (Docker). +// node scripts/reverser-pin.mjs write record the submodule's current commit +// node scripts/reverser-pin.mjs check fail if the submodule is missing or disagrees (prebuild) +import { execFileSync } from 'node:child_process'; +import { existsSync, readFileSync, writeFileSync } from 'node:fs'; + +const dir = 'external/gitops-reverser'; +const file = 'src/lib/reverser-pin.json'; +const git = (...args) => execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8' }).trim(); + +if (!existsSync(`${dir}/README.md`)) { + console.error(`${dir} is empty. Run: git submodule update --init`); + process.exit(1); +} + +const mode = process.argv[2]; +let sha; +try { + sha = git('rev-parse', 'HEAD'); +} catch { + if (mode === 'check') { + console.log('reverser-pin: no git metadata, trusting', file); + process.exit(0); + } + throw new Error('reverser-pin: cannot read the submodule commit'); +} + +if (mode === 'write') { + let tag = null; + try { tag = git('describe', '--tags', '--exact-match', 'HEAD'); } catch {} + writeFileSync(file, JSON.stringify({ sha, tag }, null, '\t') + '\n'); + console.log(`reverser-pin: ${tag ?? sha}`); +} else if (mode === 'check') { + const pin = JSON.parse(readFileSync(file, 'utf8')); + if (pin.sha !== sha) { + console.error(`reverser-pin: ${file} has ${pin.sha}, submodule is at ${sha}. Run: npm run reverser:pin`); + process.exit(1); + } +} else { + console.error('usage: reverser-pin.mjs write|check'); + process.exit(2); +} diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 4354137..461c4c5 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -33,7 +33,7 @@ const year = 2026;

Open source

diff --git a/src/components/Nav.astro b/src/components/Nav.astro index 7689f0f..c449e56 100644 --- a/src/components/Nav.astro +++ b/src/components/Nav.astro @@ -19,7 +19,7 @@ const cur = (href: string) => (isActive(href) ? 'page' : undefined); gitops tech - open source + open source about diff --git a/src/lib/reverser-pin.json b/src/lib/reverser-pin.json new file mode 100644 index 0000000..06faf53 --- /dev/null +++ b/src/lib/reverser-pin.json @@ -0,0 +1,4 @@ +{ + "sha": "e09a9f5987bb53b4587a88327a5fe286e7ba5660", + "tag": "v0.56.0" +} diff --git a/src/lib/reverser.ts b/src/lib/reverser.ts new file mode 100644 index 0000000..1eab816 --- /dev/null +++ b/src/lib/reverser.ts @@ -0,0 +1,116 @@ +// Renders gitops-reverser's own Markdown, unedited. The operator repo is the source of truth; +// this file only decides which documents get a route and where every other link goes. +import { createMarkdownProcessor } from '@astrojs/markdown-remark'; +import rehypeRaw from 'rehype-raw'; +import { existsSync, readFileSync, statSync } from 'node:fs'; +import path from 'node:path'; +import pin from './reverser-pin.json'; + +export const repo = 'https://github.com/ConfigButler/gitops-reverser'; +export const ref = pin.sha; +export const version = pin.tag ?? pin.sha.slice(0, 7); +const root = 'external/gitops-reverser'; + +// Source file → route under /reverser. A link to anything else opens on GitHub at the pin. +export const docs = [ + { slug: undefined, src: 'README.md', nav: 'Overview' }, + { slug: 'quickstart', src: 'docs/quickstart.md', nav: 'Quick start' }, + { slug: 'configuration', src: 'docs/configuration.md', nav: 'Configuration' }, +] as const; + +export const route = (slug?: string) => (slug ? `/reverser/${slug}` : '/reverser'); +const routes = new Map(docs.map((d) => [d.src, route(d.slug)])); + +// Bundle every image the docs can reference, so pages never load them from GitHub. +const assets = import.meta.glob( + '/external/gitops-reverser/docs/{images,demo}/*.{svg,gif,png,jpg}', + { query: '?url', import: 'default', eager: true }, +); +const assetUrl = (p: string) => assets[`/${root}/${p}`]; + +const isExternal = (url: string) => /^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith('//'); + +// A repo-relative path for `url` as written in `from`, or null when it is not a repo link. +function resolve(from: string, url: string) { + // A leading "/" is already a site path: rewritten by the remark pass. + if (!url || /^[#/]/.test(url) || isExternal(url)) return null; + const [p, hash] = url.split('#'); + const target = path.posix.normalize(path.posix.join(path.posix.dirname(from), p)); + return { target: target.replace(/\/$/, ''), hash: hash ? `#${hash}` : '' }; +} + +function rewriteLink(from: string, url: string) { + const r = resolve(from, url); + if (!r) return url; + const mapped = routes.get(r.target); + if (mapped) return mapped + r.hash; + const full = path.join(root, r.target); + const kind = existsSync(full) && statSync(full).isDirectory() ? 'tree' : 'blob'; + return `${repo}/${kind}/${ref}/${r.target}${r.hash}`; +} + +function rewriteImage(from: string, url: string) { + const r = resolve(from, url); + if (!r) return url; + const local = assetUrl(r.target); + if (!local) throw new Error(`reverser: ${from} references ${url}, which is not bundled`); + return local; +} + +type Node = { type: string; depth?: number; value?: string; url?: string; tagName?: string; properties?: Record; children?: Node[] }; +function walk(node: Node, fn: (n: Node) => void) { + fn(node); + node.children?.forEach((c) => walk(c, fn)); +} + +const remarkRepoLinks = (from: string) => () => (tree: Node) => + walk(tree, (n) => { + if (n.type === 'link' || n.type === 'definition') n.url = rewriteLink(from, n.url!); + if (n.type === 'image') n.url = rewriteImage(from, n.url!); + }); + +// Raw HTML in the source (the README's demo ) only becomes elements after rehype-raw. +const rehypeRepoLinks = (from: string) => () => (tree: Node) => + walk(tree, (n) => { + if (n.type !== 'element') return; + const p = n.properties!; + if (n.tagName === 'img' && typeof p.src === 'string') p.src = rewriteImage(from, p.src); + if (n.tagName === 'a' && typeof p.href === 'string') { + p.href = rewriteLink(from, p.href); + if (isExternal(p.href as string)) { + p.target = '_blank'; + p.rel = 'noopener'; + } + } + }); + +const text = (n: Node): string => n.value ?? n.children?.map(text).join('') ?? ''; + +// The first paragraph after the title, as the page's meta description. +const remarkLede = (out: { description: string }) => () => (tree: Node) => { + const nodes = tree.children ?? []; + const h1 = nodes.findIndex((n) => n.type === 'heading' && n.depth === 1); + const p = nodes.slice(h1 + 1).find((n) => n.type === 'paragraph'); + const t = p ? text(p).replace(/\s+/g, ' ').trim() : ''; + out.description = t.length > 160 ? `${t.slice(0, t.lastIndexOf(' ', 157))}…` : t; +}; + +export async function render(src: string) { + const lede = { description: '' }; + const md = await createMarkdownProcessor({ + syntaxHighlight: 'shiki', + shikiConfig: { theme: 'github-dark-default', langAlias: { promql: 'plaintext' } }, + smartypants: false, + remarkPlugins: [remarkLede(lede), remarkRepoLinks(src)], + rehypePlugins: [rehypeRaw, rehypeRepoLinks(src)], + }); + const { code, metadata } = await md.render(readFileSync(path.join(root, src), 'utf8')); + const h1 = metadata.headings.find((h) => h.depth === 1)?.text ?? src; + return { + html: code, + title: h1, + description: lede.description, + toc: metadata.headings.filter((h) => h.depth === 2), + source: `${repo}/blob/${ref}/${src}`, + }; +} diff --git a/src/pages/gitops.astro b/src/pages/gitops.astro index 5b6d685..bc579fc 100644 --- a/src/pages/gitops.astro +++ b/src/pages/gitops.astro @@ -169,6 +169,7 @@ const audiences = [ diff --git a/src/pages/index.astro b/src/pages/index.astro index 54bf7f2..d8840f1 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -319,7 +319,7 @@ const flow = [

Much of the thinking is developed in public.

{repos.map((r) => ( - +
{r.tag}

{r.name}

{r.desc}

diff --git a/src/pages/reverser/[...slug].astro b/src/pages/reverser/[...slug].astro new file mode 100644 index 0000000..24a34f8 --- /dev/null +++ b/src/pages/reverser/[...slug].astro @@ -0,0 +1,129 @@ +--- +import Layout from '../../layouts/Layout.astro'; +import { docs, render, route, version, repo, ref } from '../../lib/reverser'; + +export function getStaticPaths() { + return docs.map((d) => ({ params: { slug: d.slug }, props: { src: d.src } })); +} + +const { src } = Astro.props; +const { html, title, description, toc, source } = await render(src); +const here = route(Astro.params.slug); +--- + +
+ +
+ {toc.length > 2 && ( + + )} +
+
+ +
+ Rendered from ConfigButler/gitops-reverser @ {version}. + Spotted something wrong? Edit it upstream. +
+ + + + + diff --git a/src/pages/sitemap.xml.ts b/src/pages/sitemap.xml.ts index 21e8f80..928aee2 100644 --- a/src/pages/sitemap.xml.ts +++ b/src/pages/sitemap.xml.ts @@ -1,12 +1,14 @@ import type { APIRoute } from 'astro'; +import { docs, route } from '../lib/reverser'; // Every .astro page under src/pages becomes one entry, so the sitemap // stays correct without anyone remembering to update it. const pages = Object.keys(import.meta.glob('./**/*.astro')) .map((file) => file.replace(/^\.\//, '').replace(/\.astro$/, '')) - .filter((name) => !name.startsWith('404')) + .filter((name) => !name.startsWith('404') && !name.includes('[')) // Trailing slashes, to match the each page emits. .map((name) => (name === 'index' ? '' : `${name.replace(/\/index$/, '')}/`)) + .concat(docs.map((d) => `${route(d.slug).slice(1)}/`)) .sort(); export const GET: APIRoute = ({ site }) => { diff --git a/tests/e2e/reverser.spec.ts b/tests/e2e/reverser.spec.ts new file mode 100644 index 0000000..19a1631 --- /dev/null +++ b/tests/e2e/reverser.spec.ts @@ -0,0 +1,65 @@ +import { test, expect } from '@playwright/test'; +import pin from '../../src/lib/reverser-pin.json' with { type: 'json' }; + +const pages = ['/reverser', '/reverser/quickstart', '/reverser/configuration']; + +test('reached from the open-source page, which stays highlighted', async ({ page }) => { + await page.goto('/open-source'); + await page.locator('a.repo', { hasText: 'GitOps Reverser' }).click(); + await expect(page).toHaveURL(/\/reverser\/?$/); + await expect(page.locator('article.doc h1')).toHaveText('GitOps Reverser'); + await expect(page.locator('#site-nav a[aria-current="page"]')).toHaveText('open source'); +}); + +for (const path of pages) { + test(`${path} renders upstream Markdown`, async ({ page }) => { + await page.goto(path); + await expect(page.locator('article.doc h1')).toBeVisible(); + + // Every bundled image loads. + for (const img of await page.locator('article.doc img[src^="/"]').all()) { + await img.scrollIntoViewIfNeeded(); + expect(await img.evaluate((i: HTMLImageElement) => i.complete && i.naturalWidth > 0)).toBe(true); + } + + // No link stays relative to the source repo: it is a site route, an anchor, or absolute. + const hrefs = await page.locator('article.doc a').evaluateAll((as) => as.map((a) => a.getAttribute('href') ?? '')); + for (const href of hrefs) expect(href).toMatch(/^(\/|#|https?:|mailto:)/); + + // Repo links open the pinned commit, never a moving branch. + for (const href of hrefs.filter((h) => h.includes('github.com/ConfigButler/gitops-reverser/'))) { + if (/\/(blob|tree)\//.test(href)) expect(href).toContain(pin.sha); + } + }); +} + +test('cross-document anchors land on a heading', async ({ page, request }) => { + for (const path of pages) { + await page.goto(path); + const targets = await page + .locator('article.doc a[href*="#"]') + .evaluateAll((as) => as.map((a) => a.getAttribute('href')!).filter((h) => h.startsWith('/') || h.startsWith('#'))); + for (const t of new Set(targets)) { + const [route, id] = t.split('#'); + const html = await (await request.get(route || path)).text(); + expect(html, `${path} → ${t}`).toContain(`id="${id}"`); + } + } +}); + +test('quickstart loads directly, with and without trailing slash', async ({ page }) => { + for (const url of ['/reverser/quickstart', '/reverser/quickstart/']) { + const res = await page.goto(url); + expect(res?.status()).toBe(200); + await expect(page.locator('article.doc h1')).toHaveText('Quick start'); + } +}); + +test('mobile: no horizontal page scroll', async ({ page }) => { + await page.setViewportSize({ width: 375, height: 800 }); + for (const path of pages) { + await page.goto(path); + const overflow = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth); + expect(overflow, path).toBeLessThanOrEqual(0); + } +}); From 1369eed990264fbf888ee79702a52e8b7d88bf10 Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Thu, 12 Nov 2026 10:15:13 +0000 Subject: [PATCH 2/2] docs: One release procedure, including the pin Co-Authored-By: Claude Opus 5.5 --- README.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 39c5f30..62f03df 100644 --- a/README.md +++ b/README.md @@ -33,15 +33,7 @@ submodule at build time, unedited. The operator repo is the single source of tru other file open on GitHub at the pinned commit. - Clone with `--recurse-submodules`, or run `git submodule update --init`. The build fails without it. -Move to a new release: - -```sh -git -C external/gitops-reverser fetch --tags -git -C external/gitops-reverser checkout v0.57.0 -npm run reverser:pin # records the commit in src/lib/reverser-pin.json (read by builds without .git) -npm run build # prebuild fails if the pin and the submodule disagree -git add external/gitops-reverser src/lib/reverser-pin.json -``` +To move to a new release, see [gitops-reverser submodule](#gitops-reverser-submodule). ## Container image @@ -75,8 +67,11 @@ To move to a new gitops-reverser release: git -C external/gitops-reverser fetch --tags git -C external/gitops-reverser checkout vX.Y.Z git diff --submodule=log # what changed upstream since the last pin +npm run reverser:pin # records the commit in src/lib/reverser-pin.json (for builds without .git) +npm run build # prebuild fails if the pin and the submodule disagree # review whether docs or concepts the site relies on changed, then: -git add external/gitops-reverser && git commit -m "chore: Bump gitops-reverser to vX.Y.Z" +git add external/gitops-reverser src/lib/reverser-pin.json +git commit -m "chore: Bump gitops-reverser to vX.Y.Z" ``` ## Structure