forked from basecamp/once
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.go
More file actions
63 lines (53 loc) · 1.31 KB
/
update.go
File metadata and controls
63 lines (53 loc) · 1.31 KB
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
package command
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/basecamp/once/internal/docker"
"github.com/basecamp/once/internal/version"
)
type updateCommand struct {
cmd *cobra.Command
}
func newUpdateCommand() *updateCommand {
u := &updateCommand{}
u.cmd = &cobra.Command{
Use: "update [app]",
Short: "Update once to the latest version, or update a specific application",
Args: cobra.MaximumNArgs(1),
RunE: WithNamespace(u.run),
}
return u
}
// Private
func (u *updateCommand) run(ctx context.Context, ns *docker.Namespace, cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return version.NewUpdater().UpdateBinary()
}
appName := args[0]
progress := func(p docker.DeployProgress) {
switch p.Stage {
case docker.DeployStageDownloading:
fmt.Printf("Downloading: %d%%\n", p.Percentage)
case docker.DeployStageStarting:
fmt.Println("Starting...")
case docker.DeployStageFinished:
fmt.Println("Finished")
}
}
var changed bool
err := withApplication(ns, appName, "updating", func(app *docker.Application) error {
var err error
changed, err = app.Update(ctx, progress)
return err
})
if err != nil {
return err
}
if changed {
fmt.Printf("Updated %s\n", appName)
} else {
fmt.Printf("%s is already up to date\n", appName)
}
return nil
}