|
26 | 26 | * committed file leaves them out, since their content-addressed tags change with |
27 | 27 | * every sandbox image rebuild and would otherwise force a chart version bump. |
28 | 28 | */ |
29 | | -import { spawnSync } from 'node:child_process' |
30 | 29 | import { readFile, writeFile } from 'node:fs/promises' |
31 | 30 | import { dirname, resolve } from 'node:path' |
32 | 31 | import { fileURLToPath } from 'node:url' |
| 32 | +import { IMAGE_LIST_PATH, readReleaseImageList } from './release-image-list' |
33 | 33 |
|
34 | 34 | const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url)) |
35 | 35 | const ROOT = resolve(SCRIPT_DIR, '..') |
@@ -74,15 +74,6 @@ const RENDER_ARGS = [ |
74 | 74 | 'sandbox.kubernetes.images.doc.tag=main-REPLACE', |
75 | 75 | ] as const |
76 | 76 |
|
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 | | - |
86 | 77 | /** |
87 | 78 | * Sentinel registry used for the second render. |
88 | 79 | * |
@@ -293,57 +284,17 @@ function renderChart(args: readonly string[] = RENDER_ARGS): unknown[] { |
293 | 284 | return Array.isArray(documents) ? documents : [documents] |
294 | 285 | } |
295 | 286 |
|
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 | | - |
301 | 287 | /** |
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. |
306 | 290 | */ |
307 | 291 | 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.`) |
326 | 295 | return [] |
327 | 296 | } |
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) |
347 | 298 | } |
348 | 299 |
|
349 | 300 | async function main(): Promise<void> { |
|
0 commit comments