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
115 lines
3.1 KiB
JavaScript
115 lines
3.1 KiB
JavaScript
//
|
|
// Networks section.
|
|
//
|
|
|
|
const { Controller } = require("./Controller");
|
|
const { NetworkTreeItem } = require("../TreeItems/NetworkTreeItem");
|
|
const { ContainerCLI } = require("../../Interfaces/ContainerCLI");
|
|
const networks = require("../Models/Network");
|
|
const notify = require("../../Utilities/Notify");
|
|
const prompt = require("../../Utilities/Prompt");
|
|
|
|
class NetworksController extends Controller {
|
|
constructor(sidebar) {
|
|
super("apple_container.networks");
|
|
this.sidebar = sidebar;
|
|
this.registerCommands();
|
|
}
|
|
|
|
async fetch() {
|
|
return networks.build(await ContainerCLI.listNetworks());
|
|
}
|
|
|
|
getTreeItem(element) {
|
|
return new NetworkTreeItem(element);
|
|
}
|
|
|
|
registerCommands() {
|
|
this.register("apple_container.networks.reload", () => this.reload());
|
|
|
|
this.register("apple_container.networks.create", async () => {
|
|
// A name on its own is the common case, but `container network
|
|
// create` also takes --subnet, --internal and friends, so the whole
|
|
// argument line is accepted here.
|
|
let answer = await prompt.input("Network name, and any options", {
|
|
placeholder: "backend --subnet 192.168.70.0/24"
|
|
});
|
|
|
|
if (!answer) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await ContainerCLI.createNetwork(answer.split(/\s+/));
|
|
} catch (error) {
|
|
notify.failure("Unable to create network", error, "apple-container-network");
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
|
|
this.register("apple_container.networks.inspect", async () => {
|
|
for (let network of this.selection) {
|
|
try {
|
|
let output = await ContainerCLI.inspectNetwork(network.name);
|
|
nova.workspace.openNewTextDocument({ content: output, syntax: "json" });
|
|
} catch (error) {
|
|
notify.failure("Unable to inspect network", error, "apple-container-inspect");
|
|
}
|
|
}
|
|
});
|
|
|
|
this.register("apple_container.networks.copy", () => {
|
|
let network = this.selection[0];
|
|
|
|
if (network) {
|
|
nova.clipboard.writeText(network.subnet || network.name);
|
|
}
|
|
});
|
|
|
|
this.register("apple_container.networks.delete", async () => {
|
|
let selected = this.selection;
|
|
let builtin = selected.filter((network) => network.builtin);
|
|
|
|
if (builtin.length > 0) {
|
|
notify.info(
|
|
"Built-in network",
|
|
`${builtin.map((network) => network.name).join(", ")} is managed by Apple Container and cannot be deleted.`,
|
|
"apple-container-network-builtin"
|
|
);
|
|
return;
|
|
}
|
|
|
|
let names = selected.map((network) => network.name);
|
|
|
|
if (names.length === 0 || !(await prompt.confirm(`Delete ${names.join(", ")}?`))) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await ContainerCLI.deleteNetworks(names);
|
|
} catch (error) {
|
|
notify.failure("Unable to delete network", error, "apple-container-delete-network");
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
|
|
this.register("apple_container.networks.prune", async () => {
|
|
if (!(await prompt.confirm("Remove networks with no connected containers?", "Remove"))) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await ContainerCLI.pruneNetworks();
|
|
} catch (error) {
|
|
notify.failure("Unable to prune networks", error, "apple-container-prune-network");
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = { NetworksController };
|