Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default newly launched applications to auto suspend #4067

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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.MachineGuest != nil && compute.MachineGuest.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
Loading