Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ 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.

To move to a new release, see [gitops-reverser submodule](#gitops-reverser-submodule).

## Container image

[`.github/workflows/image.yml`](.github/workflows/image.yml) builds the site into an nginx image
Expand Down Expand Up @@ -56,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
Expand Down
2 changes: 2 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
2 changes: 1 addition & 1 deletion external/gitops-reverser
Submodule gitops-reverser updated 227 files
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions public/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
42 changes: 42 additions & 0 deletions scripts/reverser-pin.mjs
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion src/components/Footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const year = 2026;
<h4>Open source</h4>
<ul>
<li><a href="/open-source">Overview</a></li>
<li><a href="https://github.com/ConfigButler/gitops-reverser" target="_blank" rel="noopener">GitOps Reverser</a></li>
<li><a href="/reverser">GitOps Reverser</a></li>
<li><a href="https://github.com/ConfigButler/krm-stream" target="_blank" rel="noopener">KRM Stream</a></li>
<li><a href="https://reversegitops.dev" target="_blank" rel="noopener">Reverse GitOps</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Nav.astro
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const cur = (href: string) => (isActive(href) ? 'page' : undefined);
<a class="lk lk--gitops" href="/gitops" aria-current={cur('/gitops')}><span class="d"></span>gitops</a>
<span class="nav-div" aria-hidden="true"></span>
<a href="/technology" aria-current={cur('/technology')}>tech</a>
<a href="/open-source" aria-current={cur('/open-source')}>open source</a>
<a href="/open-source" aria-current={cur('/open-source') ?? cur('/reverser')}>open source</a>
<a href="/about" aria-current={cur('/about')}>about</a>
</nav>

Expand Down
4 changes: 4 additions & 0 deletions src/lib/reverser-pin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"sha": "e09a9f5987bb53b4587a88327a5fe286e7ba5660",
"tag": "v0.56.0"
}
116 changes: 116 additions & 0 deletions src/lib/reverser.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>(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<string>(
'/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<string, unknown>; 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 <img>) 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}`,
};
}
1 change: 1 addition & 0 deletions src/pages/gitops.astro
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const audiences = [
<div class="cta-row" style="margin-top:28px">
<a class="btn btn-brass" href="/about#contact"><span class="d"></span>Talk to Simon</a>
<a class="btn btn-ghost-dark" href="/technology">See the architecture →</a>
<a class="btn btn-ghost-dark" href="/reverser">Self-host GitOps Reverser →</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ const flow = [
<h2 class="sect-h">Much of the thinking is <span class="b">developed in public.</span></h2>
</div>
<div class="grid grid-3">
<a class="repo rv" href="https://github.com/ConfigButler/gitops-reverser" target="_blank" rel="noopener">
<a class="repo rv" href="/reverser">
<div class="repo-top"><Icon name="github" class="gh" /><span class="pill pill-brass">engine</span></div>
<h3>GitOps Reverser</h3>
<p>Open-source engine for turning API activity into clean YAML commits in Git.</p>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/open-source.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Icon from '../components/Icon.astro';
const repos = [
{
name: 'GitOps Reverser', tag: 'engine', lang: 'Go', langColor: '#3178c6', license: 'Apache-2.0',
url: 'https://github.com/ConfigButler/gitops-reverser', label: 'github.com/ConfigButler/gitops-reverser',
url: '/reverser', label: 'github.com/ConfigButler/gitops-reverser',
desc: 'The open-source engine for turning API activity into clean YAML commits in Git. The reconciliation core behind the durable record.',
},
{
Expand Down Expand Up @@ -53,7 +53,7 @@ const repos = [
</div>
<div class="grid grid-3">
{repos.map((r) => (
<a class="repo rv" href={r.url} target="_blank" rel="noopener">
<a class="repo rv" href={r.url} target={r.url.startsWith('/') ? undefined : '_blank'} rel="noopener">
<div class="repo-top"><Icon name={r.icon ?? 'github'} class="gh" /><span class="pill pill-brass">{r.tag}</span></div>
<h3>{r.name}</h3>
<p>{r.desc}</p>
Expand Down
Loading
Loading