Build the Apple Container extension
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
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
const { statusIcon } = require("./StatusIcon");
|
||||
|
||||
class ContainerTreeItem extends TreeItem {
|
||||
constructor(container) {
|
||||
super(label(container), TreeItemCollapsibleState.None);
|
||||
|
||||
this.identifier = container.identifier;
|
||||
this.image = statusIcon(container.running);
|
||||
this.contextValue = container.running ? "container.running" : "container.stopped";
|
||||
this.tooltip = container.tooltip;
|
||||
this.descriptiveText = description(container);
|
||||
}
|
||||
}
|
||||
|
||||
function label(container) {
|
||||
switch (nova.config.get("apple_container.containers.label", "string")) {
|
||||
case "Image":
|
||||
return container.imageName;
|
||||
case "Service":
|
||||
return container.service || container.name;
|
||||
default:
|
||||
return container.name;
|
||||
}
|
||||
}
|
||||
|
||||
function description(container) {
|
||||
let parts = [];
|
||||
|
||||
if (nova.config.get("apple_container.containers.desc.image", "boolean")) {
|
||||
parts.push(container.imageName);
|
||||
}
|
||||
if (nova.config.get("apple_container.containers.desc.ports", "boolean") && container.ports.length > 0) {
|
||||
parts.push(container.portSummary);
|
||||
}
|
||||
if (nova.config.get("apple_container.containers.desc.address", "boolean") && container.address) {
|
||||
parts.push(container.address);
|
||||
}
|
||||
if (nova.config.get("apple_container.containers.desc.state", "boolean")) {
|
||||
parts.push(container.state);
|
||||
}
|
||||
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
module.exports = { ContainerTreeItem };
|
||||
@@ -0,0 +1,38 @@
|
||||
const format = require("../../Utilities/Format");
|
||||
|
||||
class ImageTreeItem extends TreeItem {
|
||||
constructor(image, options = {}) {
|
||||
super(options.grouped ? image.tag : label(image), TreeItemCollapsibleState.None);
|
||||
|
||||
this.identifier = image.identifier;
|
||||
this.image = "icons/tag.png";
|
||||
this.contextValue = "image.tag";
|
||||
this.tooltip = image.tooltip;
|
||||
this.descriptiveText = [format.bytes(image.size), format.age(image.created)]
|
||||
.filter((part) => part.length > 0)
|
||||
.join(" ");
|
||||
}
|
||||
}
|
||||
|
||||
class RepositoryTreeItem extends TreeItem {
|
||||
constructor(repository) {
|
||||
super(
|
||||
repository.name,
|
||||
repository.expanded ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed
|
||||
);
|
||||
|
||||
this.identifier = repository.identifier;
|
||||
this.image = "icons/layers.png";
|
||||
this.contextValue = "image.repo";
|
||||
this.descriptiveText = format.bytes(repository.size);
|
||||
this.tooltip = repository.name;
|
||||
}
|
||||
}
|
||||
|
||||
function label(image) {
|
||||
return nova.config.get("apple_container.images.registry", "boolean")
|
||||
? image.reference
|
||||
: `${image.short}:${image.tag}`;
|
||||
}
|
||||
|
||||
module.exports = { ImageTreeItem, RepositoryTreeItem };
|
||||
@@ -0,0 +1,15 @@
|
||||
class NetworkTreeItem extends TreeItem {
|
||||
constructor(network) {
|
||||
super(network.name, TreeItemCollapsibleState.None);
|
||||
|
||||
this.identifier = network.identifier;
|
||||
this.image = "icons/network.png";
|
||||
this.contextValue = "network";
|
||||
this.tooltip = network.tooltip;
|
||||
this.descriptiveText = [network.subnet, network.mode]
|
||||
.filter((part) => part && part.length > 0)
|
||||
.join(" ");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { NetworkTreeItem };
|
||||
@@ -0,0 +1,18 @@
|
||||
class ProjectTreeItem extends TreeItem {
|
||||
constructor(project) {
|
||||
super(
|
||||
project.name,
|
||||
project.expanded ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed
|
||||
);
|
||||
|
||||
this.identifier = project.identifier;
|
||||
this.image = project.compose ? "icons/layers.png" : "icons/folder.png";
|
||||
// Compose projects gain the compose commands; the ungrouped bucket only
|
||||
// gets the bulk start and stop.
|
||||
this.contextValue = project.compose ? "project.compose" : "project";
|
||||
this.descriptiveText = project.summary;
|
||||
this.tooltip = project.file ? `Compose file:\t${project.file}` : project.name;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { ProjectTreeItem };
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Maps a running/stopped state onto the icon set chosen in preferences.
|
||||
//
|
||||
|
||||
const SETS = {
|
||||
"Traffic Lights": ["icons/status/traffic-on.png", "icons/status/traffic-off.png"],
|
||||
Toggles: ["icons/status/toggle-on.png", "icons/status/toggle-off.png"],
|
||||
Power: ["icons/status/power-on.png", "icons/status/power-off.png"]
|
||||
};
|
||||
|
||||
function statusIcon(running) {
|
||||
let set = SETS[nova.config.get("apple_container.containers.icons", "string")] || SETS["Traffic Lights"];
|
||||
return running ? set[0] : set[1];
|
||||
}
|
||||
|
||||
module.exports = { statusIcon };
|
||||
@@ -0,0 +1,15 @@
|
||||
const { statusIcon } = require("./StatusIcon");
|
||||
|
||||
class SystemTreeItem extends TreeItem {
|
||||
constructor(row) {
|
||||
super(row.label, TreeItemCollapsibleState.None);
|
||||
|
||||
this.identifier = row.identifier;
|
||||
this.contextValue = row.contextValue;
|
||||
this.descriptiveText = row.description || "";
|
||||
this.tooltip = row.tooltip || row.label;
|
||||
this.image = row.running === undefined ? row.image || "icons/system.png" : statusIcon(row.running);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { SystemTreeItem };
|
||||
@@ -0,0 +1,17 @@
|
||||
class VolumeTreeItem extends TreeItem {
|
||||
constructor(volume) {
|
||||
super(volume.name, TreeItemCollapsibleState.None);
|
||||
|
||||
this.identifier = volume.identifier;
|
||||
this.image = "icons/volume.png";
|
||||
this.contextValue = "volume";
|
||||
this.tooltip = volume.tooltip;
|
||||
// Volume images are sparse, so a size here would only mislead; the
|
||||
// capacity is in the tooltip instead.
|
||||
this.descriptiveText = [volume.driver, volume.filesystem]
|
||||
.filter((part) => part && part.length > 0)
|
||||
.join(" ");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { VolumeTreeItem };
|
||||
Reference in New Issue
Block a user