From 1408fd7bcb5f25b75679b7ce0e509adc7f8f6004 Mon Sep 17 00:00:00 2001 From: quentinGllmt Date: Thu, 6 May 2021 16:50:11 +0200 Subject: [PATCH] Fix parsing driver_opts from compose to docker network creation Change-type: patch Signed-off-by: quentinGllmt --- src/compose/network.ts | 1 + test/src/compose/network.spec.ts | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/compose/network.ts b/src/compose/network.ts index 06475673..5fb5b6aa 100644 --- a/src/compose/network.ts +++ b/src/compose/network.ts @@ -130,6 +130,7 @@ export class Network { Name: Network.generateDockerName(this.appId, this.name), Driver: this.config.driver, CheckDuplicate: true, + Options: this.config.options, IPAM: { Driver: this.config.ipam.driver, Config: this.config.ipam.config.map((conf) => { diff --git a/test/src/compose/network.spec.ts b/test/src/compose/network.spec.ts index 3b497ed1..cb41746c 100644 --- a/test/src/compose/network.spec.ts +++ b/test/src/compose/network.spec.ts @@ -110,6 +110,62 @@ describe('compose/network', () => { 'Network IPAM config entries must have both a subnet and gateway', ); }); + + it('parses values from a compose object', () => { + const network1 = Network.fromComposeObject('default', 12345, { + driver: 'bridge', + enable_ipv6: true, + internal: false, + ipam: { + driver: 'default', + options: { + 'com.docker.ipam-option': 'abcd', + }, + config: [ + { + subnet: '172.18.0.0/16', + gateway: '172.18.0.1', + }, + ], + }, + driver_opts: { + 'com.docker.network-option': 'abcd', + }, + labels: { + 'com.docker.some-label': 'yes', + }, + }); + + const dockerConfig = network1.toDockerConfig(); + + expect(dockerConfig.Driver).to.equal('bridge'); + // Check duplicate forced to be true + expect(dockerConfig.CheckDuplicate).to.equal(true); + expect(dockerConfig.Internal).to.equal(false); + expect(dockerConfig.EnableIPv6).to.equal(true); + + expect(dockerConfig.IPAM).to.deep.equal({ + Driver: 'default', + Options: { + 'com.docker.ipam-option': 'abcd', + }, + Config: [ + { + Subnet: '172.18.0.0/16', + Gateway: '172.18.0.1', + }, + ], + }); + + expect(dockerConfig.Labels).to.deep.equal({ + 'io.balena.supervised': 'true', + 'com.docker.some-label': 'yes', + }); + + expect(dockerConfig.Options).to.deep.equal({ + 'com.docker.network-option': 'abcd', + }); + }); }); describe('creating a network from docker engine state', () => {