Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions src/pkg/cli/compose/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func TestValidationAndConvert(t *testing.T) {
t.Fatal(err)
}

if err := FixupServices(context.Background(), mockClient, project, UploadModeIgnore); err != nil {
t.Logf("Service conversion failed: %v", err)
logs.WriteString(err.Error() + "\n")
}

if err := ValidateProjectConfig(context.Background(), project, listConfigNamesFunc); err != nil {
t.Logf("Project config validation failed: %v", err)
logs.WriteString(err.Error() + "\n")
Expand All @@ -56,11 +61,6 @@ func TestValidationAndConvert(t *testing.T) {
logs.WriteString(err.Error() + "\n")
}

if err := FixupServices(context.Background(), mockClient, project, UploadModeIgnore); err != nil {
t.Logf("Service conversion failed: %v", err)
logs.WriteString(err.Error() + "\n")
}

// The order of the services is not guaranteed, so we sort the logs before comparing
logLines := strings.SplitAfter(logs.String(), "\n")
slices.Sort(logLines)
Expand Down
8 changes: 4 additions & 4 deletions src/pkg/cli/composeUp.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ func ComposeUp(ctx context.Context, project *compose.Project, fabric client.Fabr
}
}

if err := compose.ValidateProject(project); err != nil {
return nil, project, &ComposeError{err}
}

// Create a new project with only the necessary resources.
// Do not modify the original project, because the caller needs it for debugging.
fixedProject := project.WithoutUnnecessaryResources()
Expand All @@ -59,6 +55,10 @@ func ComposeUp(ctx context.Context, project *compose.Project, fabric client.Fabr
return nil, project, err
}

if err := compose.ValidateProject(project); err != nil {
return nil, project, &ComposeError{err}
}

bytes, err := fixedProject.MarshalYAML()
if err != nil {
return nil, project, err
Expand Down
2 changes: 2 additions & 0 deletions src/testdata/models/compose.yaml.warnings
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
! service "ai_model": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "app": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "my_model": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "withendpoint": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
2 changes: 0 additions & 2 deletions src/testdata/ports/compose.yaml.warnings
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@
! service "short": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "short-published": ingress port without healthcheck defaults to GET / HTTP/1.1
! service "short-published": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "short-udp": ingress port without healthcheck defaults to GET / HTTP/1.1
! service "short-udp": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
! service "short-udp-published": ingress port without healthcheck defaults to GET / HTTP/1.1
! service "short-udp-published": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
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
1 change: 1 addition & 0 deletions src/testdata/postgres/compose.yaml.warnings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
! 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": 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
1 change: 1 addition & 0 deletions src/testdata/redis/compose.yaml.warnings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
! 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": 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