Skip to content

Commit 37085dc

Browse files
committed
add memory warning
1 parent d5c96bb commit 37085dc

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/pkg/cli/composeStart.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ func ComposeStart(ctx context.Context, client defangv1connect.FabricControllerCl
230230

231231
ports, err := convertPorts(svccfg.Ports)
232232
if err != nil {
233+
// TODO: move this validation up so we don't upload the build context if it's invalid
233234
return nil, &ComposeError{err}
234235
}
235236
// Show a warning when we have ingress ports but no explicit healthcheck
@@ -243,7 +244,7 @@ func ComposeStart(ctx context.Context, client defangv1connect.FabricControllerCl
243244
var deploy *pb.Deploy
244245
if svccfg.Deploy != nil {
245246
deploy = &pb.Deploy{}
246-
deploy.Replicas = 1 // default to one replica per service
247+
deploy.Replicas = 1 // default to one replica per service; allow the user to override this to 0
247248
if svccfg.Deploy.Replicas != nil {
248249
deploy.Replicas = uint32(*svccfg.Deploy.Replicas)
249250
}
@@ -253,9 +254,9 @@ func ComposeStart(ctx context.Context, client defangv1connect.FabricControllerCl
253254
reservations = svccfg.Deploy.Resources.Limits
254255
}
255256
if reservations != nil {
256-
// TODO: move this validation up so we don't upload the build context if it's invalid
257257
cpus, err := strconv.ParseFloat(reservations.NanoCPUs, 32)
258258
if err != nil {
259+
// TODO: move this validation up so we don't upload the build context if it's invalid
259260
return nil, &ComposeError{fmt.Errorf("invalid reservations cpus: %v", err)}
260261
}
261262
var devices []*pb.Device
@@ -276,6 +277,10 @@ func ComposeStart(ctx context.Context, client defangv1connect.FabricControllerCl
276277
}
277278
}
278279

280+
if deploy == nil || deploy.Resources == nil || deploy.Resources.Reservations == nil || deploy.Resources.Reservations.Memory == 0 {
281+
logrus.Warn("missing memory reservation; specify deploy.resources.reservations.memory to avoid out-of-memory errors")
282+
}
283+
279284
// Upload the build context, if any; TODO: parallelize
280285
var build *pb.Build
281286
if svccfg.Build != nil {

src/tests/docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ services:
77
DNS: "${COMPOSE_PROJECT_NAME}-dfnx.prod1.defang.dev"
88
env_file:
99
- fileName.env
10+
# deploy:
11+
# resources:
12+
# limits:
13+
# cpus: '0.50'
14+
# memory: 512M
15+
# reservations:
16+
# cpus: '0.25'
17+
# memory: 256M
1018
ports:
1119
- target: 80
1220
mode: ingress

0 commit comments

Comments
 (0)