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

Commit050177b

Browse files
committed
add sub agent env and revert container id change
1 parent9afa5ea commit050177b

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

‎agent/agentcontainers/api.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type API struct {
5959
scriptLoggerfunc(logSourceID uuid.UUID)ScriptLogger
6060
subAgentClientSubAgentClient
6161
subAgentURLstring
62+
subAgentEnv []string
6263

6364
mu sync.RWMutex
6465
closedbool
@@ -141,6 +142,13 @@ func WithSubAgentURL(url string) Option {
141142
}
142143
}
143144

145+
// WithSubAgent sets the environment variables for the sub-agent.
146+
funcWithSubAgentEnv(env...string)Option {
147+
returnfunc(api*API) {
148+
api.subAgentEnv=env
149+
}
150+
}
151+
144152
// WithDevcontainers sets the known devcontainers for the API. This
145153
// allows the API to be aware of devcontainers defined in the workspace
146154
// agent manifest.
@@ -1147,12 +1155,14 @@ func (api *API) runSubAgentInContainer(ctx context.Context, dc codersdk.Workspac
11471155

11481156
logger.Info(ctx,"starting subagent in dev container")
11491157

1158+
env:= []string{
1159+
"CODER_AGENT_URL="+api.subAgentURL,
1160+
"CODER_AGENT_TOKEN="+agent.AuthToken.String(),
1161+
}
1162+
env=append(env,api.subAgentEnv...)
11501163
err:=api.dccli.Exec(agentCtx,dc.WorkspaceFolder,dc.ConfigPath,agentPath, []string{"agent"},
11511164
WithExecContainerID(container.ID),
1152-
WithRemoteEnv(
1153-
"CODER_AGENT_URL="+api.subAgentURL,
1154-
"CODER_AGENT_TOKEN="+agent.AuthToken.String(),
1155-
),
1165+
WithRemoteEnv(env...),
11561166
)
11571167
iferr!=nil&&!errors.Is(err,context.Canceled) {
11581168
logger.Error(ctx,"subagent process failed",slog.Error(err))

‎agent/agentcontainers/devcontainercli.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ func WithExecOutput(stdout, stderr io.Writer) DevcontainerCLIExecOptions {
6868
}
6969

7070
// WithExecContainerID sets the container ID to target a specific
71-
// container. Note that this option will unset the workspace folder to
72-
// ensure properties from the container are inherited correctly.
71+
// container.
7372
funcWithExecContainerID(idstring)DevcontainerCLIExecOptions {
7473
returnfunc(o*devcontainerCLIExecConfig) {
75-
o.containerID=id
74+
o.args=append(o.args,"--container-id",id)
7675
}
7776
}
7877

@@ -168,10 +167,12 @@ func (d *devcontainerCLI) Exec(ctx context.Context, workspaceFolder, configPath
168167
logger:=d.logger.With(slog.F("workspace_folder",workspaceFolder),slog.F("config_path",configPath))
169168

170169
args:= []string{"exec"}
171-
switch {
172-
caseconf.containerID!="":
173-
args=append(args,"--container-id",conf.containerID)
174-
caseworkspaceFolder!="":
170+
// For now, always set workspace folder even if --container-id is provided.
171+
// Otherwise the environment of exec will be incomplete, like `pwd` will be
172+
// /home/coder instead of /workspaces/coder. The downside is that the local
173+
// `devcontainer.json` config will overwrite settings serialized in the
174+
// container label.
175+
ifworkspaceFolder!="" {
175176
args=append(args,"--workspace-folder",workspaceFolder)
176177
}
177178
ifconfigPath!="" {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp