From 5c31b5ed0a38a94ba8e0316ee92969969f388182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Th=C3=B6mmes?= Date: Wed, 4 Dec 2024 17:54:39 +0100 Subject: [PATCH] APPS: Add an --update-sources parameter to create and update app (#1622) This adds a parameter named `--update-sources` to the `apps create` and `apps update` commands. If set, the respective update of the app spec also causes the underlying sources to be reevaluated and their respective latest state to be reflected in the created deployment. On the `apps create` flow, this only applies to `--upsert` cases. --- args.go | 2 ++ commands/apps.go | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/args.go b/args.go index 32c562728..3eb6a684c 100644 --- a/args.go +++ b/args.go @@ -126,6 +126,8 @@ const ( ArgSurgeUpgrade = "surge-upgrade" // ArgCommandUpsert is an upsert for a resource to be created or updated argument. ArgCommandUpsert = "upsert" + // ArgCommandUpdateSources tells the respective operation to also update the underlying sources. + ArgCommandUpdateSources = "update-sources" // ArgCommandWait is a wait for a resource to be created argument. ArgCommandWait = "wait" // ArgSetCurrentContext is a flag to set the new kubeconfig context as current. diff --git a/commands/apps.go b/commands/apps.go index 99248c47a..6489f6bc6 100644 --- a/commands/apps.go +++ b/commands/apps.go @@ -67,6 +67,7 @@ func Apps() *Command { AddBoolFlag(create, doctl.ArgCommandWait, "", false, "Boolean that specifies whether to wait for an app to complete before returning control to the terminal") AddBoolFlag(create, doctl.ArgCommandUpsert, "", false, "Boolean that specifies whether the app should be updated if it already exists") + AddBoolFlag(create, doctl.ArgCommandUpdateSources, "", false, "Boolean that specifies whether, on update, the app should also update its source code") AddStringFlag(create, doctl.ArgProjectID, "", "", "The ID of the project to assign the created app and resources to. If not provided, the default project will be used.") create.Example = `The following example creates an app in a project named ` + "`" + `example-project` + "`" + ` using an app spec located in a directory called ` + "`" + `/src/your-app.yaml` + "`" + `. Additionally, the command returns the new app's ID, ingress information, and creation date: doctl apps create --spec src/your-app.yaml --format ID,DefaultIngress,Created` @@ -109,6 +110,7 @@ Only basic information is included with the text output format. For complete app displayerType(&displayers.Apps{}), ) AddStringFlag(update, doctl.ArgAppSpec, "", "", `Path to an app spec in JSON or YAML format. Set to "-" to read from stdin.`, requiredOpt()) + AddBoolFlag(update, doctl.ArgCommandUpdateSources, "", false, "Boolean that specifies whether the app should also update its source code") AddBoolFlag(update, doctl.ArgCommandWait, "", false, "Boolean that specifies whether to wait for an app to complete updating before allowing further terminal input. This can be helpful for scripting.") update.Example = `The following example updates an app with the ID ` + "`" + `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` + "`" + ` using an app spec located in a directory called ` + "`" + `/src/your-app.yaml` + "`" + `. Additionally, the command returns the updated app's ID, ingress information, and creation date: doctl apps update f81d4fae-7dec-11d0-a765-00a0c91e6bf6 --spec src/your-app.yaml --format ID,DefaultIngress,Created` @@ -326,6 +328,11 @@ func RunAppsCreate(c *CmdConfig) error { return err } + updateSources, err := c.Doit.GetBool(c.NS, doctl.ArgCommandUpdateSources) + if err != nil { + return err + } + projectID, err := c.Doit.GetString(c.NS, doctl.ArgProjectID) if err != nil { return err @@ -346,7 +353,7 @@ func RunAppsCreate(c *CmdConfig) error { return err } - app, err = c.Apps().Update(id, &godo.AppUpdateRequest{Spec: appSpec}) + app, err = c.Apps().Update(id, &godo.AppUpdateRequest{Spec: appSpec, UpdateAllSourceVersions: updateSources}) if err != nil { return err } @@ -423,12 +430,17 @@ func RunAppsUpdate(c *CmdConfig) error { return err } + updateSources, err := c.Doit.GetBool(c.NS, doctl.ArgCommandUpdateSources) + if err != nil { + return err + } + appSpec, err := apps.ReadAppSpec(os.Stdin, specPath) if err != nil { return err } - app, err := c.Apps().Update(id, &godo.AppUpdateRequest{Spec: appSpec}) + app, err := c.Apps().Update(id, &godo.AppUpdateRequest{Spec: appSpec, UpdateAllSourceVersions: updateSources}) if err != nil { return err }