@@ -2051,6 +2051,34 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
2051
2051
}
2052
2052
}
2053
2053
2054
+ var (
2055
+ devcontainers = prAgent .GetDevcontainers ()
2056
+ devcontainerIDs = make ([]uuid.UUID , 0 , len (devcontainers ))
2057
+ devcontainerNames = make ([]string , 0 , len (devcontainers ))
2058
+ devcontainerWorkspaceFolders = make ([]string , 0 , len (devcontainers ))
2059
+ devcontainerConfigPaths = make ([]string , 0 , len (devcontainers ))
2060
+ )
2061
+ if len (devcontainers ) > 0 {
2062
+ for _ , dc := range devcontainers {
2063
+ devcontainerIDs = append (devcontainerIDs , uuid .New ())
2064
+ devcontainerNames = append (devcontainerNames , dc .Name )
2065
+ devcontainerWorkspaceFolders = append (devcontainerWorkspaceFolders , dc .WorkspaceFolder )
2066
+ devcontainerConfigPaths = append (devcontainerConfigPaths , dc .ConfigPath )
2067
+ }
2068
+
2069
+ _ , err = db .InsertWorkspaceAgentDevcontainers (ctx , database.InsertWorkspaceAgentDevcontainersParams {
2070
+ WorkspaceAgentID : agentID ,
2071
+ CreatedAt : dbtime .Now (),
2072
+ ID : devcontainerIDs ,
2073
+ Name : devcontainerNames ,
2074
+ WorkspaceFolder : devcontainerWorkspaceFolders ,
2075
+ ConfigPath : devcontainerConfigPaths ,
2076
+ })
2077
+ if err != nil {
2078
+ return xerrors .Errorf ("insert agent devcontainer: %w" , err )
2079
+ }
2080
+ }
2081
+
2054
2082
logSourceIDs := make ([]uuid.UUID , 0 , len (prAgent .Scripts ))
2055
2083
logSourceDisplayNames := make ([]string , 0 , len (prAgent .Scripts ))
2056
2084
logSourceIcons := make ([]string , 0 , len (prAgent .Scripts ))
@@ -2078,6 +2106,22 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
2078
2106
scriptRunOnStart = append (scriptRunOnStart , script .RunOnStart )
2079
2107
scriptRunOnStop = append (scriptRunOnStop , script .RunOnStop )
2080
2108
}
2109
+ // Add a log source and script for each devcontainer so we can
2110
+ // track logs and timings for each.
2111
+ for _ , id := range devcontainerIDs {
2112
+ logSourceIDs = append (logSourceIDs , uuid .New ())
2113
+ logSourceDisplayNames = append (logSourceDisplayNames , "Dev Container" )
2114
+ logSourceIcons = append (logSourceIcons , "/emojis/1f4e6.png" ) // Emoji package. Or perhaps /icon/container.svg?
2115
+ scriptIDs = append (scriptIDs , id ) // Re-use the devcontainer ID as the script ID for identification.
2116
+ scriptDisplayName = append (scriptDisplayName , "Dev Container" ) // TODO(mafredri): Make it unique? Grab from id used in TF?
2117
+ scriptLogPaths = append (scriptLogPaths , "" )
2118
+ scriptSources = append (scriptSources , "" )
2119
+ scriptCron = append (scriptCron , "" )
2120
+ scriptTimeout = append (scriptTimeout , 0 )
2121
+ scriptStartBlocksLogin = append (scriptStartBlocksLogin , false )
2122
+ scriptRunOnStart = append (scriptRunOnStart , false )
2123
+ scriptRunOnStop = append (scriptRunOnStop , false )
2124
+ }
2081
2125
2082
2126
_ , err = db .InsertWorkspaceAgentLogSources (ctx , database.InsertWorkspaceAgentLogSourcesParams {
2083
2127
WorkspaceAgentID : agentID ,
@@ -2108,33 +2152,6 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
2108
2152
return xerrors .Errorf ("insert agent scripts: %w" , err )
2109
2153
}
2110
2154
2111
- if devcontainers := prAgent .GetDevcontainers (); len (devcontainers ) > 0 {
2112
- var (
2113
- devcontainerIDs = make ([]uuid.UUID , 0 , len (devcontainers ))
2114
- devcontainerNames = make ([]string , 0 , len (devcontainers ))
2115
- devcontainerWorkspaceFolders = make ([]string , 0 , len (devcontainers ))
2116
- devcontainerConfigPaths = make ([]string , 0 , len (devcontainers ))
2117
- )
2118
- for _ , dc := range devcontainers {
2119
- devcontainerIDs = append (devcontainerIDs , uuid .New ())
2120
- devcontainerNames = append (devcontainerNames , dc .Name )
2121
- devcontainerWorkspaceFolders = append (devcontainerWorkspaceFolders , dc .WorkspaceFolder )
2122
- devcontainerConfigPaths = append (devcontainerConfigPaths , dc .ConfigPath )
2123
- }
2124
-
2125
- _ , err = db .InsertWorkspaceAgentDevcontainers (ctx , database.InsertWorkspaceAgentDevcontainersParams {
2126
- WorkspaceAgentID : agentID ,
2127
- CreatedAt : dbtime .Now (),
2128
- ID : devcontainerIDs ,
2129
- Name : devcontainerNames ,
2130
- WorkspaceFolder : devcontainerWorkspaceFolders ,
2131
- ConfigPath : devcontainerConfigPaths ,
2132
- })
2133
- if err != nil {
2134
- return xerrors .Errorf ("insert agent devcontainer: %w" , err )
2135
- }
2136
- }
2137
-
2138
2155
for _ , app := range prAgent .Apps {
2139
2156
// Similar logic is duplicated in terraform/resources.go.
2140
2157
slug := app .Slug
0 commit comments