Skip to content

Commit eb0c6a2

Browse files
assume host mode for postgres short ports
1 parent 2ead202 commit eb0c6a2

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

src/pkg/cli/compose/fixup.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ func fixupPostgresService(svccfg *composeTypes.ServiceConfig, provider client.Pr
241241
}
242242
term.Debugf("service %q: adding postgres host port %d", svccfg.Name, port)
243243
svccfg.Ports = []composeTypes.ServicePortConfig{{Target: port, Mode: Mode_HOST, Protocol: Protocol_TCP}}
244+
} else {
245+
for i, port := range svccfg.Ports {
246+
if port.Mode == Mode_INGRESS || port.Mode == "" {
247+
svccfg.Ports[i].Mode = Mode_HOST
248+
svccfg.Ports[i].Published = "" // ignore published port in host mode
249+
svccfg.Ports[i].AppProtocol = "" // ignore app_protocol in host mode
250+
}
251+
}
244252
}
245253
return nil
246254
}

src/testdata/postgres/compose.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ services:
2929
x-defang-postgres:
3030
environment:
3131
- PGPORT=5433
32+
33+
short-ports:
34+
image: postgres
35+
x-defang-postgres:
36+
ports:
37+
- 5432:5432

src/testdata/postgres/compose.yaml.fixup

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@
4747
}
4848
]
4949
},
50+
"short-ports": {
51+
"command": null,
52+
"entrypoint": null,
53+
"image": "postgres",
54+
"networks": {
55+
"default": null
56+
},
57+
"ports": [
58+
{
59+
"mode": "host",
60+
"target": 5432,
61+
"protocol": "tcp"
62+
}
63+
]
64+
},
5065
"with-ext": {
5166
"command": null,
5267
"entrypoint": null,

src/testdata/postgres/compose.yaml.golden

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ services:
2020
networks:
2121
default: null
2222
x-defang-postgres: null
23+
short-ports:
24+
image: postgres
25+
networks:
26+
default: null
27+
ports:
28+
- mode: ingress
29+
target: 5432
30+
published: "5432"
31+
protocol: tcp
32+
x-defang-postgres: null
2333
with-ext:
2434
image: postgres
2535
networks:

src/testdata/postgres/compose.yaml.warnings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
! service "no-ext": stateful service will lose data on restart; use a managed service instead
33
! service "no-ports": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
44
! service "no-ports-override": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
5+
! service "short-ports": ingress port without healthcheck defaults to GET / HTTP/1.1
6+
! service "short-ports": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
57
! service "with-ext": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
68
! service "wrong-image": managed Postgres service should use a postgres image
79
! service "wrong-image": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors

0 commit comments

Comments
 (0)