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,211 @@
|
||||
//
|
||||
// Containers, and the compose projects they are grouped into.
|
||||
//
|
||||
// container-compose stamps com.docker.compose.project and
|
||||
// com.docker.compose.service on the containers it creates, which is the only
|
||||
// link back to a project; containers created any other way fall into an
|
||||
// ungrouped bucket.
|
||||
//
|
||||
|
||||
const { Element } = require("./Element");
|
||||
const format = require("../../Utilities/Format");
|
||||
|
||||
const PROJECT_LABEL = "com.docker.compose.project";
|
||||
const SERVICE_LABEL = "com.docker.compose.service";
|
||||
const UNGROUPED = "Containers";
|
||||
|
||||
class ContainerModel extends Element {
|
||||
constructor(json) {
|
||||
let configuration = (json && json.configuration) || {};
|
||||
let status = (json && json.status) || {};
|
||||
|
||||
super(`container:${configuration.id || json.id}`);
|
||||
|
||||
this.id = configuration.id || json.id;
|
||||
this.name = this.id;
|
||||
this.state = typeof status.state === "string" ? status.state : "unknown";
|
||||
this.labels = configuration.labels || {};
|
||||
this.image = (configuration.image && configuration.image.reference) || "";
|
||||
this.imageName = format.reference(this.image).short;
|
||||
this.platform = configuration.platform || {};
|
||||
this.startedDate = status.startedDate || null;
|
||||
this.project = this.labels[PROJECT_LABEL] || null;
|
||||
this.service = this.labels[SERVICE_LABEL] || null;
|
||||
|
||||
this.cpus = (configuration.resources && configuration.resources.cpus) || null;
|
||||
this.memory = (configuration.resources && configuration.resources.memoryInBytes) || null;
|
||||
|
||||
this.ports = (configuration.publishedPorts || []).map((port) => ({
|
||||
hostAddress: port.hostAddress,
|
||||
hostPort: port.hostPort,
|
||||
containerPort: port.containerPort,
|
||||
proto: port.proto || "tcp"
|
||||
}));
|
||||
|
||||
this.mounts = (configuration.mounts || []).map((mount) => ({
|
||||
destination: mount.destination,
|
||||
source: mount.source,
|
||||
volume: mount.type && mount.type.volume ? mount.type.volume.name : null
|
||||
}));
|
||||
|
||||
// Addresses only exist while the container is running.
|
||||
this.addresses = (status.networks || []).map((attachment) => ({
|
||||
network: attachment.network,
|
||||
hostname: stripTrailingDot(attachment.hostname),
|
||||
address: stripPrefix(attachment.ipv4Address)
|
||||
}));
|
||||
|
||||
this.hostname = this.addresses.length > 0 ? this.addresses[0].hostname : null;
|
||||
this.address = this.addresses.length > 0 ? this.addresses[0].address : null;
|
||||
}
|
||||
|
||||
get running() {
|
||||
return this.state === "running";
|
||||
}
|
||||
|
||||
get revision() {
|
||||
return `${this.state}:${this.address || ""}:${this.portSummary}`;
|
||||
}
|
||||
|
||||
get portSummary() {
|
||||
return this.ports
|
||||
.map((port) => `${port.hostPort}→${port.containerPort}/${port.proto}`)
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
// Every way this container can be reached over HTTP, most useful first:
|
||||
// published ports resolve from the host unconditionally, while the DNS
|
||||
// hostname only resolves once its domain is registered with macOS.
|
||||
get urls() {
|
||||
let urls = this.ports
|
||||
.filter((port) => port.proto === "tcp")
|
||||
.map((port) => {
|
||||
let host =
|
||||
!port.hostAddress || port.hostAddress === "0.0.0.0" ? "localhost" : port.hostAddress;
|
||||
return {
|
||||
url: `http://${host}:${port.hostPort}`,
|
||||
label: `http://${host}:${port.hostPort} → container port ${port.containerPort}`
|
||||
};
|
||||
});
|
||||
|
||||
if (this.running && this.hostname) {
|
||||
urls.push({ url: `http://${this.hostname}`, label: `http://${this.hostname} (DNS name)` });
|
||||
}
|
||||
|
||||
if (this.running && this.address) {
|
||||
urls.push({ url: `http://${this.address}`, label: `http://${this.address} (container IP)` });
|
||||
}
|
||||
|
||||
return urls;
|
||||
}
|
||||
|
||||
get url() {
|
||||
let urls = this.urls;
|
||||
return urls.length > 0 ? urls[0].url : null;
|
||||
}
|
||||
|
||||
get tooltip() {
|
||||
let lines = [
|
||||
`Name:\t${this.name}`,
|
||||
`Image:\t${this.image}`,
|
||||
`State:\t${this.state}`
|
||||
];
|
||||
|
||||
if (this.service) {
|
||||
lines.push(`Service:\t${this.service}`);
|
||||
}
|
||||
if (this.address) {
|
||||
lines.push(`Address:\t${this.address}`);
|
||||
}
|
||||
if (this.hostname) {
|
||||
lines.push(`Hostname:\t${this.hostname}`);
|
||||
}
|
||||
if (this.ports.length > 0) {
|
||||
lines.push(`Ports:\t${this.portSummary}`);
|
||||
}
|
||||
if (this.memory) {
|
||||
lines.push(`Memory:\t${format.bytes(this.memory)}`);
|
||||
}
|
||||
if (this.cpus) {
|
||||
lines.push(`CPUs:\t${this.cpus}`);
|
||||
}
|
||||
if (this.startedDate) {
|
||||
lines.push(`Started:\t${format.age(this.startedDate)}`);
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
class ProjectModel extends Element {
|
||||
constructor(name, compose) {
|
||||
super(`project:${name}`);
|
||||
this.name = name;
|
||||
// A compose project is one the sidebar can also drive with
|
||||
// container-compose; the ungrouped bucket is not.
|
||||
this.compose = compose;
|
||||
this.file = null;
|
||||
this.expanded = true;
|
||||
}
|
||||
|
||||
get running() {
|
||||
return this.children.some((child) => child.running);
|
||||
}
|
||||
|
||||
get summary() {
|
||||
let running = this.children.filter((child) => child.running).length;
|
||||
return `${running}/${this.children.length} running`;
|
||||
}
|
||||
|
||||
get revision() {
|
||||
return `${this.file || ""}:${this.summary}`;
|
||||
}
|
||||
}
|
||||
|
||||
function stripTrailingDot(hostname) {
|
||||
if (!hostname) {
|
||||
return null;
|
||||
}
|
||||
return String(hostname).replace(/\.$/, "");
|
||||
}
|
||||
|
||||
function stripPrefix(cidr) {
|
||||
if (!cidr) {
|
||||
return null;
|
||||
}
|
||||
return String(cidr).split("/")[0];
|
||||
}
|
||||
|
||||
// Builds the container tree. Returns projects when grouping is on, and a flat
|
||||
// list of containers when it is off.
|
||||
function build(list, options = {}) {
|
||||
let containers = (list || []).map((entry) => new ContainerModel(entry));
|
||||
|
||||
containers.sort((left, right) => left.name.localeCompare(right.name));
|
||||
|
||||
if (!options.group) {
|
||||
return containers;
|
||||
}
|
||||
|
||||
let projects = new Map();
|
||||
|
||||
for (let container of containers) {
|
||||
let name = container.project || UNGROUPED;
|
||||
|
||||
if (!projects.has(name)) {
|
||||
projects.set(name, new ProjectModel(name, container.project !== null));
|
||||
}
|
||||
|
||||
projects.get(name).addChild(container);
|
||||
}
|
||||
|
||||
// Ungrouped containers sort last, everything else alphabetically.
|
||||
return [...projects.values()].sort((left, right) => {
|
||||
if (left.compose !== right.compose) {
|
||||
return left.compose ? -1 : 1;
|
||||
}
|
||||
return left.name.localeCompare(right.name);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { ContainerModel, ProjectModel, build, PROJECT_LABEL, SERVICE_LABEL };
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Shared base for everything shown in the sidebar trees.
|
||||
//
|
||||
|
||||
class Element {
|
||||
constructor(identifier) {
|
||||
this.identifier = identifier;
|
||||
this.children = [];
|
||||
this.parent = null;
|
||||
this.expanded = false;
|
||||
}
|
||||
|
||||
addChild(child) {
|
||||
child.parent = this;
|
||||
this.children.push(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
get hasChildren() {
|
||||
return this.children.length > 0;
|
||||
}
|
||||
|
||||
// Everything about the element that should trigger a tree reload when it
|
||||
// changes. Identity is compared separately.
|
||||
get revision() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { Element };
|
||||
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// Images, optionally grouped by repository.
|
||||
//
|
||||
|
||||
const { Element } = require("./Element");
|
||||
const format = require("../../Utilities/Format");
|
||||
|
||||
const INFRA_PREFIXES = [
|
||||
"ghcr.io/apple/container-builder-shim/",
|
||||
"ghcr.io/apple/containerization/vminit"
|
||||
];
|
||||
|
||||
class ImageModel extends Element {
|
||||
constructor(json) {
|
||||
let configuration = (json && json.configuration) || {};
|
||||
|
||||
super(`image:${configuration.name}`);
|
||||
|
||||
this.reference = configuration.name || "";
|
||||
this.digest = (configuration.descriptor && configuration.descriptor.digest) || "";
|
||||
// The CLI identifies images by the first twelve hex digits of the digest.
|
||||
this.shortDigest = this.digest.replace(/^[a-z0-9]+:/, "").slice(0, 12);
|
||||
this.id = json.id || "";
|
||||
this.created = configuration.creationDate || null;
|
||||
|
||||
let parts = format.reference(this.reference);
|
||||
this.registry = parts.registry;
|
||||
this.repository = parts.repository;
|
||||
this.tag = parts.tag;
|
||||
this.short = parts.short;
|
||||
|
||||
this.variants = (json.variants || []).map((variant) => ({
|
||||
architecture: (variant.platform && variant.platform.architecture) || "",
|
||||
os: (variant.platform && variant.platform.os) || "",
|
||||
size: variant.size || 0
|
||||
}));
|
||||
|
||||
this.size = this.variants.reduce((total, variant) => total + variant.size, 0);
|
||||
}
|
||||
|
||||
get revision() {
|
||||
return `${this.digest}:${this.size}`;
|
||||
}
|
||||
|
||||
get infrastructure() {
|
||||
return INFRA_PREFIXES.some((prefix) => this.reference.startsWith(prefix));
|
||||
}
|
||||
|
||||
get platforms() {
|
||||
return this.variants
|
||||
.map((variant) => (variant.os ? `${variant.os}/${variant.architecture}` : variant.architecture))
|
||||
.filter((platform) => platform.length > 0)
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
get tooltip() {
|
||||
let lines = [`Image:\t${this.reference}`, `Digest:\t${this.shortDigest}`];
|
||||
|
||||
if (this.platforms) {
|
||||
lines.push(`Platform:\t${this.platforms}`);
|
||||
}
|
||||
if (this.size) {
|
||||
lines.push(`Size:\t${format.bytes(this.size)}`);
|
||||
}
|
||||
if (this.created) {
|
||||
lines.push(`Created:\t${format.age(this.created)}`);
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
class RepositoryModel extends Element {
|
||||
constructor(name) {
|
||||
super(`repository:${name}`);
|
||||
this.name = name;
|
||||
this.expanded = true;
|
||||
}
|
||||
|
||||
get size() {
|
||||
return this.children.reduce((total, image) => total + image.size, 0);
|
||||
}
|
||||
|
||||
get revision() {
|
||||
return String(this.size);
|
||||
}
|
||||
}
|
||||
|
||||
function build(list, options = {}) {
|
||||
let images = (list || []).map((entry) => new ImageModel(entry));
|
||||
|
||||
if (!options.infrastructure) {
|
||||
images = images.filter((image) => !image.infrastructure);
|
||||
}
|
||||
|
||||
let label = (image) => (options.registry ? image.reference : `${image.short}:${image.tag}`);
|
||||
|
||||
images.sort((left, right) => label(left).localeCompare(label(right)));
|
||||
|
||||
if (!options.group) {
|
||||
return images;
|
||||
}
|
||||
|
||||
let repositories = new Map();
|
||||
|
||||
for (let image of images) {
|
||||
let name = options.registry && image.registry ? `${image.registry}/${image.repository}` : image.short;
|
||||
|
||||
if (!repositories.has(name)) {
|
||||
repositories.set(name, new RepositoryModel(name));
|
||||
}
|
||||
|
||||
repositories.get(name).addChild(image);
|
||||
}
|
||||
|
||||
return [...repositories.values()].sort((left, right) => left.name.localeCompare(right.name));
|
||||
}
|
||||
|
||||
module.exports = { ImageModel, RepositoryModel, build };
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// Networks.
|
||||
//
|
||||
|
||||
const { Element } = require("./Element");
|
||||
|
||||
const ROLE_LABEL = "com.apple.container.resource.role";
|
||||
|
||||
class NetworkModel extends Element {
|
||||
constructor(json) {
|
||||
let configuration = (json && json.configuration) || {};
|
||||
let status = (json && json.status) || {};
|
||||
|
||||
super(`network:${configuration.name || json.id}`);
|
||||
|
||||
this.name = configuration.name || json.id;
|
||||
this.mode = configuration.mode || "";
|
||||
this.plugin = configuration.plugin || "";
|
||||
this.created = configuration.creationDate || null;
|
||||
this.labels = configuration.labels || {};
|
||||
this.subnet = status.ipv4Subnet || "";
|
||||
this.gateway = status.ipv4Gateway || "";
|
||||
this.subnet6 = status.ipv6Subnet || "";
|
||||
}
|
||||
|
||||
get revision() {
|
||||
return `${this.subnet}:${this.gateway}:${this.mode}`;
|
||||
}
|
||||
|
||||
get builtin() {
|
||||
return this.labels[ROLE_LABEL] === "builtin";
|
||||
}
|
||||
|
||||
get tooltip() {
|
||||
let lines = [`Network:\t${this.name}`];
|
||||
|
||||
if (this.mode) {
|
||||
lines.push(`Mode:\t${this.mode}`);
|
||||
}
|
||||
if (this.subnet) {
|
||||
lines.push(`Subnet:\t${this.subnet}`);
|
||||
}
|
||||
if (this.gateway) {
|
||||
lines.push(`Gateway:\t${this.gateway}`);
|
||||
}
|
||||
if (this.plugin) {
|
||||
lines.push(`Plugin:\t${this.plugin}`);
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
function build(list) {
|
||||
return (list || [])
|
||||
.map((entry) => new NetworkModel(entry))
|
||||
.sort((left, right) => left.name.localeCompare(right.name));
|
||||
}
|
||||
|
||||
module.exports = { NetworkModel, build };
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// Volumes.
|
||||
//
|
||||
|
||||
const { Element } = require("./Element");
|
||||
const format = require("../../Utilities/Format");
|
||||
|
||||
class VolumeModel extends Element {
|
||||
constructor(json) {
|
||||
let configuration = (json && json.configuration) || {};
|
||||
|
||||
super(`volume:${configuration.name || json.id}`);
|
||||
|
||||
this.name = configuration.name || json.id;
|
||||
this.driver = configuration.driver || "";
|
||||
this.filesystem = configuration.format || "";
|
||||
this.source = configuration.source || "";
|
||||
// The volume image is sparse: sizeInBytes is the maximum it can grow
|
||||
// to, not what it occupies, so it is reported as capacity.
|
||||
this.capacity = configuration.sizeInBytes || 0;
|
||||
this.created = configuration.creationDate || null;
|
||||
this.labels = configuration.labels || {};
|
||||
}
|
||||
|
||||
get revision() {
|
||||
return `${this.capacity}:${this.filesystem}`;
|
||||
}
|
||||
|
||||
get tooltip() {
|
||||
let lines = [`Volume:\t${this.name}`, `Driver:\t${this.driver}`];
|
||||
|
||||
if (this.filesystem) {
|
||||
lines.push(`Format:\t${this.filesystem}`);
|
||||
}
|
||||
if (this.capacity) {
|
||||
lines.push(`Capacity:\t${format.bytes(this.capacity)}`);
|
||||
}
|
||||
if (this.created) {
|
||||
lines.push(`Created:\t${format.age(this.created)}`);
|
||||
}
|
||||
if (this.source) {
|
||||
lines.push(`Source:\t${this.source}`);
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
function build(list) {
|
||||
return (list || [])
|
||||
.map((entry) => new VolumeModel(entry))
|
||||
.sort((left, right) => left.name.localeCompare(right.name));
|
||||
}
|
||||
|
||||
module.exports = { VolumeModel, build };
|
||||
Reference in New Issue
Block a user