-
Notifications
You must be signed in to change notification settings - Fork 224
/
update.go
69 lines (57 loc) · 1.48 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package image
import (
"context"
"fmt"
"github.com/spf13/cobra"
fly "github.com/superfly/fly-go"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/command/apps"
"github.com/superfly/flyctl/internal/flag"
)
func newUpdate() *cobra.Command {
const (
long = `Update the app's image to the latest available version.
The update will perform a rolling restart against each Machine, which may result in a brief service disruption.`
short = "Updates the app's image to the latest available version."
usage = "update"
)
cmd := command.New(usage, short, long, runUpdate,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.NoArgs
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.Yes(),
flag.String{
Name: "image",
Description: "Target a specific image",
},
flag.Bool{
Name: "skip-health-checks",
Description: "Skip waiting for health checks inbetween VM updates. (Machines only)",
Default: false,
},
)
return cmd
}
func runUpdate(ctx context.Context) error {
var (
appName = appconfig.NameFromContext(ctx)
client = fly.ClientFromContext(ctx)
)
app, err := client.GetAppCompact(ctx, appName)
if err != nil {
return fmt.Errorf("get app: %w", err)
}
ctx, err = apps.BuildContext(ctx, app)
if err != nil {
return err
}
if app.IsPostgresApp() {
return updatePostgresOnMachines(ctx, app)
}
return updateImageForMachines(ctx, app)
}