Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/pkg/cli/compose/fixup.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ func fixupPostgresService(svccfg *composeTypes.ServiceConfig, provider client.Pr
}
term.Debugf("service %q: adding postgres host port %d", svccfg.Name, port)
svccfg.Ports = []composeTypes.ServicePortConfig{{Target: port, Mode: Mode_HOST, Protocol: Protocol_TCP}}
} else {
for i, port := range svccfg.Ports {
if port.Mode == Mode_INGRESS || port.Mode == "" {
svccfg.Ports[i].Mode = Mode_HOST
svccfg.Ports[i].Published = "" // ignore published port in host mode
svccfg.Ports[i].AppProtocol = "" // ignore app_protocol in host mode
}
}
}
return nil
}
Expand Down Expand Up @@ -303,6 +311,14 @@ func fixupRedisService(svccfg *composeTypes.ServiceConfig, provider client.Provi
}
term.Debugf("service %q: adding redis host port %d", svccfg.Name, port)
svccfg.Ports = []composeTypes.ServicePortConfig{{Target: port, Mode: Mode_HOST, Protocol: Protocol_TCP}}
} else {
for i, port := range svccfg.Ports {
if port.Mode == Mode_INGRESS || port.Mode == "" {
svccfg.Ports[i].Mode = Mode_HOST
svccfg.Ports[i].Published = "" // ignore published port in host mode
svccfg.Ports[i].AppProtocol = "" // ignore app_protocol in host mode
}
}
}
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions src/testdata/postgres/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ services:
- target: 5432
mode: host

short-ports:
image: postgres
x-defang-postgres:
ports:
- 5432:5432

no-ext:
image: postgres
ports:
Expand All @@ -29,3 +35,4 @@ services:
x-defang-postgres:
environment:
- PGPORT=5433

15 changes: 15 additions & 0 deletions src/testdata/postgres/compose.yaml.fixup
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@
}
]
},
"short-ports": {
"command": null,
"entrypoint": null,
"image": "postgres",
"networks": {
"default": null
},
"ports": [
{
"mode": "host",
"target": 5432,
"protocol": "tcp"
}
]
},
"with-ext": {
"command": null,
"entrypoint": null,
Expand Down
10 changes: 10 additions & 0 deletions src/testdata/postgres/compose.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ services:
networks:
default: null
x-defang-postgres: null
short-ports:
image: postgres
networks:
default: null
ports:
- mode: ingress
target: 5432
published: "5432"
protocol: tcp
Comment on lines +28 to +31
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lionello should this include the fixup or not?

x-defang-postgres: null
with-ext:
image: postgres
networks:
Expand Down
2 changes: 2 additions & 0 deletions src/testdata/postgres/compose.yaml.warnings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
! service "no-ext": stateful service will lose data on restart; use a managed service instead
! service "no-ports": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "no-ports-override": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "short-ports": ingress port without healthcheck defaults to GET / HTTP/1.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this warning is shown because the fixup happens too late

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaict this test doesn't consider fixup

! service "short-ports": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "with-ext": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "wrong-image": managed Postgres service should use a postgres image
! service "wrong-image": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
6 changes: 6 additions & 0 deletions src/testdata/redis/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ services:
- target: 6379
mode: host

short-ports:
image: redis
x-defang-redis:
ports:
- 6379:6379

no-ext:
image: redis
ports:
Expand Down
15 changes: 15 additions & 0 deletions src/testdata/redis/compose.yaml.fixup
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@
}
]
},
"short-ports": {
"command": null,
"entrypoint": null,
"image": "redis",
"networks": {
"default": null
},
"ports": [
{
"mode": "host",
"target": 6379,
"protocol": "tcp"
}
]
},
"with-ext": {
"command": null,
"entrypoint": null,
Expand Down
10 changes: 10 additions & 0 deletions src/testdata/redis/compose.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ services:
networks:
default: null
x-defang-redis: null
short-ports:
image: redis
networks:
default: null
ports:
- mode: ingress
target: 6379
published: "6379"
protocol: tcp
x-defang-redis: null
with-ext:
image: redis
networks:
Expand Down
2 changes: 2 additions & 0 deletions src/testdata/redis/compose.yaml.warnings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
! service "no-ext": stateful service will lose data on restart; use a managed service instead
! service "no-ports": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "no-ports-override": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "short-ports": ingress port without healthcheck defaults to GET / HTTP/1.1
! service "short-ports": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "with-ext": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "wrong-image": managed Redis service should use a redis image
! service "wrong-image": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
Loading