From 1d69ae66948c781aa5cabd1e4aad0360dde16161 Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Tue, 11 Dec 2018 17:50:07 +0100 Subject: [PATCH 1/7] dockerode definition update --- types/dockerode/index.d.ts | 261 +++++++++++++++++++++++++++---------- 1 file changed, 194 insertions(+), 67 deletions(-) diff --git a/types/dockerode/index.d.ts b/types/dockerode/index.d.ts index 5c1c1bfae6..e467441634 100644 --- a/types/dockerode/index.d.ts +++ b/types/dockerode/index.d.ts @@ -6,6 +6,8 @@ // Ray Fang // Marius Meisenzahl // Rob Moran +// Cameron Diver +// Pascal Sthamer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -14,8 +16,16 @@ import * as stream from 'stream'; import * as events from 'events'; +// The modem parameter is an instance of docker-modem, which is missing type declarations. +// https://github.com/apocas/docker-modem + declare namespace Dockerode { - interface Container { + class Container { + constructor(modem: any, id: string); + + modem: any; + id: string; + inspect(options: {}, callback: Callback): void; inspect(callback: Callback): void; inspect(options?: {}): Promise; @@ -103,14 +113,16 @@ declare namespace Dockerode { stats(callback: Callback): void; stats(options?: {}): Promise; - attach(options: {}, callback: Callback): void; - attach(options: {}): Promise; - - modem: any; - id?: string; + attach(options: {}, callback: Callback): void; + attach(options: {}): Promise; } - interface Image { + class Image { + constructor(modem: any, name: string); + + modem: any; + id: string; + inspect(callback: Callback): void; inspect(): Promise; @@ -131,24 +143,28 @@ declare namespace Dockerode { remove(options: {}, callback: Callback): void; remove(callback: Callback): void; remove(options?: {}): Promise; - - modem: any; - id?: string; } - interface Volume { + class Volume { + constructor(modem: any, name: string); + + modem: any; + name: string; + inspect(callback: Callback): void; inspect(): Promise; remove(options: {}, callback: Callback): void; remove(callback: Callback): void; remove(options?: {}): Promise; - - modem: any; - name?: string; } - interface Service { + class Service { + constructor(modem: any, id: string); + + modem: any; + id: string; + inspect(callback: Callback): void; inspect(): Promise; @@ -158,20 +174,24 @@ declare namespace Dockerode { update(options: {}, callback: Callback): void; update(options: {}): Promise; - - modem: any; - id?: string; } - interface Task { + class Task { + constructor(modem: any, id: string); + + modem: any; + id: string; + inspect(callback: Callback): void; inspect(): Promise; - - modem: any; - id?: string; } - interface Node { + class Node { + constructor(modem: any, id: string); + + modem: any; + id: string; + inspect(callback: Callback): void; inspect(): Promise; @@ -182,12 +202,11 @@ declare namespace Dockerode { remove(options: {}, callback: Callback): void; remove(callback: Callback): void; remove(options?: {}): Promise; - - modem: any; - id?: string; } - interface Plugin { + class Plugin { + constructor(modem: any, name: string, remote?: any); + modem: any; name: string; remote: any; @@ -226,7 +245,12 @@ declare namespace Dockerode { upgrade(auth: any, options?: {}): Promise; } - interface Secret { + class Secret { + constructor(modem: any, id: string); + + modem: any; + id: string; + inspect(callback: Callback): void; inspect(): Promise; @@ -237,12 +261,14 @@ declare namespace Dockerode { remove(options: {}, callback: Callback): void; remove(callback: Callback): void; remove(options?: {}): Promise; - - modem: any; - id?: string; } - interface Network { + class Network { + constructor(modem: any, id: string); + + modem: any; + id: string; + inspect(callback: Callback): void; inspect(): Promise; @@ -257,12 +283,14 @@ declare namespace Dockerode { disconnect(options: {}, callback: Callback): void; disconnect(callback: Callback): void; disconnect(options?: {}): Promise; - - modem: any; - id?: string; } - interface Exec { + class Exec { + constructor(modem: any, id: string); + + modem: any; + id: string; + inspect(callback: Callback): void; inspect(): Promise; @@ -271,9 +299,6 @@ declare namespace Dockerode { resize(options: {}, callback: Callback): void; resize(options: {}): Promise; - - modem: any; - id?: string; } interface ImageInfo { @@ -328,6 +353,20 @@ declare namespace Dockerode { MacAddress: string; } + // not complete definition of network inspection + // info which is returned by list / inspect + interface NetworkInspectInfo { + Id: string; + Name: string; + Driver: string; + Created: string; + Scope: string; + EnableIPv6: boolean; + Internal: boolean; + Attachable: boolean; + Ingress: boolean; + } + interface ContainerInspectInfo { Id: string; Created: string; @@ -434,13 +473,13 @@ declare namespace Dockerode { } }; Node?: { - ID: string; - IP: string; - Addr: string; - Name: string; - Cpus: number; - Memory: number; - Labels: any; + ID: string; + IP: string; + Addr: string; + Name: string; + Cpus: number; + Memory: number; + Labels: any; } }; } @@ -573,6 +612,77 @@ declare namespace Dockerode { }; } + interface AuthConfig { + username: string; + password: string; + serveraddress: string; + email?: string; + } + + interface PortBinding { + HostIp?: string; + HostPort?: string; + } + + interface PortMap { + [key: string]: PortBinding[]; + } + + interface RestartPolicy { + Name: string; + MaximumRetryCount?: number; + } + + type LoggingDriverType = + | "json-file" + | "syslog" + | "journald" + | "gelf" + | "fluentd" + | "awslogs" + | "splunk" + | "etwlogs" + | "none"; + + interface LogConfig { + Type: LoggingDriverType; + Config?: { [key: string]: string }; + } + + interface DeviceMapping { + PathOnHost: string; + PathInContainer: string; + CgroupPermissions: string; + } + + /* tslint:disable:interface-name */ + interface IPAMConfig { + IPv4Address?: string; + IPv6Address?: string; + LinkLocalIPs?: string[]; + } + /* tslint:enable:interface-name */ + + interface EndpointSettings { + IPAMConfig?: IPAMConfig; + Links?: string[]; + Aliases?: string[]; + NetworkID?: string; + EndpointID?: string; + Gateway?: string; + IPAddress?: string; + IPPrefixLen?: number; + IPv6Gateway?: string; + GlobalIPv6Address?: string; + GlobalIPV6PrefixLen?: number; + MacAddress?: string; + DriverOpts?: { [key: string]: string }; + } + + interface EndpointsConfig { + [key: string]: EndpointSettings; + } + interface ContainerCreateOptions { name?: string; Hostname?: string; @@ -620,7 +730,7 @@ declare namespace Dockerode { OomScoreAdj?: number; PidMode?: string; PidsLimit?: number; - PortBindings?: { [portAndProtocol: string]: Array<{ [index: string]: string }> }; + PortBindings?: PortMap; PublishAllPorts?: boolean; Privileged?: boolean; ReadonlyRootfs?: boolean; @@ -632,31 +742,19 @@ declare namespace Dockerode { CapAdd?: string[]; CapDrop?: string[]; GroupAdd?: string[]; - RestartPolicy?: { [index: string]: number | string }; + RestartPolicy?: RestartPolicy; NetworkMode?: string; - Devices?: any[]; + Devices?: DeviceMapping[]; Sysctls?: { [index: string]: string }; Ulimits?: Array<{}>; - LogConfig?: { [index: string]: string | {} }; + LogConfig?: LogConfig; SecurityOpt?: { [index: string]: any }; CgroupParent?: string; VolumeDriver?: string; ShmSize?: number; }; NetworkingConfig?: { - EndpointsConfig?: { - [index: string]: any; - isolated_nw?: { - [index: string]: any; - IPAMConfig?: { - IPv4Address?: string; - IPv6Adress?: string; - LinkLocalIPs?: string[]; - } - Links?: string[]; - Aliases?: string[]; - } - } + EndpointsConfig?: EndpointsConfig; }; } @@ -820,8 +918,37 @@ declare namespace Dockerode { } interface ImageBuildContext { - context: string; - src: string[]; + context: string; + src: string[]; + } + + interface DockerVersion { + ApiVersion: string; + Arch: string; + BuildTime: Date; + Components: Array<{ + Details: { + ApiVersion: string; + Arch: string; + BuilTime: Date; + Experimental: string; + GitCommit: string; + GoVersion: string; + KernelVersion: string; + Os: string; + }; + Name: string; + Version: string; + }>; + GitCommit: string; + GoVersion: string; + KernelVersion: string; + MinAPIVersion: string; + Os: string; + Platform: { + Name: string; + }; + Version: string; } } @@ -949,8 +1076,8 @@ declare class Dockerode { df(callback: Callback): void; df(): Promise; - version(callback: Callback): void; - version(): Promise; + version(callback: Callback): void; + version(): Promise; ping(callback: Callback): void; ping(): Promise; From e1b2162dce95f3e655cf918b7a9befaebe8fcb78 Mon Sep 17 00:00:00 2001 From: CameronDiver Date: Tue, 11 Dec 2018 18:53:50 +0100 Subject: [PATCH 2/7] Fix typo Co-Authored-By: P4sca1 --- types/dockerode/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/dockerode/index.d.ts b/types/dockerode/index.d.ts index 64656edbb8..3ced325cb2 100644 --- a/types/dockerode/index.d.ts +++ b/types/dockerode/index.d.ts @@ -930,7 +930,7 @@ declare namespace Dockerode { Details: { ApiVersion: string; Arch: string; - BuilTime: Date; + BuildTime: Date; Experimental: string; GitCommit: string; GoVersion: string; From 01401844ac7c7824ced00aeb73ea4372d20f4542 Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Tue, 11 Dec 2018 18:57:07 +0100 Subject: [PATCH 3/7] Remove duplicate DockerVersion interface --- types/dockerode/index.d.ts | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/types/dockerode/index.d.ts b/types/dockerode/index.d.ts index 3ced325cb2..d823c46fe4 100644 --- a/types/dockerode/index.d.ts +++ b/types/dockerode/index.d.ts @@ -950,35 +950,6 @@ declare namespace Dockerode { }; Version: string; } - - interface DockerVersion { - ApiVersion: string; - Arch: string; - BuildTime: Date; - Components: Array<{ - Details: { - ApiVersion: string; - Arch: string; - BuilTime: Date; - Experimental: string; - GitCommit: string; - GoVersion: string; - KernelVersion: string; - Os: string; - }; - Name: string; - Version: string; - }>; - GitCommit: string; - GoVersion: string; - KernelVersion: string; - MinAPIVersion: string; - Os: string; - Platform: { - Name: string; - }; - Version: string; - } } type Callback = (error?: any, result?: T) => void; From c73305cc54f9ad601b68cd9289f127671de01cd8 Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Wed, 12 Dec 2018 12:42:20 +0100 Subject: [PATCH 4/7] Include container.stats types --- types/dockerode/index.d.ts | 83 +++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/types/dockerode/index.d.ts b/types/dockerode/index.d.ts index d823c46fe4..6a988ba5c2 100644 --- a/types/dockerode/index.d.ts +++ b/types/dockerode/index.d.ts @@ -470,7 +470,7 @@ declare namespace Dockerode { GlobalIPv6Address: string; GlobalIPv6PrefixLen: number; MacAddress: string; - } + }; }; Node?: { ID: string; @@ -480,10 +480,89 @@ declare namespace Dockerode { Cpus: number; Memory: number; Labels: any; - } + }; }; } + + interface NetworkStats { + [name: string]: { + rx_bytes: number; + rx_dropped: number; + rx_errors: number; + rx_packets: number; + tx_bytes: number; + tx_dropped: number; + tx_errors: number; + tx_packets: number; + }; + } + interface CPUStats { + cpu_usage: { + percpu_usage: Array; + usage_in_usermode: number; + total_usage: number; + usage_in_kernelmode: number; + }; + system_cpu_usage: number; + online_cpus: number; + throttling_data: { + periods: number; + throttled_periods: number; + throttled_time: number; + }; + } + + interface MemoryStats { + stats: { + total_pgmajfault: number; + cache: number; + mapped_file: number; + total_inactive_file: number; + pgpgout: number; + rss: number; + total_mapped_file: number; + writeback: number; + unevictable: number; + pgpgin: number; + total_unevictable: number; + pgmajfault: number; + total_rss: number; + total_rss_huge: number; + total_writeback: number; + total_inactive_anon: number; + rss_huge: number; + hierarchical_memory_limit: number; + total_pgfault: number; + total_active_file: number; + active_anon: number; + total_active_anon: number; + total_pgpgout: number; + total_cache: number; + inactive_anon: number; + active_file: number; + pgfault: number; + inactive_file: number; + total_pgpgin: number; + }; + max_usage: number; + usage: number; + failcnt: number; + limit: number; + } + + interface ContainerStats { + read: string; + pid_stats: { + current: number; + }; + networks: NetworkStats; + memory_stats: MemoryStats; + blkio_stats: {}; + cpu_stats: CPUStats; + precpu_stats: CPUStats; + } + interface HostConfig { AutoRemove: boolean; Binds: string[]; From cea66cd28fc108a0328b8c9b407007c6ac9aa2f8 Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Wed, 12 Dec 2018 12:44:19 +0100 Subject: [PATCH 5/7] Forgot to update return types --- types/dockerode/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/dockerode/index.d.ts b/types/dockerode/index.d.ts index 6a988ba5c2..1dd099f1c3 100644 --- a/types/dockerode/index.d.ts +++ b/types/dockerode/index.d.ts @@ -109,9 +109,9 @@ declare namespace Dockerode { logs(callback: Callback): void; logs(options?: ContainerLogsOptions): Promise; - stats(options: {}, callback: Callback): void; - stats(callback: Callback): void; - stats(options?: {}): Promise; + stats(options: {}, callback: Callback): void; + stats(callback: Callback): void; + stats(options?: {}): Promise; attach(options: {}, callback: Callback): void; attach(options: {}): Promise; From ba36ee16316092fa2e83c2ec70b658c37a19db1e Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Wed, 12 Dec 2018 12:53:43 +0100 Subject: [PATCH 6/7] Fix tslint error --- types/dockerode/index.d.ts | 152 ++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/types/dockerode/index.d.ts b/types/dockerode/index.d.ts index 1dd099f1c3..694cc295b4 100644 --- a/types/dockerode/index.d.ts +++ b/types/dockerode/index.d.ts @@ -483,86 +483,86 @@ declare namespace Dockerode { }; }; } - + interface NetworkStats { - [name: string]: { - rx_bytes: number; - rx_dropped: number; - rx_errors: number; - rx_packets: number; - tx_bytes: number; - tx_dropped: number; - tx_errors: number; - tx_packets: number; - }; - } + [name: string]: { + rx_bytes: number; + rx_dropped: number; + rx_errors: number; + rx_packets: number; + tx_bytes: number; + tx_dropped: number; + tx_errors: number; + tx_packets: number; + }; + } - interface CPUStats { - cpu_usage: { - percpu_usage: Array; - usage_in_usermode: number; - total_usage: number; - usage_in_kernelmode: number; - }; - system_cpu_usage: number; - online_cpus: number; - throttling_data: { - periods: number; - throttled_periods: number; - throttled_time: number; - }; - } + interface CPUStats { + cpu_usage: { + percpu_usage: number[]; + usage_in_usermode: number; + total_usage: number; + usage_in_kernelmode: number; + }; + system_cpu_usage: number; + online_cpus: number; + throttling_data: { + periods: number; + throttled_periods: number; + throttled_time: number; + }; + } - interface MemoryStats { - stats: { - total_pgmajfault: number; - cache: number; - mapped_file: number; - total_inactive_file: number; - pgpgout: number; - rss: number; - total_mapped_file: number; - writeback: number; - unevictable: number; - pgpgin: number; - total_unevictable: number; - pgmajfault: number; - total_rss: number; - total_rss_huge: number; - total_writeback: number; - total_inactive_anon: number; - rss_huge: number; - hierarchical_memory_limit: number; - total_pgfault: number; - total_active_file: number; - active_anon: number; - total_active_anon: number; - total_pgpgout: number; - total_cache: number; - inactive_anon: number; - active_file: number; - pgfault: number; - inactive_file: number; - total_pgpgin: number; - }; - max_usage: number; - usage: number; - failcnt: number; - limit: number; - } + interface MemoryStats { + stats: { + total_pgmajfault: number; + cache: number; + mapped_file: number; + total_inactive_file: number; + pgpgout: number; + rss: number; + total_mapped_file: number; + writeback: number; + unevictable: number; + pgpgin: number; + total_unevictable: number; + pgmajfault: number; + total_rss: number; + total_rss_huge: number; + total_writeback: number; + total_inactive_anon: number; + rss_huge: number; + hierarchical_memory_limit: number; + total_pgfault: number; + total_active_file: number; + active_anon: number; + total_active_anon: number; + total_pgpgout: number; + total_cache: number; + inactive_anon: number; + active_file: number; + pgfault: number; + inactive_file: number; + total_pgpgin: number; + }; + max_usage: number; + usage: number; + failcnt: number; + limit: number; + } + + interface ContainerStats { + read: string; + pid_stats: { + current: number; + }; + networks: NetworkStats; + memory_stats: MemoryStats; + blkio_stats: {}; + cpu_stats: CPUStats; + precpu_stats: CPUStats; + } - interface ContainerStats { - read: string; - pid_stats: { - current: number; - }; - networks: NetworkStats; - memory_stats: MemoryStats; - blkio_stats: {}; - cpu_stats: CPUStats; - precpu_stats: CPUStats; - } - interface HostConfig { AutoRemove: boolean; Binds: string[]; From 84efa71066822fca8efa9155ab1d7a41b637bdc0 Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Wed, 12 Dec 2018 14:05:43 +0100 Subject: [PATCH 7/7] Mount config for creating a container --- types/dockerode/index.d.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/types/dockerode/index.d.ts b/types/dockerode/index.d.ts index 694cc295b4..cd06bc7ebb 100644 --- a/types/dockerode/index.d.ts +++ b/types/dockerode/index.d.ts @@ -762,6 +762,38 @@ declare namespace Dockerode { [key: string]: EndpointSettings; } + type MountType = + | "bind" + | "volume" + | "tmpfs"; + + type MountConsistency = + | "default" + | "consistent" + | "cached" + | "delegated"; + + type MountPropagation = + | "private" + | "rprivate" + | "shared" + | "rshared" + | "slave" + | "rslave"; + + interface MountSettings { + Target: string; + Source: string; + Type: MountType; + ReadOnly ?: boolean; + Consistency ?: MountConsistency; + BindOptions ?: { + Propagation: MountPropagation; + }; + } + + type MountConfig = MountSettings[]; + interface ContainerCreateOptions { name?: string; Hostname?: string; @@ -818,6 +850,7 @@ declare namespace Dockerode { DnsSearch?: string[]; ExtraHosts?: any; VolumesFrom?: string[]; + Mounts?: MountConfig; CapAdd?: string[]; CapDrop?: string[]; GroupAdd?: string[];