Skip to content

Commit

Permalink
APPS: Add an --update-sources parameter to create and update app (#1622)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
markusthoemmes authored Dec 4, 2024
1 parent 60e44f9 commit 5c31b5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions commands/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5c31b5e

Please sign in to comment.