@@ -2051,34 +2051,6 @@ 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
-
2082
2054
logSourceIDs := make ([]uuid.UUID , 0 , len (prAgent .Scripts ))
2083
2055
logSourceDisplayNames := make ([]string , 0 , len (prAgent .Scripts ))
2084
2056
logSourceIcons := make ([]string , 0 , len (prAgent .Scripts ))
@@ -2106,21 +2078,54 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
2106
2078
scriptRunOnStart = append (scriptRunOnStart , script .RunOnStart )
2107
2079
scriptRunOnStop = append (scriptRunOnStop , script .RunOnStop )
2108
2080
}
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 )
2081
+
2082
+ // Dev Containers require a script and log/source, so we do this before
2083
+ // the logs insert below.
2084
+ if devcontainers := prAgent .GetDevcontainers (); len (devcontainers ) > 0 {
2085
+ var (
2086
+ devcontainerIDs = make ([]uuid.UUID , 0 , len (devcontainers ))
2087
+ devcontainerNames = make ([]string , 0 , len (devcontainers ))
2088
+ devcontainerWorkspaceFolders = make ([]string , 0 , len (devcontainers ))
2089
+ devcontainerConfigPaths = make ([]string , 0 , len (devcontainers ))
2090
+ )
2091
+ for _ , dc := range devcontainers {
2092
+ id := uuid .New ()
2093
+ devcontainerIDs = append (devcontainerIDs , id )
2094
+ devcontainerNames = append (devcontainerNames , dc .Name )
2095
+ devcontainerWorkspaceFolders = append (devcontainerWorkspaceFolders , dc .WorkspaceFolder )
2096
+ devcontainerConfigPaths = append (devcontainerConfigPaths , dc .ConfigPath )
2097
+
2098
+ // Add a log source and script for each devcontainer so we can
2099
+ // track logs and timings for each devcontainer.
2100
+ displayName := fmt .Sprintf ("Dev Container (%s)" , dc .Name )
2101
+ logSourceIDs = append (logSourceIDs , uuid .New ())
2102
+ logSourceDisplayNames = append (logSourceDisplayNames , displayName )
2103
+ logSourceIcons = append (logSourceIcons , "/emojis/1f4e6.png" ) // Emoji package. Or perhaps /icon/container.svg?
2104
+ scriptIDs = append (scriptIDs , id ) // Re-use the devcontainer ID as the script ID for identification.
2105
+ scriptDisplayName = append (scriptDisplayName , displayName )
2106
+ scriptLogPaths = append (scriptLogPaths , "" )
2107
+ scriptSources = append (scriptSources , `echo "WARNING: Dev Containers are early access. If you're seeing this message then Dev Containers haven't been enabled for your workspace yet. To enable, the agent needs to run with the environment variable CODER_AGENT_DEVCONTAINERS_ENABLE=true set."` )
2108
+ scriptCron = append (scriptCron , "" )
2109
+ scriptTimeout = append (scriptTimeout , 0 )
2110
+ scriptStartBlocksLogin = append (scriptStartBlocksLogin , false )
2111
+ // Run on start to surface the warning message in case the
2112
+ // terraform resource is used, but the experiment hasn't
2113
+ // been enabled.
2114
+ scriptRunOnStart = append (scriptRunOnStart , true )
2115
+ scriptRunOnStop = append (scriptRunOnStop , false )
2116
+ }
2117
+
2118
+ _ , err = db .InsertWorkspaceAgentDevcontainers (ctx , database.InsertWorkspaceAgentDevcontainersParams {
2119
+ WorkspaceAgentID : agentID ,
2120
+ CreatedAt : dbtime .Now (),
2121
+ ID : devcontainerIDs ,
2122
+ Name : devcontainerNames ,
2123
+ WorkspaceFolder : devcontainerWorkspaceFolders ,
2124
+ ConfigPath : devcontainerConfigPaths ,
2125
+ })
2126
+ if err != nil {
2127
+ return xerrors .Errorf ("insert agent devcontainer: %w" , err )
2128
+ }
2124
2129
}
2125
2130
2126
2131
_ , err = db .InsertWorkspaceAgentLogSources (ctx , database.InsertWorkspaceAgentLogSourcesParams {
0 commit comments