Skip to content

Commit 224ab35

Browse files
committed
improvement(self-hosting): share the release image list and fold upgrade notes
1 parent 49d8a7c commit 224ab35

7 files changed

Lines changed: 150 additions & 149 deletions

File tree

‎.github/workflows/helm.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
# change to its generator has to run this workflow too.
1313
- 'scripts/generate-image-manifest.ts'
1414
- 'scripts/write-chart-sandbox-images.ts'
15+
- 'scripts/release-image-list.ts'
1516
# The publish jobs run it to stamp appVersion and the release's sandbox images.
1617
- 'scripts/sync-chart-appversion.ts'
1718
- 'package.json'
@@ -26,6 +27,7 @@ on:
2627
# change to its generator has to run this workflow too.
2728
- 'scripts/generate-image-manifest.ts'
2829
- 'scripts/write-chart-sandbox-images.ts'
30+
- 'scripts/release-image-list.ts'
2931
# The publish jobs run it to stamp appVersion and the release's sandbox images.
3032
- 'scripts/sync-chart-appversion.ts'
3133
- 'package.json'
@@ -248,9 +250,9 @@ jobs:
248250
kubectl -n sim logs deploy/sim-app --tail=80 || true
249251
kubectl -n sim logs deploy/sim-realtime --tail=80 || true
250252
kubectl -n sim logs sim-test-connection || true
253+
kubectl -n sim logs sim-test-self-check || true
251254
kubectl -n sim-upgrade get pods -o wide || true
252255
kubectl -n sim-upgrade get events --sort-by=.lastTimestamp | tail -20 || true
253-
kubectl -n sim logs sim-test-self-check || true
254256
255257
# Resolved once and shared, so the two publish paths cannot package the same
256258
# immutable chart version with different appVersions -- they run in parallel,

‎helm/sim/README.md‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -667,14 +667,7 @@ kubectl --namespace sim logs deploy/sim-app -c migrations
667667

668668
## Upgrading to 1.22.0
669669

670-
* **`helm test` now proves the install works.** A second test pod calls the app's authenticated `/api/cron/self-check` (see [Test the install](#test-the-install)). Run `helm test` with `--timeout 10m` when the Kubernetes sandbox provider is on: the sandbox check starts two sandbox pods.
671-
* **`tests.image` defaults to `curlimages/curl:8.5.0`**, the image the cron jobs use, instead of `busybox:1.36`. If you pinned `tests.image` to busybox, either drop the override or set it to an image that has `curl`.
672-
* **With `networkPolicy.enabled` and the ingress disabled, `helm test` no longer times out.** The app and realtime policies admit the test pods while `tests.enabled` is true; before, nothing did.
673-
* **`images.yaml` covers the Kubernetes sandbox provider.** It now lists the warm-capacity `pause` image and the Mothership's `copilot-sandbox-shell` and `copilot-sandbox-doc` (with the `main-REPLACE` placeholder), and the published chart's copy also lists the `simstudioai/sandbox-*` images at the tags its appVersion pins.
674-
675-
## Upgrading to 1.21.0
676-
677-
Covers 1.19.0–1.21.0; 1.18.0 is the previous published chart. This release refuses some values earlier charts accepted; run `helm template` with your values before upgrading.
670+
Covers 1.19.0–1.22.0; 1.18.0 is the previous published chart. This release refuses some values earlier charts accepted; run `helm template` with your values before upgrading.
678671

679672
* **Argo CD or `helm template | kubectl apply`: recreate the bundled Postgres StatefulSets once.** Their volume claim labels no longer carry the chart version (Kubernetes forbids changing them, which broke every upgrade). `helm upgrade` and Flux reuse the existing labels and need nothing; tools that render without `lookup` must orphan-delete first, which keeps the pods and PVCs:
680673

