@@ -920,7 +920,7 @@ func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Reques
920
920
api .knownDevcontainers [dc .WorkspaceFolder ] = dc
921
921
api .asyncWg .Add (1 )
922
922
go func () {
923
- _ = api .recreateDevcontainer (dc , configPath )
923
+ _ = api .createDevcontainer (dc , configPath , true )
924
924
}()
925
925
926
926
api .mu .Unlock ()
@@ -939,17 +939,17 @@ func (api *API) CreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer) error
939
939
api .asyncWg .Add (1 )
940
940
api .mu .Unlock ()
941
941
942
- return api .recreateDevcontainer (dc , dc .ConfigPath )
942
+ return api .createDevcontainer (dc , dc .ConfigPath , false )
943
943
}
944
944
945
- // recreateDevcontainer should run in its own goroutine and is responsible for
945
+ // createDevcontainer should run in its own goroutine and is responsible for
946
946
// recreating a devcontainer based on the provided devcontainer configuration.
947
947
// It updates the devcontainer status and logs the process. The configPath is
948
948
// passed as a parameter for the odd chance that the container being recreated
949
949
// has a different config file than the one stored in the devcontainer state.
950
950
// The devcontainer state must be set to starting and the asyncWg must be
951
951
// incremented before calling this function.
952
- func (api * API ) recreateDevcontainer (dc codersdk.WorkspaceAgentDevcontainer , configPath string ) error {
952
+ func (api * API ) createDevcontainer (dc codersdk.WorkspaceAgentDevcontainer , configPath string , restart bool ) error {
953
953
defer api .asyncWg .Done ()
954
954
955
955
var (
@@ -991,12 +991,17 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
991
991
992
992
logger .Debug (ctx , "starting devcontainer recreation" )
993
993
994
- _ , err = api .dccli .Up (ctx , dc .WorkspaceFolder , configPath , WithUpOutput (infoW , errW ), WithRemoveExistingContainer ())
994
+ upOptions := []DevcontainerCLIUpOptions {WithUpOutput (infoW , errW )}
995
+ if restart {
996
+ upOptions = append (upOptions , WithRemoveExistingContainer ())
997
+ }
998
+
999
+ _ , err = api .dccli .Up (ctx , dc .WorkspaceFolder , configPath , upOptions ... )
995
1000
if err != nil {
996
1001
// No need to log if the API is closing (context canceled), as this
997
1002
// is expected behavior when the API is shutting down.
998
1003
if ! errors .Is (err , context .Canceled ) {
999
- logger .Error (ctx , "devcontainer recreation failed" , slog .Error (err ))
1004
+ logger .Error (ctx , "devcontainer creation failed" , slog .Error (err ))
1000
1005
}
1001
1006
1002
1007
api .mu .Lock ()
@@ -1009,7 +1014,7 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
1009
1014
return xerrors .Errorf ("start devcontainer: %w" , err )
1010
1015
}
1011
1016
1012
- logger .Info (ctx , "devcontainer recreated successfully" )
1017
+ logger .Info (ctx , "devcontainer created successfully" )
1013
1018
1014
1019
api .mu .Lock ()
1015
1020
dc = api .knownDevcontainers [dc .WorkspaceFolder ]
@@ -1032,7 +1037,7 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
1032
1037
// Ensure an immediate refresh to accurately reflect the
1033
1038
// devcontainer state after recreation.
1034
1039
if err := api .RefreshContainers (ctx ); err != nil {
1035
- logger .Error (ctx , "failed to trigger immediate refresh after devcontainer recreation " , slog .Error (err ))
1040
+ logger .Error (ctx , "failed to trigger immediate refresh after devcontainer creation " , slog .Error (err ))
1036
1041
return xerrors .Errorf ("refresh containers: %w" , err )
1037
1042
}
1038
1043
0 commit comments