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
117 lines
2.9 KiB
JavaScript
117 lines
2.9 KiB
JavaScript
//
|
|
// Volumes section.
|
|
//
|
|
|
|
const { Controller } = require("./Controller");
|
|
const { VolumeTreeItem } = require("../TreeItems/VolumeTreeItem");
|
|
const { ContainerCLI } = require("../../Interfaces/ContainerCLI");
|
|
const { exec } = require("../../Utilities/Process");
|
|
const volumes = require("../Models/Volume");
|
|
const notify = require("../../Utilities/Notify");
|
|
const prompt = require("../../Utilities/Prompt");
|
|
|
|
class VolumesController extends Controller {
|
|
constructor(sidebar) {
|
|
super("apple_container.volumes");
|
|
this.sidebar = sidebar;
|
|
this.registerCommands();
|
|
}
|
|
|
|
async fetch() {
|
|
return volumes.build(await ContainerCLI.listVolumes());
|
|
}
|
|
|
|
getTreeItem(element) {
|
|
return new VolumeTreeItem(element);
|
|
}
|
|
|
|
registerCommands() {
|
|
this.register("apple_container.volumes.reload", () => this.reload());
|
|
|
|
this.register("apple_container.volumes.create", async () => {
|
|
let name = await prompt.input("Volume name", { placeholder: "database-data" });
|
|
|
|
if (!name) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await ContainerCLI.createVolume(name);
|
|
} catch (error) {
|
|
notify.failure("Unable to create volume", error, "apple-container-volume");
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
|
|
this.register("apple_container.volumes.inspect", async () => {
|
|
for (let volume of this.selection) {
|
|
try {
|
|
let output = await ContainerCLI.inspectVolume(volume.name);
|
|
nova.workspace.openNewTextDocument({ content: output, syntax: "json" });
|
|
} catch (error) {
|
|
notify.failure("Unable to inspect volume", error, "apple-container-inspect");
|
|
}
|
|
}
|
|
});
|
|
|
|
this.register("apple_container.volumes.reveal", async () => {
|
|
for (let volume of this.selection) {
|
|
if (!volume.source) {
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
await exec("/usr/bin/open", ["-R", volume.source]);
|
|
} catch (error) {
|
|
notify.failure("Unable to reveal volume", error, "apple-container-reveal");
|
|
}
|
|
}
|
|
});
|
|
|
|
this.register("apple_container.volumes.copy", () => {
|
|
let volume = this.selection[0];
|
|
|
|
if (volume) {
|
|
nova.clipboard.writeText(volume.name);
|
|
}
|
|
});
|
|
|
|
this.register("apple_container.volumes.delete", async () => {
|
|
let names = this.selection.map((volume) => volume.name);
|
|
|
|
if (names.length === 0) {
|
|
return;
|
|
}
|
|
|
|
if (!(await prompt.confirm(`Delete ${names.join(", ")}? Their contents are lost.`))) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await ContainerCLI.deleteVolumes(names);
|
|
} catch (error) {
|
|
notify.failure("Unable to delete volume", error, "apple-container-delete-volume");
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
|
|
this.register("apple_container.volumes.prune", async () => {
|
|
if (!(await prompt.confirm("Remove volumes no container references?", "Remove"))) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await ContainerCLI.pruneVolumes();
|
|
} catch (error) {
|
|
notify.failure("Unable to prune volumes", error, "apple-container-prune-volume");
|
|
}
|
|
|
|
this.reload();
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = { VolumesController };
|