feat: recover interrupted installation preparation safely
This commit is contained in:
@@ -4,6 +4,7 @@ import { mkdirSync, mkdtempSync, realpathSync, existsSync, readFileSync, rmSync,
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import { randomBytes } from 'node:crypto';
|
||||
import { parse } from 'yaml';
|
||||
import { prepareBundle } from './release-bundle.mjs';
|
||||
import { commandRunner } from './publish-installation.mjs';
|
||||
@@ -24,14 +25,17 @@ export async function buildSourceImages({ run, source, output, revision, version
|
||||
const images = {};
|
||||
for (const role of ['core', 'frontend']) {
|
||||
const iid = join(output, `${role}.iid`);
|
||||
await run('docker', ['buildx', 'build', '--load', '--platform', platform, '--file', `docker/${role}.Dockerfile`,
|
||||
const localTag = `thothii-source-${role}:${randomBytes(16).toString('hex')}`;
|
||||
await run('docker', ['buildx', 'build', '--load', '--tag', localTag, '--platform', platform, '--file', `docker/${role}.Dockerfile`,
|
||||
'--iidfile', iid, '--build-arg', `IMAGE_VERSION=${version}`, '--label', `org.opencontainers.image.revision=${revision}`,
|
||||
'--label', `org.opencontainers.image.version=${version}`, '--provenance=false', '--sbom=false', '.'], { cwd: source, timeout: 45 * 60_000 });
|
||||
const id = readFileSync(iid, 'utf8').trim();
|
||||
if (!/^sha256:[a-f0-9]{64}$/.test(id)) throw new Error('Source build did not produce an immutable local image identity.');
|
||||
const image = JSON.parse(await run('docker', ['image', 'inspect', '--format', '{{json .}}', id], { quiet: true }));
|
||||
if (image.Id !== id || `${image.Os}/${image.Architecture}` !== platform || image.Config?.Labels?.['org.opencontainers.image.revision'] !== revision || image.Config?.Labels?.['org.opencontainers.image.version'] !== version) throw new Error('Built image identity differs from the selected source.');
|
||||
images[role] = id;
|
||||
// Containerd and classic Docker stores expose different IDs; resolve the local
|
||||
// daemon identity through our unique build tag, then pin that immutable ID.
|
||||
const image = JSON.parse(await run('docker', ['image', 'inspect', '--format', '{{json .}}', localTag], { quiet: true }));
|
||||
if (!/^sha256:[a-f0-9]{64}$/.test(image.Id ?? '') || `${image.Os}/${image.Architecture}` !== platform || image.Config?.Labels?.['org.opencontainers.image.revision'] !== revision || image.Config?.Labels?.['org.opencontainers.image.version'] !== version) throw new Error('Built image identity differs from the selected source.');
|
||||
images[role] = image.Id;
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user