Turns the empty scaffold into a working Nova extension for Apple Container and container-compose, in the shape of the Docker Suite extension. Sidebar (Scripts/Sidebar): - System, Containers, Images, Volumes and Networks sections - Containers grouped into compose projects via the com.docker.compose.project label container-compose stamps; project rows drive compose up/down/build against the matching workspace file - Lifecycle, shell, logs, inspect, browse and copy commands per resource - Apple Container publishes no event stream, so the sidebar polls while visible and only reloads a section when a fingerprint of its data changes, which keeps selection and expansion intact Hostnames (Scripts/Hostnames.js): - A container's hostname is <name>.<domain> and the domain lives in Apple Container's config.toml, which has no CLI setter, so the Hostname Domain preference reads and writes that file directly - Changing it offers to register the domain with macOS and restart the services; the write preserves the file's other tables and its mode Language support: - Dockerfile and Compose syntaxes backed by tree-sitter grammars built by Tools/build-syntaxes.sh, pinned to revisions that generate ABI 14 - The Compose syntax is named dockercompose because that is the languageId docker-language-server recognises compose files by - docker-language-server is downloaded on first use rather than bundled, at roughly 40 MB Icons are generated by Tools/make-icons.py so they can be regenerated rather than hand-maintained. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UnSBcR5Lywz5Fbj5FmVbfc
199 lines
5.1 KiB
JavaScript
199 lines
5.1 KiB
JavaScript
//
|
|
// Images section, optionally grouped by repository.
|
|
//
|
|
|
|
const { Controller } = require("./Controller");
|
|
const { ImageTreeItem, RepositoryTreeItem } = require("../TreeItems/ImageTreeItem");
|
|
const { ContainerCLI } = require("../../Interfaces/ContainerCLI");
|
|
const { Terminal } = require("../../Interfaces/Terminal");
|
|
const images = require("../Models/Image");
|
|
const notify = require("../../Utilities/Notify");
|
|
const prompt = require("../../Utilities/Prompt");
|
|
|
|
class ImagesController extends Controller {
|
|
constructor(sidebar) {
|
|
super("apple_container.images");
|
|
this.sidebar = sidebar;
|
|
this.registerCommands();
|
|
}
|
|
|
|
async fetch() {
|
|
let list = await ContainerCLI.listImages();
|
|
|
|
return images.build(list, {
|
|
group: nova.config.get("apple_container.images.group", "boolean") !== false,
|
|
registry: nova.config.get("apple_container.images.registry", "boolean") === true,
|
|
infrastructure: nova.config.get("apple_container.images.infra", "boolean") === true
|
|
});
|
|
}
|
|
|
|
getTreeItem(element) {
|
|
if (element instanceof images.RepositoryModel) {
|
|
return new RepositoryTreeItem(element);
|
|
}
|
|
|
|
return new ImageTreeItem(element, { grouped: element.parent !== null });
|
|
}
|
|
|
|
// References for the current selection, expanding repositories into tags.
|
|
selectedReferences() {
|
|
let selected = [];
|
|
|
|
for (let element of this.selection) {
|
|
if (element instanceof images.RepositoryModel) {
|
|
selected = selected.concat(element.children.map((image) => image.reference));
|
|
} else {
|
|
selected.push(element.reference);
|
|
}
|
|
}
|
|
|
|
return selected;
|
|
}
|
|
|
|
registerCommands() {
|
|
this.register("apple_container.images.reload", () => this.reload());
|
|
|
|
this.register("apple_container.images.run", async () => {
|
|
let reference = this.selectedReferences()[0];
|
|
|
|
if (!reference) {
|
|
return;
|
|
}
|
|
|
|
await runImage(reference);
|
|
this.sidebar.reloadContainers();
|
|
});
|
|
|
|
this.register("apple_container.images.pull", async () => {
|
|
for (let reference of this.selectedReferences()) {
|
|
try {
|
|
await ContainerCLI.pullImage(reference);
|
|
} catch (error) {
|
|
notify.failure(`Unable to pull ${reference}`, error, "apple-container-pull");
|
|
}
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
|
|
this.register("apple_container.images.push", async () => {
|
|
for (let reference of this.selectedReferences()) {
|
|
try {
|
|
await ContainerCLI.pushImage(reference);
|
|
notify.info("Push complete", reference, "apple-container-push");
|
|
} catch (error) {
|
|
notify.failure(`Unable to push ${reference}`, error, "apple-container-push");
|
|
}
|
|
}
|
|
});
|
|
|
|
this.register("apple_container.images.tag", async () => {
|
|
let reference = this.selectedReferences()[0];
|
|
|
|
if (!reference) {
|
|
return;
|
|
}
|
|
|
|
let target = await prompt.input("New tag", { placeholder: reference, value: reference });
|
|
|
|
if (!target) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await ContainerCLI.tagImage(reference, target);
|
|
} catch (error) {
|
|
notify.failure("Unable to tag image", error, "apple-container-tag");
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
|
|
this.register("apple_container.images.inspect", async () => {
|
|
for (let reference of this.selectedReferences()) {
|
|
try {
|
|
let output = await ContainerCLI.inspectImage(reference);
|
|
nova.workspace.openNewTextDocument({ content: output, syntax: "json" });
|
|
} catch (error) {
|
|
notify.failure("Unable to inspect image", error, "apple-container-inspect");
|
|
}
|
|
}
|
|
});
|
|
|
|
this.register("apple_container.images.copy", () => {
|
|
let reference = this.selectedReferences()[0];
|
|
|
|
if (reference) {
|
|
nova.clipboard.writeText(reference);
|
|
}
|
|
});
|
|
|
|
this.register("apple_container.images.delete", async () => {
|
|
let references = this.selectedReferences();
|
|
|
|
if (references.length === 0) {
|
|
return;
|
|
}
|
|
|
|
if (!(await prompt.confirm(`Delete ${references.join(", ")}?`))) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await ContainerCLI.deleteImages(references);
|
|
} catch (error) {
|
|
notify.failure("Unable to delete image", error, "apple-container-delete-image");
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
|
|
this.register("apple_container.images.prune", async () => {
|
|
if (!(await prompt.confirm("Remove images not referenced by a container?", "Remove"))) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await ContainerCLI.pruneImages();
|
|
} catch (error) {
|
|
notify.failure("Unable to prune images", error, "apple-container-prune-image");
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
|
|
for (let key of [
|
|
"apple_container.images.group",
|
|
"apple_container.images.registry",
|
|
"apple_container.images.infra"
|
|
]) {
|
|
this.watch(key, () => this.reload());
|
|
}
|
|
}
|
|
}
|
|
|
|
// Runs an image in the terminal, so its output is visible and an interactive
|
|
// image still works. Arguments are offered because `container run` takes no
|
|
// defaults worth guessing.
|
|
async function runImage(reference) {
|
|
let options = await prompt.input("Arguments for container run", {
|
|
placeholder: "--detach --name my-container --publish 8080:80"
|
|
});
|
|
|
|
if (options === null) {
|
|
return null;
|
|
}
|
|
|
|
let parts = [ContainerCLI.path(), "run"];
|
|
|
|
if (options) {
|
|
parts = parts.concat(options.split(/\s+/));
|
|
}
|
|
|
|
parts.push(reference);
|
|
|
|
return Terminal.run(Terminal.command(parts));
|
|
}
|
|
|
|
module.exports = { ImagesController, runImage };
|