@@ -688,6 +681,8 @@ Covers 1.19.0–1.21.0; 1.18.0 is the previous published chart. This release ref
688681
* **External Secrets: synced keys win over `envDefaults`.** A key mapped in `externalSecrets.remoteRefs.app` is no longer masked by the chart default. No action.
689682
* **existingSecret mode applies no `envDefaults`.** Put overrides in `app.env`, which is inlined in that mode.
690683
* **New render checks.** An enabled `existingSecret` with an empty `name` (`app.secrets`, `postgresql.auth`, `externalDatabase`) fails, as does enabling both `postgresql` and `externalDatabase`, and `TRIGGER_DEV_ENABLED=true` with `sandbox.kubernetes.enabled` (unset it; Trigger.dev workers cannot reach sandbox pods).
684+
* **`helm test` runs the authenticated self-check, and `tests.image` is now `curlimages/curl:8.5.0`.** Drop a `busybox` override of `tests.image`; with Kubernetes sandboxes run `helm test` with `--timeout 10m`. See [Test the install](#test-the-install).
685+
* **Air-gapped mirrors: `images.yaml` adds `pause` and the `copilot-sandbox-*` images, and `busybox` is gone.** Mirror from the published chart's copy, which also lists the sandbox images its appVersion runs.
691686
* **Kubernetes sandboxes only:**
692687
* **The quota is derived.** Empty `sandbox.kubernetes.quota.cpu`/`memory`/`ephemeralStorage` (the new default) become `quota.pods` x (resources + RuntimeClass overhead); an explicit value below that floor fails. With a RuntimeClass the chart does not create, add its `overhead.podFixed` when you set quotas.
693688
* **`prePull` no longer needs `images.function.tag` on a published chart.** It defaults to the image the chart's appVersion runs; unset `images.function.tag` if you set it only for `prePull`.

‎scripts/generate-image-manifest.test.ts‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
collectImages,
44
mergeImageEntries,
55
pairSources,
6-
parseSandboxImageReferences,
76
sandboxImageEntries,
87
} from './generate-image-manifest'
98

@@ -152,21 +151,3 @@ describe('mergeImageEntries', () => {
152151
expect(() => mergeImageEntries([entry], [entry])).toThrow(/listed twice/)
153152
})
154153
})
155-
156-
describe('parseSandboxImageReferences', () => {
157-
it('reads every reference the app pins', () => {
158-
expect(
159-
parseSandboxImageReferences(
160-
'{"function": "ghcr.io/simstudioai/sandbox-function:a", "agent": "ghcr.io/simstudioai/sandbox-agent:b"}'
161-
)
162-
).toEqual(['ghcr.io/simstudioai/sandbox-function:a', 'ghcr.io/simstudioai/sandbox-agent:b'])
163-
})
164-
165-
it.each([
166-
['an empty map', '{}'],
167-
['a non-string reference', '{"function": 1}'],
168-
['an array', '["ghcr.io/simstudioai/sandbox-function:a"]'],
169-
])('refuses %s rather than publishing an inventory without the sandbox images', (_, json) => {
170-
expect(() => parseSandboxImageReferences(json)).toThrow(/images.generated.json/)
171-
})
172-
})

‎scripts/generate-image-manifest.ts‎

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
* committed file leaves them out, since their content-addressed tags change with
2727
* every sandbox image rebuild and would otherwise force a chart version bump.
2828
*/
29-
import { spawnSync } from 'node:child_process'
3029
import { readFile, writeFile } from 'node:fs/promises'
3130
import { dirname, resolve } from 'node:path'
3231
import { fileURLToPath } from 'node:url'
32+
import { IMAGE_LIST_PATH, readReleaseImageList } from './release-image-list'
3333

3434
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url))
3535
const ROOT = resolve(SCRIPT_DIR, '..')
@@ -74,15 +74,6 @@ const RENDER_ARGS = [
7474
'sandbox.kubernetes.images.doc.tag=main-REPLACE',
7575
] as const
7676

