Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(extensions-api): add container engine methods #4172

Merged
merged 1 commit into from Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
101 changes: 96 additions & 5 deletions packages/extension-api/src/extension-api.d.ts
Expand Up @@ -1374,6 +1374,49 @@ declare module '@podman-desktop/api' {
generate(kubernetesGeneratorArguments: KubernetesGeneratorArgument[]): Promise<GenerateKubeResult>;
}

export interface ImageInfo {
engineId: string;
engineName: string;
Id: string;
ParentId: string;
RepoTags: string[] | undefined;
RepoDigests?: string[];
Created: number;
Size: number;
VirtualSize: number;
SharedSize: number;
Labels: { [label: string]: string };
Containers: number;
}

export interface NetworkContainer {
Name: string;
EndpointID: string;
MacAddress: string;
IPv4Address: string;
IPv6Address: string;
}
export interface NetworkInspectInfo {
engineId: string;
engineName: string;
engineType: 'podman' | 'docker';
Name: string;
Id: string;
Created: string;
Scope: string;
Driver: string;
EnableIPv6: boolean;
IPAM?: IPAM;
Internal: boolean;
Attachable: boolean;
Ingress: boolean;
ConfigFrom?: { Network: string };
ConfigOnly: boolean;
Containers?: { [id: string]: NetworkContainer };
Options?: { [key: string]: string };
Labels?: { [key: string]: string };
}

export interface ContainerInfo {
engineId: string;
engineName: string;
Expand Down Expand Up @@ -1470,12 +1513,12 @@ declare module '@podman-desktop/api' {
VolumeDriver?: string;
VolumesFrom?: unknown;
Mounts?: MountConfig;
CapAdd?: unknown;
CapDrop?: unknown;
Dns?: unknown[];
CapAdd?: string[];
CapDrop?: string[];
Dns?: string[];
DnsOptions?: unknown[];
DnsSearch?: string[];
ExtraHosts?: unknown;
ExtraHosts?: string[];
GroupAdd?: string[];
IpcMode?: string;
Cgroup?: string;
Expand All @@ -1485,7 +1528,7 @@ declare module '@podman-desktop/api' {
Privileged?: boolean;
PublishAllPorts?: boolean;
ReadonlyRootfs?: boolean;
SecurityOpt?: unknown;
SecurityOpt?: string[];
StorageOpt?: { [option: string]: string };
Tmpfs?: { [dir: string]: string };
UTSMode?: string;
Expand Down Expand Up @@ -1686,9 +1729,50 @@ declare module '@podman-desktop/api' {
errorDetails?: { message?: string };
}

export interface ContainerCreateOptions {
name?: string;
Hostname?: string;
User?: string;
Env?: string[];

// environment files to use
EnvFiles?: string[];

// eslint-disable-next-line @typescript-eslint/ban-types
ExposedPorts?: { [port: string]: {} };
HostConfig?: HostConfig;
Image?: string;
Tty?: boolean;
Cmd?: string[];
Entrypoint?: string | string[];
AttachStdin?: boolean;
AttachStdout?: boolean;
AttachStderr?: boolean;
OpenStdin?: boolean;
StdinOnce?: boolean;
Detach?: boolean;
}

export interface ContainerCreateResult {
id: string;
}

export interface NetworkCreateOptions {
Name: string;
}

export interface NetworkCreateResult {
Id: string;
}

export namespace containerEngine {
export function listContainers(): Promise<ContainerInfo[]>;
export function inspectContainer(engineId: string, id: string): Promise<ContainerInspectInfo>;

export function createContainer(
engineId: string,
containerCreateOptions: ContainerCreateOptions,
): Promise<ContainerCreateResult>;
export function startContainer(engineId: string, id: string): Promise<void>;
export function logsContainer(
engineId: string,
Expand All @@ -1698,6 +1782,7 @@ declare module '@podman-desktop/api' {
export function stopContainer(engineId: string, id: string): Promise<void>;
export function deleteContainer(engineId: string, id: string): Promise<void>;
export function saveImage(engineId: string, id: string, filename: string): Promise<void>;
export function listImages(): Promise<ImageInfo[]>;
export function tagImage(engineId: string, imageId: string, repo: string, tag?: string): Promise<void>;
export function pushImage(
engineId: string,
Expand All @@ -1713,6 +1798,12 @@ declare module '@podman-desktop/api' {
): Promise<void>;
export function deleteImage(engineId: string, id: string): Promise<void>;
export const onEvent: Event<ContainerJSONEvent>;

export function listNetworks(): Promise<NetworkInspectInfo[]>;
export function createNetwork(
containerProviderConnection: ContainerProviderConnection,
networkCreateOptions: NetworkCreateOptions,
): Promise<NetworkCreateResult>;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions packages/main/src/plugin/extension-loader.ts
Expand Up @@ -842,6 +842,12 @@ export class ExtensionLoader {
listContainers(): Promise<containerDesktopAPI.ContainerInfo[]> {
return containerProviderRegistry.listSimpleContainers();
},
createContainer(
engineId: string,
containerCreateOptions: containerDesktopAPI.ContainerCreateOptions,
): Promise<containerDesktopAPI.ContainerCreateResult> {
return containerProviderRegistry.createAndStartContainer(engineId, containerCreateOptions);
},
inspectContainer(engineId: string, id: string): Promise<containerDesktopAPI.ContainerInspectInfo> {
return containerProviderRegistry.getContainerInspect(engineId, id);
},
Expand All @@ -857,6 +863,9 @@ export class ExtensionLoader {
deleteContainer(engineId: string, id: string) {
return containerProviderRegistry.deleteContainer(engineId, id);
},
listImages(): Promise<containerDesktopAPI.ImageInfo[]> {
return containerProviderRegistry.listImages();
},
saveImage(engineId: string, id: string, filename: string) {
return containerProviderRegistry.saveImage(engineId, id, filename);
},
Expand Down Expand Up @@ -884,6 +893,15 @@ export class ExtensionLoader {
onEvent: (listener, thisArg, disposables) => {
return containerProviderRegistry.onEvent(listener, thisArg, disposables);
},
listNetworks(): Promise<containerDesktopAPI.NetworkInspectInfo[]> {
return containerProviderRegistry.listNetworks();
},
createNetwork(
providerContainerConnection: containerDesktopAPI.ContainerProviderConnection,
networkCreateOptions: containerDesktopAPI.NetworkCreateOptions,
): Promise<containerDesktopAPI.NetworkCreateResult> {
return containerProviderRegistry.createNetwork(providerContainerConnection, networkCreateOptions);
},
};

const authenticationProviderRegistry = this.authenticationProviderRegistry;
Expand Down