Skip to content

Commit

Permalink
published can either be a port(int) or range (string)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Feb 21, 2022
1 parent 4d4b741 commit 5118752
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 131 deletions.
2 changes: 1 addition & 1 deletion cli/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestProjectWithDotEnv(t *testing.T) {
assert.NilError(t, err)
service, err := p.GetService("simple")
assert.NilError(t, err)
assert.Equal(t, service.Ports[0].Published, uint32(8000))
assert.Equal(t, service.Ports[0].Published, "8000")
}

func TestProjectWithDiscardEnvFile(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions compatibility/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ func (c *AllowList) CheckPortsTarget(p *types.ServicePortConfig) {
}

func (c *AllowList) CheckPortsPublished(p *types.ServicePortConfig) {
if !c.supported("services.ports.published") && p.Published != 0 {
p.Published = 0
if !c.supported("services.ports.published") && len(p.Published) != 0 {
p.Published = ""
c.Unsupported("services.ports.published")
}
}
Expand Down
96 changes: 48 additions & 48 deletions loader/full-struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,113 +249,113 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
{
Mode: "ingress",
Target: 8000,
Published: 8000,
Published: "8000",
Protocol: "tcp",
},
//"9090-9091:8080-8081",
{
Mode: "ingress",
Target: 8080,
Published: 9090,
Published: "9090",
Protocol: "tcp",
},
{
Mode: "ingress",
Target: 8081,
Published: 9091,
Published: "9091",
Protocol: "tcp",
},
//"49100:22",
{
Mode: "ingress",
Target: 22,
Published: 49100,
Published: "49100",
Protocol: "tcp",
},
//"127.0.0.1:8001:8001",
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 8001,
Published: 8001,
Published: "8001",
Protocol: "tcp",
},
//"127.0.0.1:5000-5010:5000-5010",
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5000,
Published: 5000,
Published: "5000",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5001,
Published: 5001,
Published: "5001",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5002,
Published: 5002,
Published: "5002",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5003,
Published: 5003,
Published: "5003",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5004,
Published: 5004,
Published: "5004",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5005,
Published: 5005,
Published: "5005",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5006,
Published: 5006,
Published: "5006",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5007,
Published: 5007,
Published: "5007",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5008,
Published: 5008,
Published: "5008",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5009,
Published: 5009,
Published: "5009",
Protocol: "tcp",
},
{
Mode: "ingress",
HostIP: "127.0.0.1",
Target: 5010,
Published: 5010,
Published: "5010",
Protocol: "tcp",
},
},
Expand Down Expand Up @@ -734,79 +734,79 @@ func fullExampleYAML(workingDir, homeDir string) string {
protocol: tcp
- mode: ingress
target: 8000
published: 8000
published: "8000"
protocol: tcp
- mode: ingress
target: 8080
published: 9090
published: "9090"
protocol: tcp
- mode: ingress
target: 8081
published: 9091
published: "9091"
protocol: tcp
- mode: ingress
target: 22
published: 49100
published: "49100"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 8001
published: 8001
published: "8001"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5000
published: 5000
published: "5000"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5001
published: 5001
published: "5001"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5002
published: 5002
published: "5002"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5003
published: 5003
published: "5003"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5004
published: 5004
published: "5004"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5005
published: 5005
published: "5005"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5006
published: 5006
published: "5006"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5007
published: 5007
published: "5007"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5008
published: 5008
published: "5008"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5009
published: 5009
published: "5009"
protocol: tcp
- mode: ingress
host_ip: 127.0.0.1
target: 5010
published: 5010
published: "5010"
protocol: tcp
privileged: true
read_only: true
Expand Down Expand Up @@ -1314,109 +1314,109 @@ func fullExampleJSON(workingDir, homeDir string) string {
{
"mode": "ingress",
"target": 8000,
"published": 8000,
"published": "8000",
"protocol": "tcp"
},
{
"mode": "ingress",
"target": 8080,
"published": 9090,
"published": "9090",
"protocol": "tcp"
},
{
"mode": "ingress",
"target": 8081,
"published": 9091,
"published": "9091",
"protocol": "tcp"
},
{
"mode": "ingress",
"target": 22,
"published": 49100,
"published": "49100",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 8001,
"published": 8001,
"published": "8001",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5000,
"published": 5000,
"published": "5000",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5001,
"published": 5001,
"published": "5001",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5002,
"published": 5002,
"published": "5002",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5003,
"published": 5003,
"published": "5003",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5004,
"published": 5004,
"published": "5004",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5005,
"published": 5005,
"published": "5005",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5006,
"published": 5006,
"published": "5006",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5007,
"published": 5007,
"published": "5007",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5008,
"published": 5008,
"published": "5008",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5009,
"published": 5009,
"published": "5009",
"protocol": "tcp"
},
{
"mode": "ingress",
"host_ip": "127.0.0.1",
"target": 5010,
"published": 5010,
"published": "5010",
"protocol": "tcp"
}
],
Expand Down
1 change: 0 additions & 1 deletion loader/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var interpolateTypeCastMapping = map[interp.Path]interp.Cast{
servicePath("oom_score_adj"): toInt64,
servicePath("pids_limit"): toInt64,
servicePath("ports", interp.PathMatchList, "target"): toInt,
servicePath("ports", interp.PathMatchList, "published"): toInt,
servicePath("privileged"): toBoolean,
servicePath("read_only"): toBoolean,
servicePath("scale"): toInt,
Expand Down
5 changes: 5 additions & 0 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path/filepath"
"reflect"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -813,6 +814,10 @@ var transformServicePort TransformerFunc = func(data interface{}) (interface{},
ports = append(ports, v)
}
case map[string]interface{}:
published := value["published"]
if v, ok := published.(int); ok {
value["published"] = strconv.Itoa(v)
}
ports = append(ports, groupXFieldsIntoExtensions(value))
default:
return data, errors.Errorf("invalid type %T for port", value)
Expand Down
Loading

0 comments on commit 5118752

Please sign in to comment.