Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ee2668

Browse files
authored
fix(agent): fix script filtering for devcontainers (#18635)
1 parent59a6541 commit8ee2668

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

‎agent/agent.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,15 +1158,13 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11581158
}
11591159
}
11601160

1161-
var (
1162-
scripts=manifest.Scripts
1163-
scriptRunnerOpts []agentscripts.InitOption
1164-
devcontainerScriptsmap[uuid.UUID]codersdk.WorkspaceAgentScript
1165-
)
1161+
scripts:=manifest.Scripts
11661162
ifa.containerAPI!=nil {
1167-
scripts,devcontainerScripts=agentcontainers.ExtractDevcontainerScripts(manifest.Devcontainers,scripts)
1163+
// Since devcontainer are enabled, remove devcontainer scripts
1164+
// from the main scripts list to avoid showing an error.
1165+
scripts,_=agentcontainers.ExtractDevcontainerScripts(manifest.Devcontainers,manifest.Scripts)
11681166
}
1169-
err=a.scriptRunner.Init(scripts,aAPI.ScriptCompleted,scriptRunnerOpts...)
1167+
err=a.scriptRunner.Init(scripts,aAPI.ScriptCompleted)
11701168
iferr!=nil {
11711169
returnxerrors.Errorf("init script runner: %w",err)
11721170
}
@@ -1187,10 +1185,11 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11871185
ifa.containerAPI!=nil {
11881186
a.containerAPI.Init(
11891187
agentcontainers.WithManifestInfo(manifest.OwnerName,manifest.WorkspaceName,manifest.AgentName),
1190-
agentcontainers.WithDevcontainers(manifest.Devcontainers,scripts),
1188+
agentcontainers.WithDevcontainers(manifest.Devcontainers,manifest.Scripts),
11911189
agentcontainers.WithSubAgentClient(agentcontainers.NewSubAgentClientFromAPI(a.logger,aAPI)),
11921190
)
11931191

1192+
_,devcontainerScripts:=agentcontainers.ExtractDevcontainerScripts(manifest.Devcontainers,manifest.Scripts)
11941193
for_,dc:=rangemanifest.Devcontainers {
11951194
cErr:=a.createDevcontainer(ctx,aAPI,dc,devcontainerScripts[dc.ID])
11961195
err=errors.Join(err,cErr)

‎agent/agentcontainers/api.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,14 @@ type API struct {
7979
containersErrerror// Error from the last list operation.
8080
devcontainerNamesmap[string]bool// By devcontainer name.
8181
knownDevcontainersmap[string]codersdk.WorkspaceAgentDevcontainer// By workspace folder.
82+
devcontainerLogSourceIDsmap[string]uuid.UUID// By workspace folder.
8283
configFileModifiedTimesmap[string]time.Time// By config file path.
8384
recreateSuccessTimesmap[string]time.Time// By workspace folder.
8485
recreateErrorTimesmap[string]time.Time// By workspace folder.
8586
injectedSubAgentProcsmap[string]subAgentProcess// By workspace folder.
8687
usingWorkspaceFolderNamemap[string]bool// By workspace folder.
8788
ignoredDevcontainersmap[string]bool// By workspace folder. Tracks three states (true, false and not checked).
8889
asyncWg sync.WaitGroup
89-
90-
devcontainerLogSourceIDsmap[string]uuid.UUID// By workspace folder.
9190
}
9291

9392
typesubAgentProcessstruct {
@@ -935,12 +934,7 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
935934
returnxerrors.Errorf("devcontainer not found")
936935
}
937936

938-
api.asyncWg.Add(1)
939-
deferapi.asyncWg.Done()
940-
api.mu.Unlock()
941-
942937
var (
943-
errerror
944938
ctx=api.ctx
945939
logger=api.logger.With(
946940
slog.F("devcontainer_id",dc.ID),
@@ -950,19 +944,23 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
950944
)
951945
)
952946

953-
ifdc.ConfigPath!=configPath {
954-
logger.Warn(ctx,"devcontainer config path mismatch",
955-
slog.F("config_path_param",configPath),
956-
)
957-
}
958-
959947
// Send logs via agent logging facilities.
960948
logSourceID:=api.devcontainerLogSourceIDs[dc.WorkspaceFolder]
961949
iflogSourceID==uuid.Nil {
962-
// Fallback to the externallog source IDifnot found.
950+
api.logger.Debug(api.ctx,"devcontainerlog source ID not found, falling back to external log source ID")
963951
logSourceID=agentsdk.ExternalLogSourceID
964952
}
965953

954+
api.asyncWg.Add(1)
955+
deferapi.asyncWg.Done()
956+
api.mu.Unlock()
957+
958+
ifdc.ConfigPath!=configPath {
959+
logger.Warn(ctx,"devcontainer config path mismatch",
960+
slog.F("config_path_param",configPath),
961+
)
962+
}
963+
966964
scriptLogger:=api.scriptLogger(logSourceID)
967965
deferfunc() {
968966
flushCtx,cancel:=context.WithTimeout(api.ctx,5*time.Second)
@@ -981,7 +979,7 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
981979
upOptions:= []DevcontainerCLIUpOptions{WithUpOutput(infoW,errW)}
982980
upOptions=append(upOptions,opts...)
983981

984-
_,err=api.dccli.Up(ctx,dc.WorkspaceFolder,configPath,upOptions...)
982+
_,err:=api.dccli.Up(ctx,dc.WorkspaceFolder,configPath,upOptions...)
985983
iferr!=nil {
986984
// No need to log if the API is closing (context canceled), as this
987985
// is expected behavior when the API is shutting down.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp