Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1048b1

Browse files
committed
use name, print warning
1 parent 304b1a1 commit e1048b1

File tree

3 files changed

+62
-56
lines changed

3 files changed

+62
-56
lines changed

agent/agent.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -1124,21 +1124,21 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11241124
// initialized (git clone, etc).
11251125
postStartScripts []codersdk.WorkspaceAgentScript
11261126
)
1127-
for _, dc := range manifest.Devcontainers {
1128-
// TODO(mafredri): Verify `@devcontainers/cli` presence.
1129-
// TODO(mafredri): Verify workspace folder exists.
1130-
// TODO(mafredri): If set, verify config path exists.
1131-
dc = expandDevcontainerPaths(a.logger, dc)
1132-
1133-
for i, s := range scripts {
1134-
// The devcontainer scripts match the devcontainer ID for
1135-
// identification.
1136-
if s.ID == dc.ID {
1137-
scripts = slices.Delete(scripts, i, i+1)
1138-
if a.experimentalDevcontainersEnabled {
1127+
if a.experimentalDevcontainersEnabled {
1128+
for _, dc := range manifest.Devcontainers {
1129+
// TODO(mafredri): Verify `@devcontainers/cli` presence.
1130+
// TODO(mafredri): Verify workspace folder exists.
1131+
// TODO(mafredri): If set, verify config path exists.
1132+
dc = expandDevcontainerPaths(a.logger, dc)
1133+
1134+
for i, s := range scripts {
1135+
// The devcontainer scripts match the devcontainer ID for
1136+
// identification.
1137+
if s.ID == dc.ID {
1138+
scripts = slices.Delete(scripts, i, i+1)
11391139
postStartScripts = append(postStartScripts, agentcontainers.DevcontainerStartupScript(dc, s))
1140+
break
11401141
}
1141-
break
11421142
}
11431143
}
11441144
}

agent/agentcontainers/devcontainer.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ func DevcontainerStartupScript(dc codersdk.WorkspaceAgentDevcontainer, script co
1111
if dc.ConfigPath != "" {
1212
cmd = fmt.Sprintf("%s --config %q", cmd, dc.ConfigPath)
1313
}
14+
script.RunOnStart = false
1415
script.Script = cmd
1516
return script
1617
}

coderd/provisionerdserver/provisionerdserver.go

+48-43
Original file line numberDiff line numberDiff line change
@@ -2051,34 +2051,6 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
20512051
}
20522052
}
20532053

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-
20822054
logSourceIDs := make([]uuid.UUID, 0, len(prAgent.Scripts))
20832055
logSourceDisplayNames := make([]string, 0, len(prAgent.Scripts))
20842056
logSourceIcons := make([]string, 0, len(prAgent.Scripts))
@@ -2106,21 +2078,54 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
21062078
scriptRunOnStart = append(scriptRunOnStart, script.RunOnStart)
21072079
scriptRunOnStop = append(scriptRunOnStop, script.RunOnStop)
21082080
}
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+
}
21242129
}
21252130

21262131
_, err = db.InsertWorkspaceAgentLogSources(ctx, database.InsertWorkspaceAgentLogSourcesParams{

0 commit comments

Comments
 (0)