77-
/**
78-
* The sandbox images the app starts at run time, which no rendered pod names.
79-
* The app's defaults are the references this file pins, read at the release tag.
80-
*/
81-
const SANDBOX_IMAGES_PATH = 'apps/sim/lib/execution/remote-sandbox/kubernetes/images.generated.json'
82-
83-
/** A release tag as this repository cuts them: `v1.2.3`. */
84-
const RELEASE_TAG = /^v\d+\.\d+\.\d+$/
85-
8677
/**
8778
* Sentinel registry used for the second render.
8879
*
@@ -293,57 +284,17 @@ function renderChart(args: readonly string[] = RENDER_ARGS): unknown[] {
293284
return Array.isArray(documents) ? documents : [documents]
294285
}
295286

296-
function git(args: readonly string[]): { ok: boolean; stdout: string } {
297-
const result = spawnSync('git', args, { cwd: ROOT, encoding: 'utf8' })
298-
return { ok: result.status === 0, stdout: result.stdout ?? '' }
299-
}
300-
301287
/**
302-
* The sandbox image references the app at `release` defaults to. Publish jobs
303-
* check out shallow, so the tag is fetched when absent. On the release merge
304-
* itself the tag does not exist yet (that commit cuts it), so HEAD is read when
305-
* its subject names the release, the same rule helm.yml resolves the version by.
288+
* The sandbox images the app at `release` starts at run time, which no rendered pod names: the
289+
* references `images.generated.json` pins at the release tag. None for a release before the list.
306290
*/
307291
function releaseSandboxImages(release: string): string[] {
308-
if (!RELEASE_TAG.test(release)) {
309-
throw new Error(`--release must be a release tag like v1.2.3, got "${release}"`)
310-
}
311-
const tagRef = `refs/tags/${release}`
312-
if (!git(['rev-parse', '--verify', '--quiet', tagRef]).ok) {
313-
git(['fetch', '--quiet', '--no-tags', '--depth', '1', 'origin', `+${tagRef}:${tagRef}`])
314-
}
315-
let ref = tagRef
316-
if (!git(['rev-parse', '--verify', '--quiet', tagRef]).ok) {
317-
const subject = git(['log', '-1', '--format=%s', 'HEAD']).stdout.trim()
318-
if (!subject.startsWith(`${release}:`)) {
319-
throw new Error(`Release ${release} has no tag and HEAD is not its release commit`)
320-
}
321-
ref = 'HEAD'
322-
}
323-
// A release from before the Kubernetes sandbox provider starts no sandbox images.
324-
if (!git(['cat-file', '-e', `${ref}:${SANDBOX_IMAGES_PATH}`]).ok) {
325-
console.log(`${release} has no ${SANDBOX_IMAGES_PATH}; listing no sandbox images.`)
292+
const list = readReleaseImageList(release)
293+
if (!list) {
294+
console.log(`${release} has no ${IMAGE_LIST_PATH}; listing no sandbox images.`)
326295
return []
327296
}
328-
const shown = git(['show', `${ref}:${SANDBOX_IMAGES_PATH}`])
329-
if (!shown.ok) throw new Error(`Could not read ${SANDBOX_IMAGES_PATH} at ${ref}`)
330-
return parseSandboxImageReferences(shown.stdout)
331-
}
332-
333-
/** The references in `images.generated.json`, refusing anything that is not a string map. */
334-
export function parseSandboxImageReferences(json: string): string[] {
335-
const parsed: unknown = JSON.parse(json)
336-
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
337-
throw new Error(`${SANDBOX_IMAGES_PATH} is not an object of image references`)
338-
}
339-
const references = Object.values(parsed)
340-
if (
341-
references.length > 0 &&
342-
references.every((value): value is string => typeof value === 'string')
343-
) {
344-
return references
345-
}
346-
throw new Error(`${SANDBOX_IMAGES_PATH} holds a non-string or no image reference`)
297+
return Object.values(list)
347298
}
348299

