From ed4dd13fd3ca2b0ee42a67a78e1974166e0e0eaf Mon Sep 17 00:00:00 2001 From: Yuriy Bogdanov Date: Tue, 7 Jul 2015 20:46:49 +0300 Subject: [PATCH] expose published ports as well --- src/compose/config/config.go | 9 +++++++-- src/compose/config/convert.go | 7 ++++++- src/compose/config/testdata/compose.yml | 1 + src/compose/config/testdata/container_main_config.json | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/compose/config/config.go b/src/compose/config/config.go index 6d04b14..1cce72d 100644 --- a/src/compose/config/config.go +++ b/src/compose/config/config.go @@ -13,8 +13,6 @@ import ( "github.com/go-yaml/yaml" ) -// TODO: ports default to /tcp - // Config represents the data structure which is loaded from compose.yml type Config struct { Namespace string // All containers names under current compose.yml will be prefixed with this namespace @@ -183,6 +181,13 @@ func ReadConfig(name string, reader io.Reader, vars map[string]interface{}) (*Co container.Net.Container = *container.Net.Container.DefaultNamespace(config.Namespace) } } + + // Fix exposed ports + for k, port := range container.Expose { + if !strings.Contains(port, "/") { + container.Expose[k] = port + "/tcp" + } + } } return config, nil diff --git a/src/compose/config/convert.go b/src/compose/config/convert.go index b67a243..2f062df 100644 --- a/src/compose/config/convert.go +++ b/src/compose/config/convert.go @@ -72,12 +72,17 @@ func (config *Container) GetApiConfig() *docker.Config { } // expose - if config.Expose != nil { + if len(config.Expose) > 0 || len(config.Ports) > 0 { apiConfig.ExposedPorts = map[docker.Port]struct{}{} for _, portBinding := range config.Expose { port := (docker.Port)(portBinding) apiConfig.ExposedPorts[port] = struct{}{} } + // expose publised ports as well + for _, configPort := range config.Ports { + port := (docker.Port)(configPort.Port) + apiConfig.ExposedPorts[port] = struct{}{} + } } // env diff --git a/src/compose/config/testdata/compose.yml b/src/compose/config/testdata/compose.yml index 841d05c..e56cbca 100644 --- a/src/compose/config/testdata/compose.yml +++ b/src/compose/config/testdata/compose.yml @@ -25,6 +25,7 @@ containers: entrypoint: ["/bin/patterns"] expose: - 23456/tcp + - 5000 publish_all_ports: true labels: service: pattern diff --git a/src/compose/config/testdata/container_main_config.json b/src/compose/config/testdata/container_main_config.json index 1d46940..c0929b5 100644 --- a/src/compose/config/testdata/container_main_config.json +++ b/src/compose/config/testdata/container_main_config.json @@ -1 +1 @@ -{"Hostname":"pattern1","Domainname":"grammarly.com","User":"root","Memory":314572800,"MemorySwap":1073741824,"CpuShares":512,"Cpuset":"0-2","ExposedPorts":{"23456/tcp":{}},"Env":["AWS_KEY=asdqwe"],"Cmd":["param1","param2"],"Image":"dockerhub.grammarly.io/patterns:1.9.2","Volumes":{"/var/log":{}},"WorkingDir":"/app","Entrypoint":["/bin/patterns"],"NetworkDisabled":true,"Labels":{"num":"1","service":"pattern"}} +{"Hostname":"pattern1","Domainname":"grammarly.com","User":"root","Memory":314572800,"MemorySwap":1073741824,"CpuShares":512,"Cpuset":"0-2","ExposedPorts":{"23456/tcp":{},"5000/tcp":{},"5005/tcp":{},"5006/tcp":{}},"Env":["AWS_KEY=asdqwe"],"Cmd":["param1","param2"],"Image":"dockerhub.grammarly.io/patterns:1.9.2","Volumes":{"/var/log":{}},"WorkingDir":"/app","Entrypoint":["/bin/patterns"],"NetworkDisabled":true,"Labels":{"num":"1","service":"pattern"}}