Files
kuber/shared/build-protocol.ts
T
2026-09-03 11:28:30 +07:00

64 lines
1.5 KiB
TypeScript

export const BUILD_PROTOCOL_VERSION = 1 as const;
export type Sha256Digest = `sha256:${string}`;
export type BuildArchitecture = "amd64" | "arm64";
export type WorkspaceFile = {
path: string;
type: "file" | "symlink";
digest: Sha256Digest;
size: number;
mode: 0o644 | 0o755 | 0o777;
};
export type WorkspaceManifest = {
version: typeof BUILD_PROTOCOL_VERSION;
files: WorkspaceFile[];
};
export type BuildSpec = {
architecture: BuildArchitecture;
image: string;
context: string;
dockerfile?: string;
target?: string;
buildArgs: string[];
workspace: Sha256Digest;
};
export type BuildRequest = {
version: typeof BUILD_PROTOCOL_VERSION;
id: string;
project: string;
service: string;
spec: BuildSpec;
};
export type BuildState = "queued" | "running" | "succeeded" | "failed";
export type BuildStatus = {
version: typeof BUILD_PROTOCOL_VERSION;
id: string;
state: BuildState;
createdAt: string;
startedAt?: string;
finishedAt?: string;
digest?: Sha256Digest;
error?: string;
};
export type BuildEvent =
| { type: "status"; status: BuildStatus }
| { type: "log"; id: string; sequence: number; message: string };
export function isSha256Digest(value: unknown): value is Sha256Digest {
return typeof value === "string" && /^sha256:[a-f0-9]{64}$/.test(value);
}
export function assertSha256Digest(
value: unknown,
): asserts value is Sha256Digest {
if (!isSha256Digest(value))
throw new Error(`Invalid SHA-256 digest: ${value}`);
}