349300
async function main(): Promise<void> {

scripts/write-chart-sandbox-images.test.ts renamed to scripts/release-image-list.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import { releaseRevision } from './write-chart-sandbox-images'
2+
import { parseImageList, releaseRevision } from './release-image-list'
33

44
describe('releaseRevision', () => {
55
it('reads the release tag when it exists', () => {
@@ -28,3 +28,25 @@ describe('releaseRevision', () => {
2828
).toThrow(/not present and HEAD .* is not its release commit; fetching the tag failed: fatal/)
2929
})
3030
})
31+
32+
describe('parseImageList', () => {
33+
it('reads every reference the release pins, by kind', () => {
34+
expect(
35+
parseImageList(
36+
'{"function": "ghcr.io/simstudioai/sandbox-function:a", "agent": "ghcr.io/simstudioai/sandbox-agent:b"}',
37+
'v1.2.3'
38+
)
39+
).toEqual({
40+
function: 'ghcr.io/simstudioai/sandbox-function:a',
41+
agent: 'ghcr.io/simstudioai/sandbox-agent:b',
42+
})
43+
})
44+
45+
it.each([
46+
['an empty map', '{}'],
47+
['a non-string reference', '{"function": 1}'],
48+
['an array', '["ghcr.io/simstudioai/sandbox-function:a"]'],
49+
])('refuses %s rather than publishing a chart without the sandbox images', (_, json) => {
50+
expect(() => parseImageList(json, 'v1.2.3')).toThrow(/images.generated.json at v1.2.3/)
51+
})
52+
})

‎scripts/release-image-list.ts‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Reads the sandbox image list a Sim release runs by default:
3+
* `apps/sim/lib/execution/remote-sandbox/kubernetes/images.generated.json` at the release tag.
4+
* Shared by the chart publish steps (`write-chart-sandbox-images.ts`, and
5+
* `generate-image-manifest.ts --release`) so they agree on which revision a release reads.
6+
*
7+
* The tag is fetched when the checkout lacks it (publish jobs check out shallow). On the release
8+
* commit itself the tag may not exist yet, since publishing does not wait for the job that cuts
9+
* it, so HEAD is read when its subject names the release (`v1.2.3: ...`, the rule helm.yml
10+
* resolves the version by). Imports only node builtins, so it runs on a CI job with no install.
11+
*/
12+
import { spawnSync } from 'node:child_process'
13+
import { dirname, resolve } from 'node:path'
14+
import { fileURLToPath } from 'node:url'
15+
16+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
17+
18+
export const IMAGE_LIST_PATH =
19+
'apps/sim/lib/execution/remote-sandbox/kubernetes/images.generated.json'
20+
21+
/** A release tag as this repository cuts them: `v1.2.3`. */
22+
export const RELEASE_TAG = /^v\d+\.\d+\.\d+$/
23+
24+
function git(args: readonly string[]): { ok: boolean; stdout: string; stderr: string } {
25+
const result = spawnSync('git', args, { cwd: ROOT, encoding: 'utf8', maxBuffer: 64 << 20 })
26+
return { ok: result.status === 0, stdout: result.stdout ?? '', stderr: result.stderr ?? '' }
27+
}
28+
29+
/**
30+
* The git revision to read `version`'s image list from: its tag when present, else HEAD when
31+
* HEAD is the release commit that will be tagged `version`. Throws otherwise, naming why.
32+
*/
33+
export function releaseRevision(input: {
34+
version: string
35+
tagPresent: boolean
36+
headSubject: string
37+
fetchError?: string
38+
}): string {
39+
if (input.tagPresent) return `refs/tags/${input.version}`
40+
if (input.headSubject.startsWith(`${input.version}:`)) return 'HEAD'
41+
throw new Error(
42+
`Release tag ${input.version} is not present and HEAD ("${input.headSubject}") is not its release commit${input.fetchError ? `; fetching the tag failed: ${input.fetchError.trim()}` : ''}`
43+
)
44+
}
45+
46+
/** The image list's references by kind, refusing anything but a non-empty map of strings. */
47+
export function parseImageList(json: string, label: string): Record<string, string> {
48+
const parsed: unknown = JSON.parse(json)
49+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
50+
throw new Error(`${IMAGE_LIST_PATH} at ${label} is not an object of image references`)
51+
}
52+
const references: Record<string, string> = {}
53+
for (const [kind, value] of Object.entries(parsed)) {
54+
if (typeof value !== 'string') {
55+
throw new Error(`${IMAGE_LIST_PATH} at ${label} holds a non-string image reference`)
56+
}
57+
references[kind] = value
58+
}
59+
if (Object.keys(references).length === 0) {
60+
throw new Error(`${IMAGE_LIST_PATH} at ${label} holds no image reference`)
61+
}
62+
return references
63+
}
64+
65+
/** Resolves {@link releaseRevision} against the repository, fetching the tag when absent. */
66+
function resolveReleaseRevision(version: string): string {
67+
const tagRef = `refs/tags/${version}`
68+
const hasTag = () => git(['rev-parse', '--verify', '--quiet', `${tagRef}^{commit}`]).ok
69+
let fetchError: string | undefined
70+
if (!hasTag()) {
71+
const fetched = git([
72+
'fetch',
73+
'--quiet',
74+
'--no-tags',
75+
'--depth',
76+
'1',
77+
'origin',
78+
`+${tagRef}:${tagRef}`,
79+
])
80+
if (!fetched.ok) fetchError = fetched.stderr
81+
}
82+
return releaseRevision({
83+
version,
84+
tagPresent: hasTag(),
85+
headSubject: git(['log', '-1', '--format=%s', 'HEAD']).stdout.trim(),
86+
fetchError,
87+
})
88+
}
89+
90+
/**
91+
* The image references `version` runs by default, by kind, or null for a release that predates
92+
* the list (it starts no Kubernetes sandbox images).
93+
*/
94+
export function readReleaseImageList(version: string): Record<string, string> | null {
95+
if (!RELEASE_TAG.test(version)) {
96+
throw new Error(`A release must be a tag like v1.2.3, got "${version}"`)
97+
}
98+
const revision = resolveReleaseRevision(version)
99+
if (!git(['cat-file', '-e', `${revision}:${IMAGE_LIST_PATH}`]).ok) return null
100+
const shown = git(['show', `${revision}:${IMAGE_LIST_PATH}`])
101+
if (!shown.ok) {
102+
throw new Error(`Could not read ${IMAGE_LIST_PATH} at ${version}: ${shown.stderr.trim()}`)
103+
}
104+
return parseImageList(shown.stdout, version)
105+
}

0 commit comments

Comments
 (0)