-
Notifications
You must be signed in to change notification settings - Fork 61
Allow updating a specific app via once update <app>
#26
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| package command | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/basecamp/once/internal/docker" | ||
| "github.com/basecamp/once/internal/version" | ||
| ) | ||
|
|
||
|
|
@@ -13,12 +17,47 @@ type updateCommand struct { | |
| func newUpdateCommand() *updateCommand { | ||
| u := &updateCommand{} | ||
| u.cmd = &cobra.Command{ | ||
| Use: "update", | ||
| Short: "Update once to the latest version", | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return version.NewUpdater().UpdateBinary() | ||
| }, | ||
| 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) | ||
florentdestremau marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return err | ||
| }) | ||
|
Comment on lines
+38
to
+43
|
||
| 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 | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.