Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add layering for OCI #290

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/runtime/lib/elements/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,14 @@ export class ContainerElement extends HTMLElement {
return { resultType: "terminated" };
}
console.error(e);
this.terminal.write(`\nRunno crashed: ${e}`);
if (
e != null &&
(e instanceof Error || (typeof e === "object" && "message" in e))
) {
this.terminal.write(
`\n[Crashed] ${(e as any).type ?? "Error"}: ${e.message}\n`
);
}
return { resultType: "crash", error: makeRunnoError(e) };
} finally {
this.workerHost = undefined;
Expand Down
9 changes: 8 additions & 1 deletion packages/runtime/lib/elements/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ export class TerminalElement extends HTMLElement {
return { resultType: "terminated" };
}
console.error(e);
this.terminal.write(`\nRunno crashed: ${e}`);
if (
e != null &&
(e instanceof Error || (typeof e === "object" && "message" in e))
) {
this.terminal.write(
`\n[Crashed] ${(e as any).type ?? "Error"}: ${e.message}\n`
);
}
return { resultType: "crash", error: makeRunnoError(e) };
} finally {
this.workerHost = undefined;
Expand Down
9 changes: 8 additions & 1 deletion packages/runtime/lib/elements/wasi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,14 @@ export class WASIElement extends HTMLElement {
return { resultType: "terminated" };
}
console.error(e);
this.terminal.write(`\nRunno crashed: ${e}`);
if (
e != null &&
(e instanceof Error || (typeof e === "object" && "message" in e))
) {
this.terminal.write(
`\n[Crashed] ${(e as any).type ?? "Error"}: ${e.message}\n`
);
}
return { resultType: "crash", error: makeRunnoError(e) };
} finally {
this.workerHost = undefined;
Expand Down
31 changes: 27 additions & 4 deletions packages/runtime/lib/oci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ type OCIContext = {
export async function extractOCIFile(binary: Uint8Array): Promise<OCIContext> {
const contents = await extractTarGz(binary);

// TODO: throw if the file doesn't exist or whatever
const manifestFile = contents["/manifest.json"];
const manifest = fileToJSON(manifestFile)[0];

// TODO: throw if the file doesn't exist or whatever
const configPath = manifest["Config"];

const config = fileToJSON(contents[`/${configPath}`]);
Expand All @@ -33,9 +31,34 @@ export async function extractOCIFile(binary: Uint8Array): Promise<OCIContext> {
})
);

// TODO: Implement the OCI spec for layering
// OCI spec for layering includes whiteout / deleting files
// https://github.com/opencontainers/image-spec/blob/main/layer.md
const fs = layers.reduce((prev, current) => ({ ...prev, ...current }), {});
const fs = layers.reduce((prev, current) => {
// Whiteout files must be applied first

const entries = Object.entries(current);
for (const [path] of entries) {
if (path.endsWith(".wh..wh..opq")) {
// Opaque whiteout, delete all siblings
const prefix = path.replace(".wh..wh..opq", "");
for (const [existingPath] of Object.entries(prev)) {
if (existingPath.startsWith(prefix)) {
delete prev[existingPath];
}
}
} else if (path.includes(".wh.")) {
// Regular whiteout - just delete this one file
const filename = path.replace(".wh.", "");
delete prev[filename];
}
}

const currentWithoutWhiteouts = Object.fromEntries(
entries.filter(([p]) => !p.includes(".wh."))
);

return { ...prev, ...currentWithoutWhiteouts };
}, {});

return {
fs,
Expand Down
18 changes: 16 additions & 2 deletions packages/runtime/lib/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ export class RunnoProvider implements RuntimeMethods {
fs = prepare.fs;
} catch (e) {
console.error(e);
this.terminal.terminal.write(`\nRunno crashed: ${e}\n`);
if (
e != null &&
(e instanceof Error || (typeof e === "object" && "message" in e))
) {
this.terminal.terminal.write(
`\n[Crashed] ${(e as any).type ?? "Error"}: ${e.message}\n`
);
}

return {
resultType: "crash",
Expand All @@ -102,7 +109,14 @@ export class RunnoProvider implements RuntimeMethods {
fs = { ...fs, ...baseFS };
} catch (e) {
console.error(e);
this.terminal.terminal.write(`\nRunno crashed: ${e}\n`);
if (
e != null &&
(e instanceof Error || (typeof e === "object" && "message" in e))
) {
this.terminal.terminal.write(
`\n[Crashed] ${(e as any).type ?? "Error"}: ${e.message}\n`
);
}

return {
resultType: "crash",
Expand Down
Loading