@@ -921,7 +921,7 @@ func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Reques
921
921
api .knownDevcontainers [dc .WorkspaceFolder ] = dc
922
922
api .asyncWg .Add (1 )
923
923
go func () {
924
- _ = api .createDevcontainer (dc , configPath , true )
924
+ _ = api .CreateDevcontainer (dc , configPath , CreateBehaviorRestart )
925
925
}()
926
926
927
927
api .mu .Unlock ()
@@ -932,16 +932,12 @@ func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Reques
932
932
})
933
933
}
934
934
935
- func (api * API ) CreateDevcontainer (dc codersdk.WorkspaceAgentDevcontainer ) error {
936
- api .mu .Lock ()
937
- dc .Status = codersdk .WorkspaceAgentDevcontainerStatusStarting
938
- dc .Container = nil
939
- api .knownDevcontainers [dc .WorkspaceFolder ] = dc
940
- api .asyncWg .Add (1 )
941
- api .mu .Unlock ()
935
+ type CreateBehavior bool
942
936
943
- return api .createDevcontainer (dc , dc .ConfigPath , false )
944
- }
937
+ const (
938
+ CreateBehaviorStart CreateBehavior = false
939
+ CreateBehaviorRestart CreateBehavior = true
940
+ )
945
941
946
942
// createDevcontainer should run in its own goroutine and is responsible for
947
943
// recreating a devcontainer based on the provided devcontainer configuration.
@@ -950,9 +946,18 @@ func (api *API) CreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer) error
950
946
// has a different config file than the one stored in the devcontainer state.
951
947
// The devcontainer state must be set to starting and the asyncWg must be
952
948
// incremented before calling this function.
953
- func (api * API ) createDevcontainer (dc codersdk.WorkspaceAgentDevcontainer , configPath string , restart bool ) error {
949
+ func (api * API ) CreateDevcontainer (dc codersdk.WorkspaceAgentDevcontainer , configPath string , behavior CreateBehavior ) error {
954
950
defer api .asyncWg .Done ()
955
951
952
+ if behavior == CreateBehaviorStart {
953
+ api .mu .Lock ()
954
+ dc .Status = codersdk .WorkspaceAgentDevcontainerStatusStarting
955
+ dc .Container = nil
956
+ api .knownDevcontainers [dc .WorkspaceFolder ] = dc
957
+ api .asyncWg .Add (1 )
958
+ api .mu .Unlock ()
959
+ }
960
+
956
961
var (
957
962
err error
958
963
ctx = api .ctx
@@ -993,7 +998,7 @@ func (api *API) createDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, confi
993
998
logger .Debug (ctx , "starting devcontainer recreation" )
994
999
995
1000
upOptions := []DevcontainerCLIUpOptions {WithUpOutput (infoW , errW )}
996
- if restart {
1001
+ if behavior == CreateBehaviorRestart {
997
1002
upOptions = append (upOptions , WithRemoveExistingContainer ())
998
1003
}
999
1004
0 commit comments