Skip to content

Commit

Permalink
Merge pull request superfly#1545 from superfly/fly-machine-checks
Browse files Browse the repository at this point in the history
fly machine run/update hook into health checks if present
  • Loading branch information
rugwirobaker authored Jan 11, 2023
2 parents ebd92e6 + 247f21e commit f036e03
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
22 changes: 17 additions & 5 deletions internal/command/machine/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import (
mach "github.com/superfly/flyctl/internal/machine"
"github.com/superfly/flyctl/internal/prompt"
"github.com/superfly/flyctl/internal/state"
"github.com/superfly/flyctl/internal/watch"
)

var sharedFlags = flag.Set{
flag.App(),
flag.AppConfig(),
flag.Detach(),
flag.StringSlice{
Name: "port",
Shorthand: "p",
Expand Down Expand Up @@ -164,11 +166,12 @@ func newRun() *cobra.Command {

func runMachineRun(ctx context.Context) error {
var (
appName = app.NameFromContext(ctx)
client = client.FromContext(ctx).API()
io = iostreams.FromContext(ctx)
err error
app *api.AppCompact
appName = app.NameFromContext(ctx)
client = client.FromContext(ctx).API()
io = iostreams.FromContext(ctx)
colorize = io.ColorScheme()
err error
app *api.AppCompact
)

if appName == "" {
Expand Down Expand Up @@ -247,6 +250,15 @@ func runMachineRun(ctx context.Context) error {
return err
}

if !flag.GetDetach(ctx) {
fmt.Fprintln(io.Out, colorize.Green("==> "+"Monitoring health checks"))

if err := watch.MachinesChecks(ctx, []*api.Machine{machine}); err != nil {
return err
}
fmt.Fprintln(io.Out)
}

fmt.Fprintf(io.Out, "Machine started, you can connect via the following private ip\n")
fmt.Fprintf(io.Out, " %s\n", privateIP)

Expand Down
17 changes: 14 additions & 3 deletions internal/command/machine/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/superfly/flyctl/internal/command/apps"
"github.com/superfly/flyctl/internal/flag"
mach "github.com/superfly/flyctl/internal/machine"
"github.com/superfly/flyctl/internal/watch"
)

func newUpdate() *cobra.Command {
Expand Down Expand Up @@ -50,9 +51,10 @@ func newUpdate() *cobra.Command {

func runUpdate(ctx context.Context) (err error) {
var (
appName = app.NameFromContext(ctx)
io = iostreams.FromContext(ctx)
client = client.FromContext(ctx).API()
appName = app.NameFromContext(ctx)
io = iostreams.FromContext(ctx)
colorize = io.ColorScheme()
client = client.FromContext(ctx).API()

machineID = flag.FirstArg(ctx)
autoConfirm = flag.GetBool(ctx, "yes")
Expand Down Expand Up @@ -124,6 +126,15 @@ func runUpdate(ctx context.Context) (err error) {
return err
}

if !flag.GetDetach(ctx) {
fmt.Fprintln(io.Out, colorize.Green("==> "+"Monitoring health checks"))

if err := watch.MachinesChecks(ctx, []*api.Machine{machine}); err != nil {
return err
}
fmt.Fprintln(io.Out)
}

fmt.Fprintf(io.Out, "\nMonitor machine status here:\nhttps://fly.io/apps/%s/machines/%s\n", app.Name, machine.ID)

return nil
Expand Down

0 comments on commit f036e03

Please sign in to comment.