Skip to content

Commit

Permalink
Merge pull request #5845 from docker/5253-port-serialize
Browse files Browse the repository at this point in the history
Fix port serialization with external IP
  • Loading branch information
shin- authored Mar 31, 2018
2 parents 4813494 + 7aa51a1 commit 2975f06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compose/config/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ def denormalize_service_dict(service_dict, version, image_digest=None):
service_dict['healthcheck']['start_period'] = serialize_ns_time_value(
service_dict['healthcheck']['start_period']
)
if 'ports' in service_dict and version < V3_2:

if 'ports' in service_dict:
service_dict['ports'] = [
p.legacy_repr() if isinstance(p, types.ServicePort) else p
p.legacy_repr() if p.external_ip or version < V3_2 else p
for p in service_dict['ports']
]
if 'volumes' in service_dict and (version < V2_3 or (version > V3_0 and version < V3_2)):
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/config/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4943,6 +4943,18 @@ def test_serialize_ports(self):
serialized_config = yaml.load(serialize_config(config_dict))
assert '8080:80/tcp' in serialized_config['services']['web']['ports']

def test_serialize_ports_with_ext_ip(self):
config_dict = config.Config(version=V3_5, services=[
{
'ports': [types.ServicePort('80', '8080', None, None, '127.0.0.1')],
'image': 'alpine',
'name': 'web'
}
], volumes={}, networks={}, secrets={}, configs={})

serialized_config = yaml.load(serialize_config(config_dict))
assert '127.0.0.1:8080:80/tcp' in serialized_config['services']['web']['ports']

def test_serialize_configs(self):
service_dict = {
'image': 'example/web',
Expand Down

0 comments on commit 2975f06

Please sign in to comment.