import type * as plugins from '../plugins.js'; import type { DockerConfig } from '../classes.config.js'; import type { DockerImage } from '../classes.image.js'; import type { DockerNetwork } from '../classes.network.js'; import type { DockerSecret } from '../classes.secret.js'; import type { TLabels } from './label.js'; import type { IDockerResourceFileTarget } from './resource.js'; export interface IDockerServiceSecretReference { secret: string | DockerSecret; file: IDockerResourceFileTarget; } export interface IDockerServiceConfigReference { config: string | DockerConfig; file: IDockerResourceFileTarget; } export interface IDockerServiceBindMount extends plugins.tsclass.container.IVolumeMount { readOnly?: boolean; } export type TDockerServiceMode = | { type: 'replicated'; replicas: number } | { type: 'global-job' }; export type TDockerServiceArgs = [string, ...string[]]; export interface IDockerServiceRestartPolicy { /** Prevents Swarm from replacing a failed task. */ condition: 'none'; } export interface IDockerServicePlacement { /** Docker evaluates multiple placement constraints as an AND expression. */ constraints: string[]; } export interface IDockerServiceSpecMode { Replicated?: { Replicas?: number }; Global?: Record; ReplicatedJob?: { MaxConcurrent?: number; TotalCompletions?: number }; GlobalJob?: Record; } /** * Service creation descriptor supporting both string references and class instances. * Strings will be resolved to resources internally. */ export interface IServiceCreationDescriptor { name: string; /** Image tag (string) or DockerImage instance */ image: string | DockerImage; /** * Complete repository@sha256 reference to serialize instead of the image tag. * Requires a DockerImage returned by pullImage() with matching verification evidence. */ immutableImageReference?: string; /** * Complete explicitly tagged reference to serialize instead of RepoTags[0]. * Requires a DockerImage returned by pullMutableImage() for this exact reference. */ mutableImageReference?: string; labels: TLabels; /** Network names (strings) or DockerNetwork instances */ networks: (string | DockerNetwork)[]; networkAlias: string; /** Secret names, DockerSecret instances, or target-aware references */ secrets: (string | DockerSecret | IDockerServiceSecretReference)[]; /** Config names, DockerConfig instances, or target-aware references */ configs?: (string | DockerConfig | IDockerServiceConfigReference)[]; ports: string[]; /** Arguments passed to the image entrypoint without a shell. */ args?: TDockerServiceArgs; /** Explicit Swarm scheduling mode. Omitted descriptors retain Docker's default. */ mode?: TDockerServiceMode; placement?: IDockerServicePlacement; restartPolicy?: IDockerServiceRestartPolicy; accessHostDockerSock?: boolean; resources?: { memorySizeMB?: number; volumeMounts?: IDockerServiceBindMount[]; }; /** * Container health check override for the service spec. Takes precedence * over the image's HEALTHCHECK; pass `{ test: ['NONE'] }` to disable the * image's check entirely. Durations are in milliseconds. */ healthcheck?: { /** Docker HealthConfig test, e.g. ['NONE'] or ['CMD-SHELL', 'curl ...'] */ test: string[]; intervalMs?: number; timeoutMs?: number; startPeriodMs?: number; retries?: number; }; } export interface IDockerServiceTask { ID?: string; ServiceID?: string; NodeID?: string; Slot?: number; JobIteration?: { Index?: number; }; DesiredState?: string; Spec?: { ContainerSpec?: { Image?: string; Command?: string[]; Args?: string[]; Mounts?: Array<{ Target?: string; Source?: string; Type?: string; ReadOnly?: boolean; Consistency?: string; BindOptions?: Record; }>; }; RestartPolicy?: { Condition?: string; Delay?: number; MaxAttempts?: number; Window?: number; }; Placement?: { Constraints?: string[]; Platforms?: Array<{ Architecture?: string; OS?: string; }>; }; }; Status?: { State?: string; ContainerStatus?: { ContainerID?: string; Image?: string; ImageID?: string; ExitCode?: number; }; }; } export interface IDockerGlobalJobCompletionProofOptions { /** Version.Index returned by the exact created service inspection. */ expectedServiceVersionIndex: number; /** JobStatus.JobIteration.Index for the execution being proven. */ expectedJobIterationIndex: number; expectedImageReference: string; expectedArgs: TDockerServiceArgs; /** Complete writable bind-mount set expected on the installer task. */ expectedWritableBindMounts: plugins.tsclass.container.IVolumeMount[]; /** Complete ordered placement-constraint set from the authoritative generation. */ expectedPlacementConstraints: string[]; /** Authority labels which must be present on the fresh service specification. */ requiredServiceLabels: TLabels; /** Complete authoritative node-ID set for the generation-labelled targets. */ expectedTargetNodeIds: string[]; } export interface IDockerGlobalJobTaskCompletionEvidence { taskId: string; nodeId: string; jobIterationIndex: number; desiredState: 'complete'; state: 'complete'; exitCode: 0; } export interface IDockerGlobalJobCompletionProof { serviceId: string; serviceVersionIndex: number; jobIterationIndex: number; imageReference: string; args: TDockerServiceArgs; writableBindMounts: plugins.tsclass.container.IVolumeMount[]; placementConstraints: string[]; targetNodeIds: string[]; tasks: IDockerGlobalJobTaskCompletionEvidence[]; } export interface IDockerServiceStopProofOptions { /** Maximum time to wait for every task to reach a terminal state. Defaults to 30000. */ timeoutMs?: number; /** Delay between exact service/task observations. Defaults to 250. */ pollIntervalMs?: number; /** Fresh Version.Index required before a stop update or already-zero proof; ignored if absent. */ expectedVersionIndex?: number; /** Fresh service-level Spec.Labels subset required before update/zero proof; ignored if absent. */ requiredLabels?: TLabels; } export interface IDockerServiceStoppedImagePinOptions { /** Exact image reference currently present in the fresh service specification. */ expectedImageReference: string; /** Complete immutable repository digest to install in the stopped service specification. */ imageReference: string; }