Skip to content

Commit

Permalink
Default newly launched applications to auto suspend
Browse files Browse the repository at this point in the history
Continue to default applications to auto stop if:
  * a GPU is present
  * more than 2G of RAM is requested
  • Loading branch information
rubys committed Nov 17, 2024
1 parent cafc23d commit 387423e
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions internal/command/launch/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"path/filepath"
"strings"

"github.com/docker/go-units"
fly "github.com/superfly/fly-go"
"github.com/superfly/fly-go/flaps"
"github.com/superfly/flyctl/helpers"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command/launch/plan"
"github.com/superfly/flyctl/internal/flag"
Expand Down Expand Up @@ -169,12 +171,34 @@ func (state *launchState) updateConfig(ctx context.Context) {
if state.env != nil {
state.appConfig.SetEnvVariables(state.env)
}

state.appConfig.Compute = state.Plan.Compute

if state.Plan.HttpServicePort != 0 {
// default to autostop: suspend
autostop := fly.MachineAutostopSuspend

// if any compute has a GPU or more than 2GB of memory, set autostop to stop
for _, compute := range state.appConfig.Compute {
if compute.GPUKind != "" {
autostop = fly.MachineAutostopStop
break
}

if compute.Memory != "" {
mb, err := helpers.ParseSize(compute.Memory, units.RAMInBytes, units.MiB)
if err != nil || mb >= 2048 {
autostop = fly.MachineAutostopStop
break
}
}
}

if state.appConfig.HTTPService == nil {
state.appConfig.HTTPService = &appconfig.HTTPService{
ForceHTTPS: true,
AutoStartMachines: fly.Pointer(true),
AutoStopMachines: fly.Pointer(fly.MachineAutostopStop),
AutoStopMachines: fly.Pointer(autostop),
MinMachinesRunning: fly.Pointer(0),
Processes: []string{"app"},
}
Expand All @@ -183,7 +207,6 @@ func (state *launchState) updateConfig(ctx context.Context) {
} else {
state.appConfig.HTTPService = nil
}
state.appConfig.Compute = state.Plan.Compute
}

// createApp creates the fly.io app for the plan
Expand Down

0 comments on commit 387423e

Please sign in to comment.