Skip to content

Commit 8acb62f

Browse files
authored
🤖 Merge PR DefinitelyTyped#72881 [dockerode] Support full NetworkCreateOptions by @cywang117
Signed-off-by: Christina Ying Wang <[email protected]>
1 parent 72cbf47 commit 8acb62f

File tree

2 files changed

+82
-6
lines changed

2 files changed

+82
-6
lines changed

‎types/dockerode/dockerode-tests.ts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,73 @@ docker.createNetwork({ Name: "networkName" }, (err, network) => {
387387
});
388388
});
389389

390+
// Should support all network create options
391+
// See: https://github.com/moby/moby/blob/7ea613d780be40e08665f0fc15bf53f5993455a9/api/types/network/network.go#L23-L46
392+
docker.createNetwork({
393+
Name: "networkName",
394+
CheckDuplicate: true,
395+
abortSignal: new AbortController().signal,
396+
Driver: "bridge",
397+
Scope: "local",
398+
EnableIPv4: true,
399+
EnableIPv6: true,
400+
IPAM: {
401+
Driver: "default",
402+
Options: {
403+
foo: "bar",
404+
},
405+
Config: [
406+
{
407+
Subnet: "172.28.0.0/16",
408+
IPRange: "172.28.1.0/24",
409+
Gateway: "172.28.0.1",
410+
},
411+
],
412+
},
413+
Internal: true,
414+
Attachable: true,
415+
Ingress: true,
416+
// Docker doesn't accept ConfigFrom & ConfigOnly together,
417+
// but that's not dockerode's job to enforce.
418+
ConfigOnly: true,
419+
ConfigFrom: { Network: "configOnlyNetwork" },
420+
Options: { someOption: "someValue" },
421+
Labels: { someLabel: "someValue" },
422+
}, (err, network) => {
423+
network.remove((err, data) => {
424+
// NOOP
425+
});
426+
});
427+
428+
// Should support all network create IPAM config options
429+
// See: https://github.com/moby/moby/blob/5d7550e9ef36f860738af643d321a132539452af/api/types/network/ipam.go#L11-L24
430+
docker.createNetwork({
431+
Name: "ipamNetwork",
432+
IPAM: {
433+
Driver: "default",
434+
Config: [
435+
{
436+
Subnet: "172.28.0.0/16",
437+
IPRange: "172.28.5.0/24",
438+
Gateway: "172.28.5.254",
439+
AuxiliaryAddresses: {
440+
host1: "172.28.1.5",
441+
host2: "172.28.1.6",
442+
host3: "172.28.1.7",
443+
},
444+
},
445+
],
446+
Options: {
447+
foo: "bar",
448+
bar: "0",
449+
},
450+
},
451+
}, (err, network) => {
452+
network.remove((err, data) => {
453+
// NOOP
454+
});
455+
});
456+
390457
docker.createVolume();
391458

392459
docker.createVolume({ Name: "volumeName", abortSignal: new AbortController().signal });

‎types/dockerode/index.d.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,15 @@ declare namespace Dockerode {
475475
Name: string;
476476
CheckDuplicate?: boolean | undefined;
477477
Driver?: string | undefined;
478+
Scope?: string | undefined;
479+
EnableIPv4?: boolean | undefined;
480+
EnableIPv6?: boolean | undefined;
481+
IPAM?: IPAM | undefined;
478482
Internal?: boolean | undefined;
479483
Attachable?: boolean | undefined;
480484
Ingress?: boolean | undefined;
481-
IPAM?: IPAM | undefined;
482-
EnableIPv6?: boolean | undefined;
485+
ConfigOnly?: boolean | undefined;
486+
ConfigFrom?: { Network?: string } | undefined;
483487
Options?: { [option: string]: string } | undefined;
484488
Labels?: { [label: string]: string } | undefined;
485489

@@ -499,13 +503,18 @@ declare namespace Dockerode {
499503
IPv6Address: string;
500504
}
501505

502-
/* tslint:disable:interface-name */
503506
interface IPAM {
504-
Driver: string;
505-
Config?: Array<{ [key: string]: string }> | undefined;
507+
Driver?: string;
506508
Options?: { [key: string]: string } | undefined;
509+
Config?:
510+
| Array<{
511+
Subnet?: string | undefined;
512+
IPRange?: string | undefined;
513+
Gateway?: string | undefined;
514+
AuxiliaryAddresses?: Partial<{ [host: string]: string }> | undefined;
515+
}>
516+
| undefined;
507517
}
508-
/* tslint:enable:interface-name */
509518

510519
interface VolumeCreateOptions {
511520
Name?: string | undefined;

0 commit comments

Comments
 (0)