@dockstat/docker 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,673 @@
1
+ // ============================================================================
2
+ // Container Types
3
+ // ============================================================================
4
+
5
+ /**
6
+ * Container summary information
7
+ */
8
+ export interface ContainerSummary {
9
+ Id: string
10
+ Names: string[]
11
+ Image: string
12
+ ImageID: string
13
+ Command: string
14
+ Created: number
15
+ Ports: Port[]
16
+ SizeRw?: number
17
+ SizeRootFs?: number
18
+ Labels?: Record<string, string>
19
+ State: string
20
+ Status: string
21
+ HostConfig?: {
22
+ NetworkMode: string
23
+ Annotations?: Record<string, string>
24
+ }
25
+ NetworkSettings?: {
26
+ Networks?: Record<string, NetworkSummary>
27
+ }
28
+ Mounts?: Mount[]
29
+ Health?: Health
30
+ }
31
+
32
+ /**
33
+ * Detailed container information
34
+ */
35
+ export interface ContainerInspectResponse {
36
+ Id: string
37
+ Created: string
38
+ Path: string
39
+ Args: string[]
40
+ State: ContainerState
41
+ Image: string
42
+ ResolvConfPath: string
43
+ HostnamePath: string
44
+ HostsPath: string
45
+ LogPath: string
46
+ Name: string
47
+ RestartCount: number
48
+ Driver: string
49
+ Platform: string
50
+ MountLabel: string
51
+ ProcessLabel: string
52
+ AppArmorProfile: string
53
+ ExecIDs: string[]
54
+ HostConfig: HostConfig
55
+ GraphDriver: GraphDriver
56
+ SizeRw?: number
57
+ SizeRootFs?: number
58
+ Mounts?: Mount[]
59
+ Config: ContainerConfig
60
+ NetworkSettings: NetworkSettings
61
+ }
62
+
63
+ /**
64
+ * Container state information
65
+ */
66
+ export interface ContainerState {
67
+ Status: string
68
+ Running: boolean
69
+ Paused: boolean
70
+ Restarting: boolean
71
+ OOMKilled: boolean
72
+ Dead: boolean
73
+ Pid?: number
74
+ ExitCode?: number
75
+ Error?: string
76
+ StartedAt?: string
77
+ FinishedAt?: string
78
+ Health?: Health
79
+ }
80
+
81
+ /**
82
+ * Container configuration
83
+ */
84
+ export interface ContainerConfig {
85
+ Hostname: string
86
+ Domainname: string
87
+ User?: string
88
+ AttachStdin: boolean
89
+ AttachStdout: boolean
90
+ AttachStderr: boolean
91
+ ExposedPorts?: Record<string, object> | null
92
+ Tty: boolean
93
+ OpenStdin: boolean
94
+ StdinOnce: boolean
95
+ Env?: string[]
96
+ Cmd?: string[]
97
+ Healthcheck?: HealthConfig
98
+ ArgsEscaped: boolean | null
99
+ Image: string
100
+ Volumes?: Record<string, object>
101
+ WorkingDir: string
102
+ Entrypoint?: string[]
103
+ NetworkDisabled?: boolean
104
+ MacAddress?: string
105
+ OnBuild?: string[]
106
+ Labels?: Record<string, string>
107
+ StopSignal?: string
108
+ StopTimeout?: number
109
+ Shell?: string[]
110
+ }
111
+
112
+ /**
113
+ * Host configuration
114
+ */
115
+ export interface HostConfig {
116
+ Binds?: string[]
117
+ ContainerIDFile?: string
118
+ LogConfig?: LogConfig
119
+ NetworkMode?: string
120
+ PortBindings?: Record<string, PortBinding[]>
121
+ RestartPolicy?: RestartPolicy
122
+ AutoRemove?: boolean
123
+ VolumeDriver?: string
124
+ VolumesFrom?: string[]
125
+ CapAdd?: string[]
126
+ CapDrop?: string[]
127
+ CgroupnsMode?: string
128
+ Dns?: string[]
129
+ DnsOptions?: string[]
130
+ DnsSearch?: string[]
131
+ ExtraHosts?: string[]
132
+ GroupAdd?: string[]
133
+ IpcMode?: string
134
+ Cgroup?: string
135
+ Links?: string[]
136
+ OomScoreAdj?: number
137
+ PidMode?: string
138
+ Privileged?: boolean
139
+ PublishAllPorts?: boolean
140
+ ReadonlyRootfs?: boolean
141
+ SecurityOpt?: string[]
142
+ StorageOpt?: Record<string, string>
143
+ Tmpfs?: Record<string, string>
144
+ UTSMode?: string
145
+ UsernsMode?: string
146
+ ShmSize?: number
147
+ Sysctls?: Record<string, string>
148
+ Runtime?: string
149
+ ConsoleSize?: number[]
150
+ Isolation?: string
151
+ Resources?: Resources
152
+ MaskedPaths?: string[]
153
+ ReadonlyPaths?: string[]
154
+ }
155
+
156
+ /**
157
+ * Container stats
158
+ */
159
+ export interface ContainerStatsResponse {
160
+ id?: string
161
+ name?: string
162
+ os_type?: string
163
+ read: string
164
+ cpu_stats: ContainerCPUStats
165
+ memory_stats: ContainerMemoryStats
166
+ networks?: Record<string, ContainerNetworkStats>
167
+ pids_stats?: ContainerPidsStats
168
+ blkio_stats: ContainerBlkioStats
169
+ num_procs?: number
170
+ storage_stats?: ContainerStorageStats
171
+ }
172
+
173
+ /**
174
+ * CPU stats
175
+ */
176
+ export interface ContainerCPUStats {
177
+ cpu_usage: ContainerCPUUsage
178
+ system_cpu_usage: number
179
+ online_cpus?: number
180
+ throttling_data?: ContainerThrottlingData
181
+ }
182
+
183
+ /**
184
+ * CPU usage
185
+ */
186
+ export interface ContainerCPUUsage {
187
+ total_usage: number
188
+ percpu_usage?: number[]
189
+ usage_in_kernelmode: number
190
+ usage_in_usermode: number
191
+ }
192
+
193
+ /**
194
+ * Throttling data
195
+ */
196
+ export interface ContainerThrottlingData {
197
+ periods: number
198
+ throttled_periods: number
199
+ throttled_time: number
200
+ }
201
+
202
+ /**
203
+ * Memory stats
204
+ */
205
+ export interface ContainerMemoryStats {
206
+ usage: number
207
+ max_usage?: number
208
+ stats?: Record<string, number>
209
+ failcnt?: number
210
+ limit: number
211
+ commitbytes?: number
212
+ commitpeakbytes?: number
213
+ privateworkingset?: number
214
+ }
215
+
216
+ /**
217
+ * PIDs stats
218
+ */
219
+ export interface ContainerPidsStats {
220
+ current?: number
221
+ limit?: number
222
+ }
223
+
224
+ /**
225
+ * Block I/O stats
226
+ */
227
+ export interface ContainerBlkioStats {
228
+ io_service_bytes_recursive?: ContainerBlkioStatEntry[]
229
+ io_serviced_recursive?: ContainerBlkioStatEntry[]
230
+ io_queue_recursive?: ContainerBlkioStatEntry[]
231
+ io_service_time_recursive?: ContainerBlkioStatEntry[]
232
+ io_wait_time_recursive?: ContainerBlkioStatEntry[]
233
+ io_merged_recursive?: ContainerBlkioStatEntry[]
234
+ io_time_recursive?: ContainerBlkioStatEntry[]
235
+ sectors_recursive?: ContainerBlkioStatEntry[]
236
+ }
237
+
238
+ /**
239
+ * Block I/O stat entry
240
+ */
241
+ export interface ContainerBlkioStatEntry {
242
+ major: number
243
+ minor: number
244
+ op: string
245
+ value: number
246
+ }
247
+
248
+ /**
249
+ * Network stats
250
+ */
251
+ export interface ContainerNetworkStats {
252
+ rx_bytes: number
253
+ rx_packets: number
254
+ rx_errors: number
255
+ rx_dropped: number
256
+ tx_bytes: number
257
+ tx_packets: number
258
+ tx_errors: number
259
+ tx_dropped: number
260
+ }
261
+
262
+ /**
263
+ * Storage stats
264
+ */
265
+ export interface ContainerStorageStats {
266
+ read_count_normalized?: number
267
+ read_size_bytes?: number
268
+ write_count_normalized?: number
269
+ write_size_bytes?: number
270
+ }
271
+
272
+ /**
273
+ * Top processes
274
+ */
275
+ export interface ContainerTopResponse {
276
+ Titles: string[]
277
+ Processes: string[][]
278
+ }
279
+
280
+ /**
281
+ * Wait response
282
+ */
283
+ export interface ContainerWaitResponse {
284
+ StatusCode: number
285
+ Error?: ContainerWaitExitError
286
+ }
287
+
288
+ /**
289
+ * Wait exit error
290
+ */
291
+ export interface ContainerWaitExitError {
292
+ Message: string
293
+ }
294
+
295
+ /**
296
+ * Create container response
297
+ */
298
+ export interface ContainerCreateResponse {
299
+ Id: string
300
+ Warnings?: string[]
301
+ }
302
+
303
+ /**
304
+ * Update container response
305
+ */
306
+ export interface ContainerUpdateResponse {
307
+ Warnings?: string[]
308
+ }
309
+
310
+ /**
311
+ * Container prune response
312
+ */
313
+ export interface ContainerPruneResponse {
314
+ ContainersDeleted?: string[]
315
+ SpaceReclaimed: number
316
+ }
317
+
318
+ /**
319
+ * Health status
320
+ */
321
+ export interface Health {
322
+ Status: string
323
+ FailingStreak?: number
324
+ Log?: HealthcheckResult[]
325
+ }
326
+
327
+ /**
328
+ * Health check configuration
329
+ */
330
+ export interface HealthConfig {
331
+ Test?: string[]
332
+ Interval?: number
333
+ Timeout?: number
334
+ Retries?: number
335
+ StartPeriod?: number
336
+ StartInterval?: number
337
+ }
338
+
339
+ /**
340
+ * Health check result
341
+ */
342
+ export interface HealthcheckResult {
343
+ Start: string
344
+ End: string
345
+ ExitCode: number
346
+ Output: string
347
+ }
348
+
349
+ /**
350
+ * Port
351
+ */
352
+ export interface Port {
353
+ IP: string
354
+ PrivatePort: number
355
+ PublicPort?: number
356
+ Type: string
357
+ }
358
+
359
+ /**
360
+ * Port binding
361
+ */
362
+ export interface PortBinding {
363
+ HostIp: string
364
+ HostPort: string
365
+ }
366
+
367
+ /**
368
+ * Restart policy
369
+ */
370
+ export interface RestartPolicy {
371
+ Name: string
372
+ MaximumRetryCount?: number
373
+ }
374
+
375
+ /**
376
+ * Resources
377
+ */
378
+ export interface Resources {
379
+ CpuShares?: number
380
+ Memory?: number
381
+ NanoCpus?: number
382
+ CpuPeriod?: number
383
+ CpuQuota?: number
384
+ CpuRealtimePeriod?: number
385
+ CpuRealtimeRuntime?: number
386
+ CpusetCpus?: string
387
+ CpusetMems?: string
388
+ BlkioWeight?: number
389
+ BlkioWeightDevice?: { Path: string; Weight: number }[]
390
+ BlkioDeviceReadBps?: { Path: string; Rate: number }[]
391
+ BlkioDeviceWriteBps?: { Path: string; Rate: number }[]
392
+ BlkioDeviceReadIOps?: { Path: string; Rate: number }[]
393
+ BlkioDeviceWriteIOps?: { Path: string; Rate: number }[]
394
+ MemoryReservation?: number
395
+ MemorySwap?: number
396
+ MemorySwappiness?: number
397
+ OomKillDisable?: boolean
398
+ PidsLimit?: number
399
+ Ulimits?: { Name: string; Soft: number; Hard: number }[]
400
+ }
401
+
402
+ /**
403
+ * Graph driver
404
+ */
405
+ export interface GraphDriver {
406
+ Name: string
407
+ Data: Record<string, string>
408
+ }
409
+
410
+ /**
411
+ * Mount
412
+ */
413
+ export interface Mount {
414
+ Type: string
415
+ Name?: string
416
+ Source?: string
417
+ Destination: string
418
+ Driver?: string
419
+ Mode?: string
420
+ RW?: boolean
421
+ Propagation?: string
422
+ }
423
+
424
+ /**
425
+ * Log config
426
+ */
427
+ export interface LogConfig {
428
+ Type: string
429
+ Config?: Record<string, string>
430
+ }
431
+
432
+ /**
433
+ * Network settings
434
+ */
435
+ export interface NetworkSettings {
436
+ SandboxID: string
437
+ SandboxKey: string
438
+ Ports?: Record<string, PortBinding[]>
439
+ Networks?: Record<string, NetworkSummary>
440
+ }
441
+
442
+ /**
443
+ * Network summary
444
+ */
445
+ export interface NetworkSummary {
446
+ EndpointID?: string
447
+ Gateway?: string
448
+ IPAddress?: string
449
+ IPPrefixLen?: number
450
+ IPv6Gateway?: string
451
+ GlobalIPv6Address?: string
452
+ GlobalIPv6PrefixLen?: number
453
+ MacAddress?: string
454
+ NetworkID?: string
455
+ }
456
+
457
+ /**
458
+ * Filesystem change
459
+ */
460
+ export interface FilesystemChange {
461
+ Path: string
462
+ Kind: number
463
+ }
464
+
465
+ /**
466
+ * Exec create options
467
+ */
468
+ export interface ExecCreateOptions {
469
+ AttachStdin?: boolean
470
+ AttachStdout?: boolean
471
+ AttachStderr?: boolean
472
+ DetachKeys?: string
473
+ Tty?: boolean
474
+ Env?: string[]
475
+ Cmd?: string[]
476
+ Privileged?: boolean
477
+ User?: string
478
+ WorkingDir?: string
479
+ }
480
+
481
+ /**
482
+ * Exec create response
483
+ */
484
+ export interface ExecCreateResponse {
485
+ Id: string
486
+ }
487
+
488
+ /**
489
+ * Exec start options
490
+ */
491
+ export interface ExecStartOptions {
492
+ Detach?: boolean
493
+ Tty?: boolean
494
+ ConsoleSize?: number[]
495
+ }
496
+
497
+ /**
498
+ * Exec inspect response
499
+ */
500
+ export interface ExecInspectResponse {
501
+ CanRemove: boolean
502
+ DetachKeys: string
503
+ ID: string
504
+ Running: boolean
505
+ ExitCode: number
506
+ ProcessConfig: {
507
+ arguments: string[]
508
+ entrypoint: string
509
+ privileged: boolean
510
+ tty: boolean
511
+ user: string
512
+ }
513
+ OpenStdin: boolean
514
+ OpenStderr: boolean
515
+ OpenStdout: boolean
516
+ ContainerID: string
517
+ Pid: number
518
+ }
519
+
520
+ /**
521
+ * Archive info
522
+ */
523
+ export interface ArchiveInfo {
524
+ name: string
525
+ size: number
526
+ mode: number
527
+ mtime: string
528
+ linkTarget?: string
529
+ }
530
+
531
+ /**
532
+ * Network config
533
+ */
534
+ export interface NetworkingConfig {
535
+ EndpointsConfig?: Record<string, EndpointSettings>
536
+ }
537
+
538
+ /**
539
+ * Endpoint settings
540
+ */
541
+ export interface EndpointSettings {
542
+ IPAMConfig?: {
543
+ IPv4Address?: string
544
+ IPv6Address?: string
545
+ LinkLocalIPs?: string[]
546
+ }
547
+ Links?: string[]
548
+ Aliases?: string[]
549
+ NetworkID?: string
550
+ EndpointID?: string
551
+ Gateway?: string
552
+ IPAddress?: string
553
+ IPPrefixLen?: number
554
+ IPv6Gateway?: string
555
+ GlobalIPv6Address?: string
556
+ GlobalIPv6PrefixLen?: number
557
+ MacAddress?: string
558
+ DriverOpts?: Record<string, string>
559
+ }
560
+
561
+ // ============================================================================
562
+ // Request/Response Types
563
+ // ============================================================================
564
+
565
+ /**
566
+ * List containers options
567
+ */
568
+ export interface ListContainersOptions {
569
+ all?: boolean
570
+ limit?: number
571
+ size?: boolean
572
+ filters?: {
573
+ ancestor?: string[]
574
+ before?: string[]
575
+ expose?: string[]
576
+ exited?: number[]
577
+ health?: string[]
578
+ id?: string[]
579
+ isolation?: string[]
580
+ label?: string[]
581
+ name?: string[]
582
+ network?: string[]
583
+ publish?: string[]
584
+ since?: string[]
585
+ status?: string[]
586
+ volume?: string[]
587
+ }
588
+ }
589
+
590
+ /**
591
+ * Create container options
592
+ */
593
+ export interface CreateContainerOptions {
594
+ name?: string
595
+ platform?: string
596
+ HostConfig?: HostConfig
597
+ NetworkingConfig?: NetworkingConfig
598
+ }
599
+
600
+ /**
601
+ * Update container options
602
+ */
603
+ export interface UpdateContainerOptions {
604
+ BlkioWeight?: number
605
+ CpuShares?: number
606
+ CpuPeriod?: number
607
+ CpuQuota?: number
608
+ CpuRealtimePeriod?: number
609
+ CpuRealtimeRuntime?: number
610
+ CpusetCpus?: string
611
+ CpusetMems?: string
612
+ Memory?: number
613
+ MemorySwap?: number
614
+ MemoryReservation?: number
615
+ RestartPolicy?: RestartPolicy
616
+ }
617
+
618
+ /**
619
+ * Attach options
620
+ */
621
+ export interface AttachOptions {
622
+ detachKeys?: string
623
+ log?: boolean
624
+ stream?: boolean
625
+ stdin?: boolean
626
+ stdout?: boolean
627
+ stderr?: boolean
628
+ }
629
+
630
+ /**
631
+ * Logs options
632
+ */
633
+ export interface LogsOptions {
634
+ follow?: boolean
635
+ stdout?: boolean
636
+ stderr?: boolean
637
+ since?: number
638
+ until?: number
639
+ timestamps?: boolean
640
+ tail?: string
641
+ }
642
+
643
+ /**
644
+ * Wait condition
645
+ */
646
+ export type WaitCondition = "not-running" | "next-exit" | "removed"
647
+
648
+ /**
649
+ * Prune containers options
650
+ */
651
+ export interface PruneContainersOptions {
652
+ filters?: {
653
+ label?: string[]
654
+ until?: string
655
+ }
656
+ }
657
+
658
+ /**
659
+ * Stats options
660
+ */
661
+ export interface StatsOptions {
662
+ stream?: boolean
663
+ "one-shot"?: boolean
664
+ }
665
+
666
+ /**
667
+ * Change type
668
+ */
669
+ export enum ChangeType {
670
+ Modified = 0,
671
+ Added = 1,
672
+ Deleted = 2,
673
+ }
@@ -0,0 +1,14 @@
1
+ import { BaseModule } from "../base"
2
+ import type { ImageInformationResponse } from "./types"
3
+
4
+ export class DistributionModule extends BaseModule {
5
+ /**
6
+ * Return image digest and platform information by contacting the registry.
7
+ * @param image Image name or id
8
+ */
9
+ async getImageInfo(image: string) {
10
+ const path = `/distribution/${image}/json`
11
+ const res = await this.request(path, "GET")
12
+ return (await res.json()) as ImageInformationResponse
13
+ }
14
+ }
@@ -0,0 +1,24 @@
1
+ export type ImageInformationResponse = {
2
+ Descriptor: {
3
+ mediaType: string
4
+ digest: string
5
+ size: number
6
+ urls: string[] | null
7
+ annotations: Record<string, string> | null
8
+ data: string | null
9
+ platform: {
10
+ architecture: string
11
+ os: string
12
+ "os.version"?: string
13
+ "os.features"?: string[]
14
+ } | null
15
+ artifactType: string | null
16
+ }
17
+ Platforms: Array<{
18
+ architecture: string
19
+ os: string
20
+ "os.version"?: string
21
+ "os.features"?: string[]
22
+ variant?: string
23
+ }>
24
+ }