- Notifications
You must be signed in to change notification settings - Fork1.1k
feat(agent/agentcontainers): support apps for dev container agents#18346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from13 commits
eb8a4690dc5bb2bcd668991fd4e7c273b2386981008ec61b6ab2e82e4db77afd3a258320e832a336997b0ae2616e17b228d1da3a1c6652a1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -64,6 +64,9 @@ type API struct { | ||||||||||||||||||||||||||||||||||||
| subAgentURL string | ||||||||||||||||||||||||||||||||||||
| subAgentEnv []string | ||||||||||||||||||||||||||||||||||||
| ownerName string | ||||||||||||||||||||||||||||||||||||
| workspaceName string | ||||||||||||||||||||||||||||||||||||
| mu sync.RWMutex | ||||||||||||||||||||||||||||||||||||
| closed bool | ||||||||||||||||||||||||||||||||||||
| containers codersdk.WorkspaceAgentListContainersResponse // Output from the last list operation. | ||||||||||||||||||||||||||||||||||||
| @@ -153,6 +156,15 @@ func WithSubAgentEnv(env ...string) Option { | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| // WithManifestInfo sets the owner name, and workspace name | ||||||||||||||||||||||||||||||||||||
| // for the sub-agent. | ||||||||||||||||||||||||||||||||||||
| func WithManifestInfo(owner, workspace string) Option { | ||||||||||||||||||||||||||||||||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit: the naming suggests you can pass in the entire manifest? | ||||||||||||||||||||||||||||||||||||
| return func(api *API) { | ||||||||||||||||||||||||||||||||||||
| api.ownerName = owner | ||||||||||||||||||||||||||||||||||||
| api.workspaceName = workspace | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| // WithDevcontainers sets the known devcontainers for the API. This | ||||||||||||||||||||||||||||||||||||
| // allows the API to be aware of devcontainers defined in the workspace | ||||||||||||||||||||||||||||||||||||
| // agent manifest. | ||||||||||||||||||||||||||||||||||||
| @@ -1127,7 +1139,16 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||||||||||||||||||||||||||||||||||||
| codersdk.DisplayAppPortForward: true, | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| var apps []SubAgentApp | ||||||||||||||||||||||||||||||||||||
| if config, err := api.dccli.ReadConfig(ctx, dc.WorkspaceFolder, dc.ConfigPath, | ||||||||||||||||||||||||||||||||||||
| []string{ | ||||||||||||||||||||||||||||||||||||
| fmt.Sprintf("CODER_WORKSPACE_AGENT_NAME=%s", dc.Name), | ||||||||||||||||||||||||||||||||||||
| fmt.Sprintf("CODER_WORKSPACE_OWNER_NAME=%s", api.ownerName), | ||||||||||||||||||||||||||||||||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Can we modify ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Just to ensure I know what you're referring to: In this stanza here? Lines 1293 to 1309 in529fb50
| ||||||||||||||||||||||||||||||||||||
| fmt.Sprintf("CODER_WORKSPACE_NAME=%s", api.workspaceName), | ||||||||||||||||||||||||||||||||||||
| fmt.Sprintf("CODER_URL=%s", api.subAgentURL), | ||||||||||||||||||||||||||||||||||||
Comment on lines +1146 to +1149 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Note for later: we'll need to document these environment variables somewhere. | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| ); err != nil { | ||||||||||||||||||||||||||||||||||||
| api.logger.Error(ctx, "unable to read devcontainer config", slog.Error(err)) | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| coderCustomization := config.MergedConfiguration.Customizations.Coder | ||||||||||||||||||||||||||||||||||||
| @@ -1143,6 +1164,8 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| displayAppsMap[app] = enabled | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| apps = append(apps, customization.Apps...) | ||||||||||||||||||||||||||||||||||||
DanielleMaywood marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| @@ -1155,6 +1178,7 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||||||||||||||||||||||||||||||||||||
| slices.Sort(displayApps) | ||||||||||||||||||||||||||||||||||||
| subAgentConfig.DisplayApps = displayApps | ||||||||||||||||||||||||||||||||||||
| subAgentConfig.Apps = apps | ||||||||||||||||||||||||||||||||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. We should log app creation errors from the response after agent creation too. | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| deleteSubAgent := proc.agent.ID != uuid.Nil && maybeRecreateSubAgent && !proc.agent.EqualConfig(subAgentConfig) | ||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,6 +7,7 @@ import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "io" | ||
| "os" | ||
| "golang.org/x/xerrors" | ||
| @@ -32,13 +33,14 @@ type DevcontainerCustomizations struct { | ||
| type CoderCustomization struct { | ||
| DisplayApps map[codersdk.DisplayApp]bool `json:"displayApps,omitempty"` | ||
| Apps []SubAgentApp `json:"apps,omitempty"` | ||
| } | ||
| // DevcontainerCLI is an interface for the devcontainer CLI. | ||
| type DevcontainerCLI interface { | ||
| Up(ctx context.Context, workspaceFolder, configPath string, opts ...DevcontainerCLIUpOptions) (id string, err error) | ||
| Exec(ctx context.Context, workspaceFolder, configPath string, cmd string, cmdArgs []string, opts ...DevcontainerCLIExecOptions) error | ||
| ReadConfig(ctx context.Context, workspaceFolder, configPath string,env []string,opts ...DevcontainerCLIReadConfigOptions) (DevcontainerConfig, error) | ||
| } | ||
| // DevcontainerCLIUpOptions are options for the devcontainer CLI Up | ||
| @@ -113,8 +115,8 @@ type devcontainerCLIReadConfigConfig struct { | ||
| stderr io.Writer | ||
| } | ||
| //WithReadConfigOutput sets additional stdout and stderr writers for logs | ||
| // duringReadConfig operations. | ||
| func WithReadConfigOutput(stdout, stderr io.Writer) DevcontainerCLIReadConfigOptions { | ||
| return func(o *devcontainerCLIReadConfigConfig) { | ||
| o.stdout = stdout | ||
| @@ -250,7 +252,7 @@ func (d *devcontainerCLI) Exec(ctx context.Context, workspaceFolder, configPath | ||
| return nil | ||
| } | ||
| func (d *devcontainerCLI) ReadConfig(ctx context.Context, workspaceFolder, configPath string,env []string,opts ...DevcontainerCLIReadConfigOptions) (DevcontainerConfig, error) { | ||
| conf := applyDevcontainerCLIReadConfigOptions(opts) | ||
| logger := d.logger.With(slog.F("workspace_folder", workspaceFolder), slog.F("config_path", configPath)) | ||
| @@ -263,6 +265,8 @@ func (d *devcontainerCLI) ReadConfig(ctx context.Context, workspaceFolder, confi | ||
| } | ||
| c := d.execer.CommandContext(ctx, "devcontainer", args...) | ||
| c.Env = append(c.Env, os.Environ()...) | ||
DanielleMaywood marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| c.Env = append(c.Env, env...) | ||
| var stdoutBuf bytes.Buffer | ||
| stdoutWriters := []io.Writer{&stdoutBuf, &devcontainerCLILogWriter{ctx: ctx, logger: logger.With(slog.F("stdout", true))}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -316,7 +316,7 @@ func TestDevcontainerCLI_ArgsAndParsing(t *testing.T) { | ||
| } | ||
| dccli := agentcontainers.NewDevcontainerCLI(logger, testExecer) | ||
| config, err := dccli.ReadConfig(ctx, tt.workspaceFolder, tt.configPath,[]string{},tt.opts...) | ||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if tt.wantError { | ||
| assert.Error(t, err, "want error") | ||
| assert.Equal(t, agentcontainers.DevcontainerConfig{}, config, "expected empty config on error") | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.