feat: Ekklesia Module Package v1, the canonical packager and verifier (ADR 0049)
CI / verify (pull_request) Successful in 57s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m42s
CI / image-build (pull_request) Successful in 29s
CI / deploy-smoke (same-origin) (pull_request) Successful in 51s
CI / deploy-smoke (split) (pull_request) Failing after 54s
CI / verify (pull_request) Successful in 57s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m42s
CI / image-build (pull_request) Successful in 29s
CI / deploy-smoke (same-origin) (pull_request) Successful in 51s
CI / deploy-smoke (split) (pull_request) Failing after 54s
A separately versioned module is now distributed as one deterministic .tar.gz and its SHA-256, produced by an Ekklesia-owned packager and checked by Core before anything is installed. This slice implements the portable `any` target, with the module template as the end-to-end proof. ADR 0049 is accepted. @ekklesia/contracts: the Module Package v1 contract. The strict ekklesia.package.json schema (packageFormat 1, identity, target, runtime, provenance, incorporated Ekklesia packages, strict transitional facts, an exact byte-wise-sorted file list with size and SHA-256), target names, and the generated runtime package.json. @ekklesia/module-pack (new, tooling): `ekklesia-pack-module --module <dir> --target any --out <dir> --source-revision <commit>`. - Bundles server, schema, and jobs with esbuild, SDK, contracts, and Drizzle included; only Node built-ins remain imports. Any warning, unresolved import, external dependency, or native or platform-specific package fails. - Copies browser artifacts as built, after proving them current, and the migrations; generates package.json and ekklesia.package.json; never ships src, tests, declarations, source maps, or workspace ranges. - THIRD_PARTY_NOTICES: every third-party package traced from the bundles' own inputs, credited once with its declared licence and every licence, copying, copyright, and notice file it ships. A missing licence fails; a missing text fails unless its standard text is complete without copyright lines (Apache-2.0, vendored, needed by drizzle-orm). - Deterministic ustar and gzip: sorted paths, uid/gid 0, empty names, mtime 0, 0755/0644, no links. Byte-identical across runs and machines. - Writes only the archive and its .sha256; never deploys, links, or installs, so the workspace's install state is untouched. Core: verifyModulePackage and `verify-module-package.js <archive> [--sha256 | --sha256-file] [--extract-to <new dir>]`. Reads the archive in memory and refuses links, special entries, setuid/setgid/sticky modes, unsafe or escaping paths, and a second top-level directory; checks metadata, every file, identity, target, Node.js range, SDK, and the transitional Drizzle agreement; runs the platform's module and migration discovery; loads the backend once in a forked process with an empty environment; only then extracts, with normalized modes, into a new directory. Errors are sanitized. @ekklesia/module-ui-build: analyzeModuleUi reports each artifact's inputs and whether the built file is current. The nested stylesheet build now works from the module directory, so artifacts no longer depend on the caller's working directory. The split deploy smoke builds the package with the canonical packager (scripts/lib/build-module-package.Dockerfile replaces the test-only pnpm deploy packaging), verifies it with the same generic image, installs the verified tree, removes it, and reinstalls the exact same archive. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
45d6506c10
commit
35ef31df9f
@@ -0,0 +1,109 @@
|
||||
import { gzipSync } from "node:zlib";
|
||||
|
||||
/**
|
||||
* The deterministic archive encoding of Ekklesia Module Package v1 (ADR 0049).
|
||||
*
|
||||
* POSIX ustar, written by hand rather than by a general tar library, so every byte is decided here:
|
||||
* - one top-level directory, then every directory and regular file in byte-wise path order, which
|
||||
* puts every directory before what it contains;
|
||||
* - uid and gid 0, empty user and group names, modification time 0, device fields 0;
|
||||
* - directories 0755 and files 0644; no links, no special files, no extended or long-name headers;
|
||||
* - exactly two zero blocks at the end;
|
||||
* - gzip at a fixed level, with Node's header: no file name and a modification time of 0.
|
||||
*
|
||||
* The same packager version and the same input bytes therefore always produce the same archive.
|
||||
*/
|
||||
|
||||
export class TarPathError extends Error {
|
||||
readonly path: string;
|
||||
|
||||
constructor(entryPath: string) {
|
||||
super("A path does not fit a portable ustar header.");
|
||||
this.name = "TarPathError";
|
||||
this.path = entryPath;
|
||||
}
|
||||
}
|
||||
|
||||
const BLOCK = 512;
|
||||
const GZIP_LEVEL = 9;
|
||||
|
||||
function octal(value: number, width: number): string {
|
||||
return `${value.toString(8).padStart(width - 1, "0")}\u0000`;
|
||||
}
|
||||
|
||||
/** Splits a path into ustar's 155-byte prefix and 100-byte name, at a `/`. */
|
||||
function splitPath(entryPath: string): { readonly name: string; readonly prefix: string } {
|
||||
if (entryPath.length <= 100) {
|
||||
return { name: entryPath, prefix: "" };
|
||||
}
|
||||
for (let index = entryPath.length - 1; index > 0; index -= 1) {
|
||||
if (entryPath[index] === "/") {
|
||||
const prefix = entryPath.slice(0, index);
|
||||
const name = entryPath.slice(index + 1);
|
||||
if (prefix.length <= 155 && name.length > 0 && name.length <= 100) {
|
||||
return { name, prefix };
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new TarPathError(entryPath);
|
||||
}
|
||||
|
||||
function header(entryPath: string, directory: boolean, size: number): Buffer {
|
||||
const block = Buffer.alloc(BLOCK);
|
||||
const { name, prefix } = splitPath(directory ? `${entryPath}/` : entryPath);
|
||||
block.write(name, 0, 100, "latin1");
|
||||
block.write(octal(directory ? 0o755 : 0o644, 8), 100, "latin1");
|
||||
block.write(octal(0, 8), 108, "latin1");
|
||||
block.write(octal(0, 8), 116, "latin1");
|
||||
block.write(octal(size, 12), 124, "latin1");
|
||||
block.write(octal(0, 12), 136, "latin1");
|
||||
block.write(" ", 148, "latin1");
|
||||
block.write(directory ? "5" : "0", 156, "latin1");
|
||||
block.write("ustar\u000000", 257, "latin1");
|
||||
block.write(octal(0, 8), 329, "latin1");
|
||||
block.write(octal(0, 8), 337, "latin1");
|
||||
block.write(prefix, 345, 155, "latin1");
|
||||
let checksum = 0;
|
||||
for (const byte of block) {
|
||||
checksum += byte;
|
||||
}
|
||||
block.write(`${checksum.toString(8).padStart(6, "0")}\u0000 `, 148, "latin1");
|
||||
return block;
|
||||
}
|
||||
|
||||
function compareBytes(left: string, right: string): number {
|
||||
return left < right ? -1 : left > right ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Archives `files` (paths relative to the module directory, printable ASCII) under `topLevel`.
|
||||
* Directories are implied by the file paths.
|
||||
*/
|
||||
export function deterministicTarGz(topLevel: string, files: ReadonlyMap<string, Buffer>): Buffer {
|
||||
const directories = new Set<string>([topLevel]);
|
||||
for (const filePath of files.keys()) {
|
||||
const segments = filePath.split("/");
|
||||
for (let index = 1; index < segments.length; index += 1) {
|
||||
directories.add(`${topLevel}/${segments.slice(0, index).join("/")}`);
|
||||
}
|
||||
}
|
||||
const entries: { readonly path: string; readonly data?: Buffer }[] = [
|
||||
...[...directories].map((directory) => ({ path: directory })),
|
||||
...[...files].map(([filePath, data]) => ({ data, path: `${topLevel}/${filePath}` })),
|
||||
].sort((left, right) => compareBytes(left.path, right.path));
|
||||
|
||||
const parts: Buffer[] = [];
|
||||
for (const entry of entries) {
|
||||
if (entry.data === undefined) {
|
||||
parts.push(header(entry.path, true, 0));
|
||||
} else {
|
||||
parts.push(header(entry.path, false, entry.data.length), entry.data);
|
||||
const padding = (BLOCK - (entry.data.length % BLOCK)) % BLOCK;
|
||||
if (padding > 0) {
|
||||
parts.push(Buffer.alloc(padding));
|
||||
}
|
||||
}
|
||||
}
|
||||
parts.push(Buffer.alloc(BLOCK * 2));
|
||||
return gzipSync(Buffer.concat(parts), { level: GZIP_LEVEL });
|
||||
}
|
||||
Reference in New Issue
Block a user