From 0556a353761cf10d710fc0c359d3e087b3a1c07a Mon Sep 17 00:00:00 2001 From: Red5d Date: Wed, 28 Jul 2021 23:03:54 -0400 Subject: [PATCH 1/4] Remove fields that are invalid in the compose v3 spec --- autocompose.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/autocompose.py b/autocompose.py index 25eab9e..dc986b9 100644 --- a/autocompose.py +++ b/autocompose.py @@ -66,8 +66,6 @@ def generate(cname): 'volumes': cattrs['HostConfig']['Binds'], 'volume_driver': cattrs['HostConfig']['VolumeDriver'], 'volumes_from': cattrs['HostConfig']['VolumesFrom'], - 'cpu_shares': cattrs['HostConfig']['CpuShares'], - 'cpuset': cattrs['HostConfig']['CpusetCpus']+','+cattrs['HostConfig']['CpusetMems'], 'entrypoint': cattrs['Config']['Entrypoint'], 'user': cattrs['Config']['User'], 'working_dir': cattrs['Config']['WorkingDir'], @@ -75,8 +73,6 @@ def generate(cname): 'hostname': cattrs['Config']['Hostname'], 'ipc': cattrs['HostConfig']['IpcMode'], 'mac_address': cattrs['NetworkSettings']['MacAddress'], - 'mem_limit': cattrs['HostConfig']['Memory'], - 'memswap_limit': cattrs['HostConfig']['MemorySwap'], 'privileged': cattrs['HostConfig']['Privileged'], 'restart': cattrs['HostConfig']['RestartPolicy']['Name'], 'read_only': cattrs['HostConfig']['ReadonlyRootfs'], From d8e5aacf20fb157f1c2dc4b7e4c0db8275f7675f Mon Sep 17 00:00:00 2001 From: Red5d Date: Wed, 28 Jul 2021 23:13:17 -0400 Subject: [PATCH 2/4] Exclude the 'networks' key if only the default bridge network is present --- autocompose.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/autocompose.py b/autocompose.py index dc986b9..d2bdfe8 100644 --- a/autocompose.py +++ b/autocompose.py @@ -60,7 +60,7 @@ def generate(cname): #'log_driver': cattrs['HostConfig']['LogConfig']['Type'], #'log_opt': cattrs['HostConfig']['LogConfig']['Config'], 'logging': {'driver': cattrs['HostConfig']['LogConfig']['Type'], 'options': cattrs['HostConfig']['LogConfig']['Config']}, - 'networks': {x for x in cattrs['NetworkSettings']['Networks'].keys()}, + 'networks': {x for x in cattrs['NetworkSettings']['Networks'].keys() if x != 'bridge'}, 'security_opt': cattrs['HostConfig']['SecurityOpt'], 'ulimits': cattrs['HostConfig']['Ulimits'], 'volumes': cattrs['HostConfig']['Binds'], @@ -80,6 +80,9 @@ def generate(cname): 'tty': cattrs['Config']['Tty'] } + if values['networks'] == set(): + del values['networks'] + networklist = c.networks.list() networks = {} for network in networklist: From a1f2aabdee8b014e4107200f122d31a8e0ad1bc5 Mon Sep 17 00:00:00 2001 From: Red5d Date: Wed, 28 Jul 2021 23:19:19 -0400 Subject: [PATCH 3/4] Fix lines that depend on the 'networks' key being in values list --- autocompose.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/autocompose.py b/autocompose.py index d2bdfe8..11299a0 100644 --- a/autocompose.py +++ b/autocompose.py @@ -80,14 +80,14 @@ def generate(cname): 'tty': cattrs['Config']['Tty'] } + networks = {} if values['networks'] == set(): del values['networks'] - - networklist = c.networks.list() - networks = {} - for network in networklist: - if network.attrs['Name'] in values['networks']: - networks[network.attrs['Name']] = {'external': (not network.attrs['Internal'])} + else: + networklist = c.networks.list() + for network in networklist: + if network.attrs['Name'] in values['networks']: + networks[network.attrs['Name']] = {'external': (not network.attrs['Internal'])} # Check for command and add it if present. if cattrs['Config']['Cmd'] != None: From 881b7979d5e6fb7b62bc290e650c7870427a9dfe Mon Sep 17 00:00:00 2001 From: Red5d Date: Wed, 28 Jul 2021 23:43:07 -0400 Subject: [PATCH 4/4] Fix malformed 'devices' values --- autocompose.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autocompose.py b/autocompose.py index 11299a0..3527e7f 100644 --- a/autocompose.py +++ b/autocompose.py @@ -49,7 +49,7 @@ def generate(cname): 'cap_drop': cattrs['HostConfig']['CapDrop'], 'cgroup_parent': cattrs['HostConfig']['CgroupParent'], 'container_name': cattrs['Name'][1:], - 'devices': cattrs['HostConfig']['Devices'], + 'devices': [], 'dns': cattrs['HostConfig']['Dns'], 'dns_search': cattrs['HostConfig']['DnsSearch'], 'environment': cattrs['Config']['Env'], @@ -80,6 +80,10 @@ def generate(cname): 'tty': cattrs['Config']['Tty'] } + # Populate devices key if device values are present + if cattrs['HostConfig']['Devices']: + values['devices'] = [x['PathOnHost']+':'+x['PathInContainer'] for x in cattrs['HostConfig']['Devices']] + networks = {} if values['networks'] == set(): del values['networks']