/** * Copyright 2023 Kapeta Inc. * SPDX-License-Identifier: BUSL-1.1 */ /// import FSExtra from 'fs-extra'; import Docker from 'dockerode'; import { InstanceInfo, LogEntry } from './types'; import { Task } from './taskManager'; import { LocalInstanceHealth } from '@kapeta/schemas'; type StringMap = { [key: string]: string; }; export type PortMap = { [key: string]: { containerPort: string; protocol: string; hostPort: string; }; }; export interface DockerMounts { Target: string; Source: string; Type: string; ReadOnly: boolean; Consistency: string; Labels?: StringMap; } export type DockerContainerStatus = 'created' | 'running' | 'paused' | 'restarting' | 'removing' | 'exited' | 'dead'; export type DockerContainerHealth = 'starting' | 'healthy' | 'unhealthy' | 'none'; export declare const CONTAINER_LABEL_PORT_PREFIX = "kapeta_port-"; export declare const COMPOSE_LABEL_PROJECT = "com.docker.compose.project"; export declare const COMPOSE_LABEL_SERVICE = "com.docker.compose.service"; export declare const HEALTH_CHECK_TIMEOUT: number; declare class ContainerManager { private _docker; private _alive; private _mountDir; private _version; private _lastDockerAccessCheck; private logStreams; private _latestImagePulls; constructor(); initialize(): Promise; checkAlive(): Promise; isAlive(): boolean; getMountPoint(systemId: string, ref: string, mountName: string): string; createMounts(systemId: string, kind: string, mountOpts: StringMap | null | undefined): Promise; createVolumes(systemId: string, serviceId: string, mountOpts: StringMap | null | undefined): Promise; ping(): Promise; docker(): Docker; getContainerByName(containerName: string): Promise; pull(image: string): Promise; toDockerMounts(mounts: StringMap): DockerMounts[]; toDockerHealth(health: LocalInstanceHealth): { Test: string[]; Interval: number; Timeout: number; Retries: any; }; private applyHash; ensureContainer(opts: any): Promise; private createOrUpdateContainer; private startContainer; waitForReady(container: Docker.Container, attempt?: number): Promise; _isReady(container: Docker.Container): Promise; remove(container: Docker.Container, opts?: { force?: boolean; }): Promise; /** * * @param name * @return {Promise} */ get(name: string): Promise; getLogs(instance: InstanceInfo): Promise; stopLogListening(systemId: string, instanceId: string): Promise; ensureLogListening(systemId: string, instanceId: string, handler: (log: LogEntry) => void): Promise; buildDockerImage(dockerFile: string, imageName: string): Task; } declare class ClosableLogStream { private readonly stream; private readonly eventEmitter; constructor(stream: FSExtra.ReadStream); onLog(listener: (log: LogEntry) => void): () => void; onEnd(listener: () => void): () => void; onError(listener: (error: Error) => void): () => void; close(): Promise; } export declare class ContainerInfo { private readonly _container; /** * * @param {Docker.Container} dockerContainer */ constructor(dockerContainer: Docker.Container); get native(): Docker.Container; isRunning(): Promise; start(): Promise; restart(): Promise; stop(): Promise; remove(opts?: { force?: boolean; }): Promise; getPort(type: string): Promise<{ containerPort: string; protocol: string; hostPort: string; } | null>; inspect(): Promise; status(): Promise<{ Status: string; Running: boolean; Paused: boolean; Restarting: boolean; OOMKilled: boolean; Dead: boolean; Pid: number; ExitCode: number; Error: string; StartedAt: string; FinishedAt: string; Health?: { Status: string; FailingStreak: number; Log: { Start: string; End: string; ExitCode: number; Output: string; }[]; } | undefined; } | undefined>; getPorts(): Promise; getLogStream(): Promise; getLogs(): Promise; } export declare function getExtraHosts(dockerVersion: string): string[] | undefined; /** * Ensure that the volume is in the correct format for the docker daemon on the host * * Windows: c:\path\to\volume -> /c/path/to/volume * Linux: /path/to/volume -> /path/to/volume * Mac: /path/to/volume -> /path/to/volume */ export declare function toLocalBindVolume(volume: string): string; export declare const containerManager: ContainerManager; export {};