Skip to content

Commit

Permalink
print some logs while the deployment is running showing how it is pro…
Browse files Browse the repository at this point in the history
…gressing
  • Loading branch information
tvdfly authored and dangra committed Jan 25, 2023
1 parent 41881a9 commit 2d0159b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 10 additions & 6 deletions internal/command/deploy/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/Khan/genqlient/graphql"
"github.com/jpillora/backoff"
"github.com/logrusorgru/aurora"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/flaps"
Expand All @@ -21,6 +22,7 @@ import (
"github.com/superfly/flyctl/internal/prompt"
"github.com/superfly/flyctl/internal/render"
"github.com/superfly/flyctl/internal/spinner"
"github.com/superfly/flyctl/internal/watch"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/terminal"
)
Expand Down Expand Up @@ -465,19 +467,17 @@ func (md *machineDeployment) DeployMachinesApp(ctx context.Context) (err error)
Region: regionCode,
}

msg := fmt.Sprintf("Deploying with %s strategy", md.strategy)
spin := spinner.Run(io, msg)
// FIXME: set success/failure based on deployment result
defer spin.StopWithSuccess()

if !md.machineSet.IsEmpty() {

err := md.machineSet.AcquireLeases(ctx, 120*time.Second)
// FIXME: should this use context.Background() or context.TODO(), since we want it to try even on CTRL+C?
defer md.machineSet.ReleaseLeases(ctx)
if err != nil {
return err
}

fmt.Fprintf(io.Out, "Deploying %s app with %s strategy\n", aurora.Bold(md.app.Name), md.strategy)

// FIXME: handle deploy strategy: rolling, immediate, canary, bluegreen

for _, m := range md.machineSet.GetMachines() {
Expand Down Expand Up @@ -521,6 +521,7 @@ func (md *machineDeployment) DeployMachinesApp(ctx context.Context) (err error)
launchInput.Config.Mounts = machine.Config.Mounts
}

fmt.Fprintf(io.ErrOut, " Updating %s\n", aurora.Bold(m.Machine().ID))
err := m.Update(ctx, launchInput)
if err != nil {
if md.strategy != "immediate" {
Expand All @@ -538,13 +539,16 @@ func (md *machineDeployment) DeployMachinesApp(ctx context.Context) (err error)
}

if md.strategy != "immediate" && !md.skipHealthChecks {
err := m.WaitForHealthchecksToPass(ctx, 120*time.Second)
err := watch.MachinesChecks(ctx, []*api.Machine{m.Machine()})
// FIXME: combine this wait with the wait for start as one update line (or two per in noninteractive case)
if err != nil {
return err
}
}
}

fmt.Fprintf(io.ErrOut, " Finished deploying\n")

} else {
fmt.Fprintf(io.Out, "Launching VM with image %s\n", launchInput.Config.Image)
_, err = md.flapsClient.Launch(ctx, launchInput)
Expand Down
14 changes: 5 additions & 9 deletions internal/command/machine/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func determineServices(ctx context.Context) ([]api.MachineService, error) {
return machineServices, nil
}

func parsePorts(input string) (port, start_port, end_port *int32, internal_port int, err error) {
func parsePorts(input string) (port, start_port, end_port *int, internal_port int, err error) {
split := strings.Split(input, ":")
if len(split) == 1 {
var external_port int
Expand All @@ -517,8 +517,7 @@ func parsePorts(input string) (port, start_port, end_port *int32, internal_port
return
}

p := int32(external_port)
port = &p
port = api.IntPointer(external_port)
} else if len(split) == 2 {
internal_port, err = strconv.Atoi(split[1])
if err != nil {
Expand All @@ -535,8 +534,7 @@ func parsePorts(input string) (port, start_port, end_port *int32, internal_port
return
}

p := int32(external_port)
port = &p
port = api.IntPointer(external_port)
} else if len(external_split) == 2 {
var start int
start, err = strconv.Atoi(external_split[0])
Expand All @@ -545,8 +543,7 @@ func parsePorts(input string) (port, start_port, end_port *int32, internal_port
return
}

s := int32(start)
start_port = &s
start_port = api.IntPointer(start)

var end int
end, err = strconv.Atoi(external_split[0])
Expand All @@ -555,8 +552,7 @@ func parsePorts(input string) (port, start_port, end_port *int32, internal_port
return
}

e := int32(end)
end_port = &e
end_port = api.IntPointer(end)
} else {
err = errors.New("external port must be at most 2 elements (port, or range start-end)")
}
Expand Down

0 comments on commit 2d0159b

Please sign in to comment.