Skip to content

Commit 5118752

Browse files
committed
published can either be a port(int) or range (string)
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 4d4b741 commit 5118752

File tree

13 files changed

+138
-131
lines changed

13 files changed

+138
-131
lines changed

cli/options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestProjectWithDotEnv(t *testing.T) {
196196
assert.NilError(t, err)
197197
service, err := p.GetService("simple")
198198
assert.NilError(t, err)
199-
assert.Equal(t, service.Ports[0].Published, uint32(8000))
199+
assert.Equal(t, service.Ports[0].Published, "8000")
200200
}
201201

202202
func TestProjectWithDiscardEnvFile(t *testing.T) {

compatibility/services.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ func (c *AllowList) CheckPortsTarget(p *types.ServicePortConfig) {
550550
}
551551

552552
func (c *AllowList) CheckPortsPublished(p *types.ServicePortConfig) {
553-
if !c.supported("services.ports.published") && p.Published != 0 {
554-
p.Published = 0
553+
if !c.supported("services.ports.published") && len(p.Published) != 0 {
554+
p.Published = ""
555555
c.Unsupported("services.ports.published")
556556
}
557557
}

loader/full-struct_test.go

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -249,113 +249,113 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
249249
{
250250
Mode: "ingress",
251251
Target: 8000,
252-
Published: 8000,
252+
Published: "8000",
253253
Protocol: "tcp",
254254
},
255255
//"9090-9091:8080-8081",
256256
{
257257
Mode: "ingress",
258258
Target: 8080,
259-
Published: 9090,
259+
Published: "9090",
260260
Protocol: "tcp",
261261
},
262262
{
263263
Mode: "ingress",
264264
Target: 8081,
265-
Published: 9091,
265+
Published: "9091",
266266
Protocol: "tcp",
267267
},
268268
//"49100:22",
269269
{
270270
Mode: "ingress",
271271
Target: 22,
272-
Published: 49100,
272+
Published: "49100",
273273
Protocol: "tcp",
274274
},
275275
//"127.0.0.1:8001:8001",
276276
{
277277
Mode: "ingress",
278278
HostIP: "127.0.0.1",
279279
Target: 8001,
280-
Published: 8001,
280+
Published: "8001",
281281
Protocol: "tcp",
282282
},
283283
//"127.0.0.1:5000-5010:5000-5010",
284284
{
285285
Mode: "ingress",
286286
HostIP: "127.0.0.1",
287287
Target: 5000,
288-
Published: 5000,
288+
Published: "5000",
289289
Protocol: "tcp",
290290
},
291291
{
292292
Mode: "ingress",
293293
HostIP: "127.0.0.1",
294294
Target: 5001,
295-
Published: 5001,
295+
Published: "5001",
296296
Protocol: "tcp",
297297
},
298298
{
299299
Mode: "ingress",
300300
HostIP: "127.0.0.1",
301301
Target: 5002,
302-
Published: 5002,
302+
Published: "5002",
303303
Protocol: "tcp",
304304
},
305305
{
306306
Mode: "ingress",
307307
HostIP: "127.0.0.1",
308308
Target: 5003,
309-
Published: 5003,
309+
Published: "5003",
310310
Protocol: "tcp",
311311
},
312312
{
313313
Mode: "ingress",
314314
HostIP: "127.0.0.1",
315315
Target: 5004,
316-
Published: 5004,
316+
Published: "5004",
317317
Protocol: "tcp",
318318
},
319319
{
320320
Mode: "ingress",
321321
HostIP: "127.0.0.1",
322322
Target: 5005,
323-
Published: 5005,
323+
Published: "5005",
324324
Protocol: "tcp",
325325
},
326326
{
327327
Mode: "ingress",
328328
HostIP: "127.0.0.1",
329329
Target: 5006,
330-
Published: 5006,
330+
Published: "5006",
331331
Protocol: "tcp",
332332
},
333333
{
334334
Mode: "ingress",
335335
HostIP: "127.0.0.1",
336336
Target: 5007,
337-
Published: 5007,
337+
Published: "5007",
338338
Protocol: "tcp",
339339
},
340340
{
341341
Mode: "ingress",
342342
HostIP: "127.0.0.1",
343343
Target: 5008,
344-
Published: 5008,
344+
Published: "5008",
345345
Protocol: "tcp",
346346
},
347347
{
348348
Mode: "ingress",
349349
HostIP: "127.0.0.1",
350350
Target: 5009,
351-
Published: 5009,
351+
Published: "5009",
352352
Protocol: "tcp",
353353
},
354354
{
355355
Mode: "ingress",
356356
HostIP: "127.0.0.1",
357357
Target: 5010,
358-
Published: 5010,
358+
Published: "5010",
359359
Protocol: "tcp",
360360
},
361361
},
@@ -734,79 +734,79 @@ func fullExampleYAML(workingDir, homeDir string) string {
734734
protocol: tcp
735735
- mode: ingress
736736
target: 8000
737-
published: 8000
737+
published: "8000"
738738
protocol: tcp
739739
- mode: ingress
740740
target: 8080
741-
published: 9090
741+
published: "9090"
742742
protocol: tcp
743743
- mode: ingress
744744
target: 8081
745-
published: 9091
745+
published: "9091"
746746
protocol: tcp
747747
- mode: ingress
748748
target: 22
749-
published: 49100
749+
published: "49100"
750750
protocol: tcp
751751
- mode: ingress
752752
host_ip: 127.0.0.1
753753
target: 8001
754-
published: 8001
754+
published: "8001"
755755
protocol: tcp
756756
- mode: ingress
757757
host_ip: 127.0.0.1
758758
target: 5000
759-
published: 5000
759+
published: "5000"
760760
protocol: tcp
761761
- mode: ingress
762762
host_ip: 127.0.0.1
763763
target: 5001
764-
published: 5001
764+
published: "5001"
765765
protocol: tcp
766766
- mode: ingress
767767
host_ip: 127.0.0.1
768768
target: 5002
769-
published: 5002
769+
published: "5002"
770770
protocol: tcp
771771
- mode: ingress
772772
host_ip: 127.0.0.1
773773
target: 5003
774-
published: 5003
774+
published: "5003"
775775
protocol: tcp
776776
- mode: ingress
777777
host_ip: 127.0.0.1
778778
target: 5004
779-
published: 5004
779+
published: "5004"
780780
protocol: tcp
781781
- mode: ingress
782782
host_ip: 127.0.0.1
783783
target: 5005
784-
published: 5005
784+
published: "5005"
785785
protocol: tcp
786786
- mode: ingress
787787
host_ip: 127.0.0.1
788788
target: 5006
789-
published: 5006
789+
published: "5006"
790790
protocol: tcp
791791
- mode: ingress
792792
host_ip: 127.0.0.1
793793
target: 5007
794-
published: 5007
794+
published: "5007"
795795
protocol: tcp
796796
- mode: ingress
797797
host_ip: 127.0.0.1
798798
target: 5008
799-
published: 5008
799+
published: "5008"
800800
protocol: tcp
801801
- mode: ingress
802802
host_ip: 127.0.0.1
803803
target: 5009
804-
published: 5009
804+
published: "5009"
805805
protocol: tcp
806806
- mode: ingress
807807
host_ip: 127.0.0.1
808808
target: 5010
809-
published: 5010
809+
published: "5010"
810810
protocol: tcp
811811
privileged: true
812812
read_only: true
@@ -1314,109 +1314,109 @@ func fullExampleJSON(workingDir, homeDir string) string {
13141314
{
13151315
"mode": "ingress",
13161316
"target": 8000,
1317-
"published": 8000,
1317+
"published": "8000",
13181318
"protocol": "tcp"
13191319
},
13201320
{
13211321
"mode": "ingress",
13221322
"target": 8080,
1323-
"published": 9090,
1323+
"published": "9090",
13241324
"protocol": "tcp"
13251325
},
13261326
{
13271327
"mode": "ingress",
13281328
"target": 8081,
1329-
"published": 9091,
1329+
"published": "9091",
13301330
"protocol": "tcp"
13311331
},
13321332
{
13331333
"mode": "ingress",
13341334
"target": 22,
1335-
"published": 49100,
1335+
"published": "49100",
13361336
"protocol": "tcp"
13371337
},
13381338
{
13391339
"mode": "ingress",
13401340
"host_ip": "127.0.0.1",
13411341
"target": 8001,
1342-
"published": 8001,
1342+
"published": "8001",
13431343
"protocol": "tcp"
13441344
},
13451345
{
13461346
"mode": "ingress",
13471347
"host_ip": "127.0.0.1",
13481348
"target": 5000,
1349-
"published": 5000,
1349+
"published": "5000",
13501350
"protocol": "tcp"
13511351
},
13521352
{
13531353
"mode": "ingress",
13541354
"host_ip": "127.0.0.1",
13551355
"target": 5001,
1356-
"published": 5001,
1356+
"published": "5001",
13571357
"protocol": "tcp"
13581358
},
13591359
{
13601360
"mode": "ingress",
13611361
"host_ip": "127.0.0.1",
13621362
"target": 5002,
1363-
"published": 5002,
1363+
"published": "5002",
13641364
"protocol": "tcp"
13651365
},
13661366
{
13671367
"mode": "ingress",
13681368
"host_ip": "127.0.0.1",
13691369
"target": 5003,
1370-
"published": 5003,
1370+
"published": "5003",
13711371
"protocol": "tcp"
13721372
},
13731373
{
13741374
"mode": "ingress",
13751375
"host_ip": "127.0.0.1",
13761376
"target": 5004,
1377-
"published": 5004,
1377+
"published": "5004",
13781378
"protocol": "tcp"
13791379
},
13801380
{
13811381
"mode": "ingress",
13821382
"host_ip": "127.0.0.1",
13831383
"target": 5005,
1384-
"published": 5005,
1384+
"published": "5005",
13851385
"protocol": "tcp"
13861386
},
13871387
{
13881388
"mode": "ingress",
13891389
"host_ip": "127.0.0.1",
13901390
"target": 5006,
1391-
"published": 5006,
1391+
"published": "5006",
13921392
"protocol": "tcp"
13931393
},
13941394
{
13951395
"mode": "ingress",
13961396
"host_ip": "127.0.0.1",
13971397
"target": 5007,
1398-
"published": 5007,
1398+
"published": "5007",
13991399
"protocol": "tcp"
14001400
},
14011401
{
14021402
"mode": "ingress",
14031403
"host_ip": "127.0.0.1",
14041404
"target": 5008,
1405-
"published": 5008,
1405+
"published": "5008",
14061406
"protocol": "tcp"
14071407
},
14081408
{
14091409
"mode": "ingress",
14101410
"host_ip": "127.0.0.1",
14111411
"target": 5009,
1412-
"published": 5009,
1412+
"published": "5009",
14131413
"protocol": "tcp"
14141414
},
14151415
{
14161416
"mode": "ingress",
14171417
"host_ip": "127.0.0.1",
14181418
"target": 5010,
1419-
"published": 5010,
1419+
"published": "5010",
14201420
"protocol": "tcp"
14211421
}
14221422
],

loader/interpolate.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ var interpolateTypeCastMapping = map[interp.Path]interp.Cast{
5252
servicePath("oom_score_adj"): toInt64,
5353
servicePath("pids_limit"): toInt64,
5454
servicePath("ports", interp.PathMatchList, "target"): toInt,
55-
servicePath("ports", interp.PathMatchList, "published"): toInt,
5655
servicePath("privileged"): toBoolean,
5756
servicePath("read_only"): toBoolean,
5857
servicePath("scale"): toInt,

loader/loader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"path/filepath"
2525
"reflect"
2626
"sort"
27+
"strconv"
2728
"strings"
2829
"time"
2930

@@ -813,6 +814,10 @@ var transformServicePort TransformerFunc = func(data interface{}) (interface{},
813814
ports = append(ports, v)
814815
}
815816
case map[string]interface{}:
817+
published := value["published"]
818+
if v, ok := published.(int); ok {
819+
value["published"] = strconv.Itoa(v)
820+
}
816821
ports = append(ports, groupXFieldsIntoExtensions(value))
817822
default:
818823
return data, errors.Errorf("invalid type %T for port", value)

0 commit comments

Comments
 (0)