feat: support explicit source bundles through the common installer

This commit is contained in:
Codex
2026-10-06 18:31:23 +02:00
parent 785d96ea50
commit 5c05778614
11 changed files with 353 additions and 5 deletions
@@ -0,0 +1,46 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { prepareBundle } from './release-bundle.mjs';
import { buildSourceImages, sourceOptions } from './prepare-source-installation.mjs';
test('source builds load local images from the isolated checkout without publication or secrets', async () => {
const output = mkdtempSync(join(tmpdir(), 'source-build-'));
const calls = [];
const revision = 'c'.repeat(40), version = '1.0.0-source', platform = 'linux/amd64';
const run = async (command, args, options) => {
calls.push({ command, args, options });
if (args[0] === 'buildx') {
assert.equal(options.cwd, '/isolated/committed-source');
assert.ok(args.includes('--load'));
assert.ok(!args.includes('--push'));
assert.ok(!args.includes('--secret'));
assert.deepEqual(args.filter((_, index) => args[index - 1] === '--build-arg'), [`IMAGE_VERSION=${version}`]);
writeFileSync(args[args.indexOf('--iidfile') + 1], `sha256:${'a'.repeat(64)}`);
return '';
}
return JSON.stringify({ Id: `sha256:${'a'.repeat(64)}`, Os: 'linux', Architecture: 'amd64', Config: { Labels: { 'org.opencontainers.image.revision': revision, 'org.opencontainers.image.version': version } } });
};
try {
assert.deepEqual(await buildSourceImages({ run, source: '/isolated/committed-source', output, revision, version, platform }), { core: `sha256:${'a'.repeat(64)}`, frontend: `sha256:${'a'.repeat(64)}` });
assert.equal(calls.length, 4);
assert.throws(() => sourceOptions(['--revision', 'HEAD']), /explicit/);
} finally { rmSync(output, { recursive: true, force: true }); }
});
test('source bundles identify their mode and use immutable local application images', () => {
const output = mkdtempSync(join(tmpdir(), 'source-bundle-'));
const images = Object.fromEntries(['core', 'frontend', 'catalog', 'qdrant', 'embedding'].map(role => [role,
['core', 'frontend'].includes(role) ? `sha256:${'a'.repeat(64)}` : `docker.io/example/${role}@sha256:${'b'.repeat(64)}`]));
try {
const manifest = prepareBundle({ source: resolve(import.meta.dirname, '../..'), destination: output,
platform: 'linux/arm64', version: '0.1.0-source', revision: 'c'.repeat(40), images, distribution: 'source' });
assert.equal(manifest.distribution, 'source');
assert.equal(manifest.images.core['linux/arm64'], images.core);
assert.doesNotMatch(readFileSync(join(output, 'compose.yaml'), 'utf8'), /build:/);
assert.throws(() => prepareBundle({ source: resolve(import.meta.dirname, '../..'), destination: output,
platform: 'linux/arm64', version: '0.1.0-source', revision: 'c'.repeat(40), images }), /immutable/);
} finally { rmSync(output, { recursive: true, force: true }); }
});