Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 4

[makefile]
indent_style = tab
25 changes: 23 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #v4.0.3
with:
cache: npm
node-version-file: .node-version

- name: Install
run: |
npm install
- name: Check
- name: Format Check
run: |
npm run check
npm run format.check
- name: Type Check
run: |
npm run typecheck
- name: Test
run: |
npm test

# - name: Integration Test - ESM Import - Install
# run: |
# npm install --install-links --prefix ./test-integration/esm-project
# - name: Integration Test - ESM Import - Test
# run: |
# npm run test --prefix ./test-integration/esm-project
# - name: Integration Test - CJS Import
# working-directory: ./test-integration/esm-project
# run: |
# npm install --install-links
# npm run test
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v22.19.0
22.19.0
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@

Node-SDK is a TypeScript library to access [Docker engine API](https://docs.docker.com/reference/api/engine/#view-the-api-reference) (a.k.a "Moby").

## Installation

```bash
npm install @docker/node-sdk
```

## Usage

```typescript
import { DockerClient } from '@docker/node-sdk';

const docker = await DockerClient.fromDockerConfig();

const containers = await docker.containerList({ all: true });
Expand Down
202 changes: 118 additions & 84 deletions lib/docker-client.ts

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions lib/http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as net from 'net';
import * as http from 'http';
import * as stream from 'stream';
import { getErrorMessage } from './util.js';

// Docker stream content type constants
const DOCKER_RAW_STREAM = 'application/vnd.docker.raw-stream';
Expand Down Expand Up @@ -31,10 +31,10 @@ export class ConflictError extends Error {
}

// Function to extract error message from response body
function getErrorMessage(
function getErrorMessageFromResp(
res: http.IncomingMessage,
body: string | undefined,
): string {
): string | undefined {
const contentType = res.headers['content-type']?.toLowerCase();
if (contentType?.includes('application/json') && body) {
const jsonBody = JSON.parse(body);
Expand All @@ -47,8 +47,8 @@ function getErrorMessage(

// Interface to represent an HTTP response
export interface HTTPResponse {
statusMessage: string;
statusCode: number;
statusMessage?: string;
statusCode?: number;
headers: { [key: string]: string };
body?: string;
sock?: stream.Duplex;
Expand Down Expand Up @@ -160,8 +160,9 @@ export class HTTPClient {
const handleResponseEnd = (body?: string) => {
const response = createResponse(res, body);

if (res.statusCode >= 400) {
const errorMessage = getErrorMessage(res, body);
if (res.statusCode && res.statusCode >= 400) {
const errorMessage =
getErrorMessageFromResp(res, body) ?? '';
if (res.statusCode === 404) {
reject(new NotFoundError(errorMessage));
} else if (res.statusCode === 401) {
Expand All @@ -179,7 +180,9 @@ export class HTTPClient {
// Helper function to handle response errors
const handleResponseError = (error: Error) => {
reject(
new Error(`Response stream error: ${error.message}`),
new Error(
`Response stream error: ${getErrorMessage(error)}`,
),
);
};

Expand Down
6 changes: 3 additions & 3 deletions lib/models/BuildInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
Do not edit the class manually.
*/

import { ErrorDetail } from '../models/ErrorDetail.js';
import { ImageID } from '../models/ImageID.js';
import { ProgressDetail } from '../models/ProgressDetail.js';
import { type ErrorDetail } from '../models/ErrorDetail.js';
import { type ImageID } from '../models/ImageID.js';
import { type ProgressDetail } from '../models/ProgressDetail.js';

export interface BuildInfo {
Id?: string;
Expand Down
6 changes: 3 additions & 3 deletions lib/models/ClusterInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
Do not edit the class manually.
*/

import { ObjectVersion } from '../models/ObjectVersion.js';
import { SwarmSpec } from '../models/SwarmSpec.js';
import { TLSInfo } from '../models/TLSInfo.js';
import { type ObjectVersion } from '../models/ObjectVersion.js';
import { type SwarmSpec } from '../models/SwarmSpec.js';
import { type TLSInfo } from '../models/TLSInfo.js';

/**
* ClusterInfo represents information about the swarm as is returned by the \"/info\" endpoint. Join-tokens are not included.
Expand Down
8 changes: 4 additions & 4 deletions lib/models/ClusterVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
Do not edit the class manually.
*/

import { ClusterVolumeInfo } from '../models/ClusterVolumeInfo.js';
import { ClusterVolumePublishStatusInner } from '../models/ClusterVolumePublishStatusInner.js';
import { ClusterVolumeSpec } from '../models/ClusterVolumeSpec.js';
import { ObjectVersion } from '../models/ObjectVersion.js';
import { type ClusterVolumeInfo } from '../models/ClusterVolumeInfo.js';
import { type ClusterVolumePublishStatusInner } from '../models/ClusterVolumePublishStatusInner.js';
import { type ClusterVolumeSpec } from '../models/ClusterVolumeSpec.js';
import { type ObjectVersion } from '../models/ObjectVersion.js';

/**
* Options and information specific to, and only present on, Swarm CSI cluster volumes.
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ClusterVolumeSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Do not edit the class manually.
*/

import { ClusterVolumeSpecAccessMode } from '../models/ClusterVolumeSpecAccessMode.js';
import { type ClusterVolumeSpecAccessMode } from '../models/ClusterVolumeSpecAccessMode.js';

/**
* Cluster-specific options used to create the volume.
Expand Down
6 changes: 3 additions & 3 deletions lib/models/ClusterVolumeSpecAccessMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
Do not edit the class manually.
*/

import { ClusterVolumeSpecAccessModeAccessibilityRequirements } from '../models/ClusterVolumeSpecAccessModeAccessibilityRequirements.js';
import { ClusterVolumeSpecAccessModeCapacityRange } from '../models/ClusterVolumeSpecAccessModeCapacityRange.js';
import { ClusterVolumeSpecAccessModeSecretsInner } from '../models/ClusterVolumeSpecAccessModeSecretsInner.js';
import { type ClusterVolumeSpecAccessModeAccessibilityRequirements } from '../models/ClusterVolumeSpecAccessModeAccessibilityRequirements.js';
import { type ClusterVolumeSpecAccessModeCapacityRange } from '../models/ClusterVolumeSpecAccessModeCapacityRange.js';
import { type ClusterVolumeSpecAccessModeSecretsInner } from '../models/ClusterVolumeSpecAccessModeSecretsInner.js';

/**
* Defines how the volume is used by tasks.
Expand Down
4 changes: 2 additions & 2 deletions lib/models/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
Do not edit the class manually.
*/

import { ConfigSpec } from '../models/ConfigSpec.js';
import { ObjectVersion } from '../models/ObjectVersion.js';
import { type ConfigSpec } from '../models/ConfigSpec.js';
import { type ObjectVersion } from '../models/ObjectVersion.js';

export interface Config {
ID?: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ConfigCreateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Do not edit the class manually.
*/

import { Driver } from '../models/Driver.js';
import { type Driver } from '../models/Driver.js';

export interface ConfigCreateRequest {
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ConfigSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Do not edit the class manually.
*/

import { Driver } from '../models/Driver.js';
import { type Driver } from '../models/Driver.js';

export interface ConfigSpec {
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ContainerBlkioStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Do not edit the class manually.
*/

import { ContainerBlkioStatEntry } from '../models/ContainerBlkioStatEntry.js';
import { type ContainerBlkioStatEntry } from '../models/ContainerBlkioStatEntry.js';

/**
* BlkioStats stores all IO service stats for data read and write. This type is Linux-specific and holds many fields that are specific to cgroups v1. On a cgroup v2 host, all fields other than `io_service_bytes_recursive` are omitted or `null`. This type is only populated on Linux and omitted for Windows containers.
Expand Down
4 changes: 2 additions & 2 deletions lib/models/ContainerCPUStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
Do not edit the class manually.
*/

import { ContainerCPUUsage } from '../models/ContainerCPUUsage.js';
import { ContainerThrottlingData } from '../models/ContainerThrottlingData.js';
import { type ContainerCPUUsage } from '../models/ContainerCPUUsage.js';
import { type ContainerThrottlingData } from '../models/ContainerThrottlingData.js';

/**
* CPU related info of the container
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ContainerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Do not edit the class manually.
*/

import { HealthConfig } from '../models/HealthConfig.js';
import { type HealthConfig } from '../models/HealthConfig.js';

/**
* Configuration for a container that is portable between hosts.
Expand Down
6 changes: 3 additions & 3 deletions lib/models/ContainerCreateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
Do not edit the class manually.
*/

import { HealthConfig } from '../models/HealthConfig.js';
import { HostConfig } from '../models/HostConfig.js';
import { NetworkingConfig } from '../models/NetworkingConfig.js';
import { type HealthConfig } from '../models/HealthConfig.js';
import { type HostConfig } from '../models/HostConfig.js';
import { type NetworkingConfig } from '../models/NetworkingConfig.js';

export interface ContainerCreateRequest {
/**
Expand Down
14 changes: 7 additions & 7 deletions lib/models/ContainerInspectResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
Do not edit the class manually.
*/

import { ContainerConfig } from '../models/ContainerConfig.js';
import { ContainerState } from '../models/ContainerState.js';
import { DriverData } from '../models/DriverData.js';
import { HostConfig } from '../models/HostConfig.js';
import { MountPoint } from '../models/MountPoint.js';
import { NetworkSettings } from '../models/NetworkSettings.js';
import { OCIDescriptor } from '../models/OCIDescriptor.js';
import { type ContainerConfig } from '../models/ContainerConfig.js';
import { type ContainerState } from '../models/ContainerState.js';
import { type DriverData } from '../models/DriverData.js';
import { type HostConfig } from '../models/HostConfig.js';
import { type MountPoint } from '../models/MountPoint.js';
import { type NetworkSettings } from '../models/NetworkSettings.js';
import { type OCIDescriptor } from '../models/OCIDescriptor.js';

export interface ContainerInspectResponse {
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ContainerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Do not edit the class manually.
*/

import { Health } from '../models/Health.js';
import { type Health } from '../models/Health.js';

/**
* ContainerState stores container\'s running state. It\'s part of ContainerJSONBase and will be returned by the \"inspect\" command.
Expand Down
10 changes: 5 additions & 5 deletions lib/models/ContainerStatsResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
Do not edit the class manually.
*/

import { ContainerBlkioStats } from '../models/ContainerBlkioStats.js';
import { ContainerCPUStats } from '../models/ContainerCPUStats.js';
import { ContainerMemoryStats } from '../models/ContainerMemoryStats.js';
import { ContainerPidsStats } from '../models/ContainerPidsStats.js';
import { ContainerStorageStats } from '../models/ContainerStorageStats.js';
import { type ContainerBlkioStats } from '../models/ContainerBlkioStats.js';
import { type ContainerCPUStats } from '../models/ContainerCPUStats.js';
import { type ContainerMemoryStats } from '../models/ContainerMemoryStats.js';
import { type ContainerPidsStats } from '../models/ContainerPidsStats.js';
import { type ContainerStorageStats } from '../models/ContainerStorageStats.js';

/**
* Statistics sample for a container.
Expand Down
12 changes: 6 additions & 6 deletions lib/models/ContainerSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
Do not edit the class manually.
*/

import { ContainerSummaryHealth } from '../models/ContainerSummaryHealth.js';
import { ContainerSummaryHostConfig } from '../models/ContainerSummaryHostConfig.js';
import { ContainerSummaryNetworkSettings } from '../models/ContainerSummaryNetworkSettings.js';
import { MountPoint } from '../models/MountPoint.js';
import { OCIDescriptor } from '../models/OCIDescriptor.js';
import { PortSummary } from '../models/PortSummary.js';
import { type ContainerSummaryHealth } from '../models/ContainerSummaryHealth.js';
import { type ContainerSummaryHostConfig } from '../models/ContainerSummaryHostConfig.js';
import { type ContainerSummaryNetworkSettings } from '../models/ContainerSummaryNetworkSettings.js';
import { type MountPoint } from '../models/MountPoint.js';
import { type OCIDescriptor } from '../models/OCIDescriptor.js';
import { type PortSummary } from '../models/PortSummary.js';

export interface ContainerSummary {
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ContainerSummaryNetworkSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Do not edit the class manually.
*/

import { EndpointSettings } from '../models/EndpointSettings.js';
import { type EndpointSettings } from '../models/EndpointSettings.js';

/**
* Summary of the container\'s network settings
Expand Down
12 changes: 6 additions & 6 deletions lib/models/ContainerUpdateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
Do not edit the class manually.
*/

import { DeviceMapping } from '../models/DeviceMapping.js';
import { DeviceRequest } from '../models/DeviceRequest.js';
import { ResourcesBlkioWeightDeviceInner } from '../models/ResourcesBlkioWeightDeviceInner.js';
import { ResourcesUlimitsInner } from '../models/ResourcesUlimitsInner.js';
import { RestartPolicy } from '../models/RestartPolicy.js';
import { ThrottleDevice } from '../models/ThrottleDevice.js';
import { type DeviceMapping } from '../models/DeviceMapping.js';
import { type DeviceRequest } from '../models/DeviceRequest.js';
import { type ResourcesBlkioWeightDeviceInner } from '../models/ResourcesBlkioWeightDeviceInner.js';
import { type ResourcesUlimitsInner } from '../models/ResourcesUlimitsInner.js';
import { type RestartPolicy } from '../models/RestartPolicy.js';
import { type ThrottleDevice } from '../models/ThrottleDevice.js';

export interface ContainerUpdateRequest {
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ContainerWaitResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Do not edit the class manually.
*/

import { ContainerWaitExitError } from '../models/ContainerWaitExitError.js';
import { type ContainerWaitExitError } from '../models/ContainerWaitExitError.js';

/**
* OK response to ContainerWait operation
Expand Down
2 changes: 1 addition & 1 deletion lib/models/ContainerdInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Do not edit the class manually.
*/

import { ContainerdInfoNamespaces } from '../models/ContainerdInfoNamespaces.js';
import { type ContainerdInfoNamespaces } from '../models/ContainerdInfoNamespaces.js';

/**
* Information for connecting to the containerd instance that is used by the daemon. This is included for debugging purposes only.
Expand Down
4 changes: 2 additions & 2 deletions lib/models/CreateImageInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
Do not edit the class manually.
*/

import { ErrorDetail } from '../models/ErrorDetail.js';
import { ProgressDetail } from '../models/ProgressDetail.js';
import { type ErrorDetail } from '../models/ErrorDetail.js';
import { type ProgressDetail } from '../models/ProgressDetail.js';

export interface CreateImageInfo {
Id?: string;
Expand Down
4 changes: 2 additions & 2 deletions lib/models/DistributionInspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
Do not edit the class manually.
*/

import { OCIDescriptor } from '../models/OCIDescriptor.js';
import { OCIPlatform } from '../models/OCIPlatform.js';
import { type OCIDescriptor } from '../models/OCIDescriptor.js';
import { type OCIPlatform } from '../models/OCIPlatform.js';

/**
* Describes the result obtained from contacting the registry to retrieve image metadata.
Expand Down
Loading