Files
sim/scripts/check-cron-parity.ts
T
Waleed 3de63c94e3 feat(self-host): align Docker Compose with Helm and overhaul self-hosting docs (#6225)
* feat(self-host): align Docker Compose with Helm and overhaul self-hosting docs

Docker Compose shipped no scheduler, so scheduled workflows, every polling
trigger, connector syncs, the outbox, and data drains silently never ran.
Adds a cron service running the same 18 jobs the Helm chart schedules as
CronJobs, and closes the remaining behavioral gaps between the two paths:
bundled Redis in the chart, no hosted plan caps in chart defaults, pinned
image tags, and fail-fast secrets. A CI check keeps the schedulers in sync.

Also rewrites the self-hosting docs: 14 new pages, 8 updated, reorganized
into Install / Configure / Operate.

* fix(self-host): drop bun install from chart CI, remove air-gapped and backup docs

The scheduler-parity check pulled a full dependency install into the
chart-validation job, which fails building isolated-vm on that runner.
Rewritten to use only node builtins so the job installs nothing.

Also removes the air-gapped and backup/restore pages, and stops pinning a
concrete release in the docs so the examples do not go stale each release.

* fix(helm): bundle Redis in secret-manager modes unless the URL is supplied

Suppressing Redis whenever a secret mode was active left those deployments
with no Redis at all — REDIS_URL is optional there and both shipped examples
omit it. The chart now steps aside only on a detectable signal: an explicit
app.env.REDIS_URL, an ESO remoteRefs.app.REDIS_URL mapping, or the new
redis.provideUrl=false opt-out for a pre-created Secret it cannot read.

* fix(compose): derive realtime BETTER_AUTH_URL from NEXT_PUBLIC_APP_URL

realtime read BETTER_AUTH_URL directly and fell back to localhost while
simstudio derived it from NEXT_PUBLIC_APP_URL, so setting only the public
origin left realtime authenticating against http://localhost:3000.

* fix(helm): deliver bundled REDIS_URL via ConfigMap so an operator value always wins

Injecting REDIS_URL as an inline container env made it beat every envFrom
source, so a REDIS_URL held in a pre-created Secret or synced by External
Secrets was silently shadowed and traffic moved to a fresh in-cluster Redis.

Kubernetes resolves duplicate envFrom keys by letting the last source win, so
the bundled URL now ships as a ConfigMap listed before the app Secret. Any
operator-supplied value overrides it without the chart needing to read it,
which also removes the redis.provideUrl flag the previous attempt required.

* docs(helm): spell out the egress rule external datastores need

The default NetworkPolicy allows 443 plus the bundled Postgres and Redis by
pod selector. Anything you run outside the chart on another port needs its own
rule, which is easiest to miss when REDIS_URL arrives via a Secret the chart
cannot inspect. Adds a copyable example to the production checklist and the
security guide.

* feat(helm): add networkPolicy.allowExternalEgress for managed datastores

The default policy allows 443 plus the bundled Postgres and Redis by pod
selector, so a managed datastore on another port needs a hand-written CIDR
rule — awkward when REDIS_URL arrives via a Secret the chart cannot inspect.

Adds an opt-in switch that drops the port restriction while still blocking the
cloud metadata endpoints. Defaults to false, keeping this chart stricter than
the common chart default of unrestricted egress.
2026-08-03 14:52:48 -07:00

102 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Fails when the Docker Compose scheduler and the Helm CronJobs disagree.
*
* Both deployments must run the same background jobs on the same schedules, or
* a feature silently works on one and not the other — the exact class of drift
* that left Compose without a scheduler for as long as it did.
*
* Sources of truth:
* docker/crontab — one line per job for Docker Compose
* helm/sim/values.yaml — cronjobs.jobs.<name>.{path,schedule} for Kubernetes
*/
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..')
/** Parses `*/5 * * * * curl ... "$SIM_URL/api/foo"` into its schedule and path. */
function parseCrontab(contents: string): Map<string, string> {
const jobs = new Map<string, string>()
for (const rawLine of contents.split('\n')) {
const line = rawLine.trim()
if (!line || line.startsWith('#') || !line.includes('curl')) continue
const schedule = line.split(/\s+/).slice(0, 5).join(' ')
const pathMatch = line.match(/\$SIM_URL(\/api\/[^"']+)/)
if (!pathMatch) {
throw new Error(`docker/crontab line has no $SIM_URL/api/... target:\n ${line}`)
}
jobs.set(pathMatch[1], schedule)
}
return jobs
}
/**
* Pulls the `schedule`/`path` pairs out of the `cronjobs.jobs` block.
*
* Deliberately dependency-free rather than using a YAML parser: this runs in the
* chart-validation CI job, which otherwise installs nothing — and a full install
* there drags in native modules that have no business building for a lint job.
* The block has a fixed shape, and an empty result is treated as an error, so a
* structural change fails loudly instead of silently passing.
*/
function parseHelmJobs(contents: string): Map<string, string> {
const lines = contents.split('\n')
const start = lines.findIndex((l) => l.startsWith('cronjobs:'))
if (start === -1) throw new Error('helm/sim/values.yaml has no top-level `cronjobs:` block')
const jobs = new Map<string, string>()
let schedule: string | null = null
for (const line of lines.slice(start + 1)) {
// A new top-level key ends the cronjobs block.
if (/^[a-zA-Z]/.test(line)) break
const scheduleMatch = line.match(/^\s+schedule:\s*"([^"]+)"/)
if (scheduleMatch) {
schedule = scheduleMatch[1]
continue
}
const pathMatch = line.match(/^\s+path:\s*"([^"]+)"/)
if (pathMatch) {
if (!schedule) throw new Error(`path "${pathMatch[1]}" has no preceding schedule`)
jobs.set(pathMatch[1], schedule)
schedule = null
}
}
if (jobs.size === 0) {
throw new Error('parsed no jobs from cronjobs.jobs — the values.yaml shape likely changed')
}
return jobs
}
const crontab = parseCrontab(readFileSync(join(repoRoot, 'docker/crontab'), 'utf8'))
const helm = parseHelmJobs(readFileSync(join(repoRoot, 'helm/sim/values.yaml'), 'utf8'))
const errors: string[] = []
for (const [path, schedule] of helm) {
if (!crontab.has(path)) {
errors.push(`${path} is a Helm CronJob but is missing from docker/crontab`)
} else if (crontab.get(path) !== schedule) {
errors.push(`${path} schedule differs — helm: "${schedule}", crontab: "${crontab.get(path)}"`)
}
}
for (const path of crontab.keys()) {
if (!helm.has(path)) {
errors.push(`${path} is in docker/crontab but has no matching Helm CronJob`)
}
}
if (errors.length > 0) {
console.error('Scheduler parity check failed:\n')
for (const error of errors) console.error(` - ${error}`)
console.error(
'\nKeep docker/crontab and helm/sim/values.yaml cronjobs.jobs in sync so both deployments run the same jobs.'
)
process.exit(1)
}
console.log(`Scheduler parity OK — ${helm.size} jobs match across Docker Compose and Helm.`)