mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix!: stop workspace before update (#18425)
Fixes https://github.com/coder/coder/issues/17840 NOTE: calling this out as a breaking change so that it is highly visible in the changelog. * CLI: Modifies `coder update` to stop the workspace if already running. * UI: Modifies "update" button to always stop the workspace if already running.
This commit is contained in:
+16
-1
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/v2/cli/cliui"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/serpent"
|
||||
)
|
||||
@@ -18,7 +19,7 @@ func (r *RootCmd) update() *serpent.Command {
|
||||
cmd := &serpent.Command{
|
||||
Annotations: workspaceCommand,
|
||||
Use: "update <workspace>",
|
||||
Short: "Will update and start a given workspace if it is out of date",
|
||||
Short: "Will update and start a given workspace if it is out of date. If the workspace is already running, it will be stopped first.",
|
||||
Long: "Use --always-prompt to change the parameter values of the workspace.",
|
||||
Middleware: serpent.Chain(
|
||||
serpent.RequireNArgs(1),
|
||||
@@ -34,6 +35,20 @@ func (r *RootCmd) update() *serpent.Command {
|
||||
return nil
|
||||
}
|
||||
|
||||
// #17840: If the workspace is already running, we will stop it before
|
||||
// updating. Simply performing a new start transition may not work if the
|
||||
// template specifies ignore_changes.
|
||||
if workspace.LatestBuild.Transition == codersdk.WorkspaceTransitionStart {
|
||||
build, err := stopWorkspace(inv, client, workspace, bflags)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("stop workspace: %w", err)
|
||||
}
|
||||
// Wait for the stop to complete.
|
||||
if err := cliui.WorkspaceBuild(inv.Context(), inv.Stdout, client, build.ID); err != nil {
|
||||
return xerrors.Errorf("wait for stop: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
build, err := startWorkspace(inv, client, workspace, parameterFlags, bflags, WorkspaceUpdate)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("start workspace: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user