- Notifications
You must be signed in to change notification settings - Fork1k
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 fromall commits
eb8a469
0dc5bb2
bcd6689
91fd4e7
c273b23
8698100
8ec61b6
ab2e82e
4db77af
d3a2583
20e832a
336997b
0ae2616
e17b228
d1da3a1
c6652a1
File 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 { | ||||||||||||||||||||||||||||||||||||
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 appsWithPossibleDuplicates []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), | ||||||||||||||||||||||||||||||||||||
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 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 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 | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
appsWithPossibleDuplicates = append(appsWithPossibleDuplicates, customization.Apps...) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
@@ -1154,7 +1177,27 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
slices.Sort(displayApps) | ||||||||||||||||||||||||||||||||||||
appSlugs := make(map[string]struct{}) | ||||||||||||||||||||||||||||||||||||
apps := make([]SubAgentApp, 0, len(appsWithPossibleDuplicates)) | ||||||||||||||||||||||||||||||||||||
// We want to deduplicate the apps based on their slugs here. | ||||||||||||||||||||||||||||||||||||
// As we want to prioritize later apps, we will walk through this | ||||||||||||||||||||||||||||||||||||
// backwards. | ||||||||||||||||||||||||||||||||||||
for _, app := range slices.Backward(appsWithPossibleDuplicates) { | ||||||||||||||||||||||||||||||||||||
if _, slugAlreadyExists := appSlugs[app.Slug]; slugAlreadyExists { | ||||||||||||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
appSlugs[app.Slug] = struct{}{} | ||||||||||||||||||||||||||||||||||||
apps = append(apps, app) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||||||||||||||||||||||||||||||||
// Apps is currently in reverse order here, so by reversing it we restore | ||||||||||||||||||||||||||||||||||||
// it to the original order. | ||||||||||||||||||||||||||||||||||||
slices.Reverse(apps) | ||||||||||||||||||||||||||||||||||||
subAgentConfig.DisplayApps = displayApps | ||||||||||||||||||||||||||||||||||||
subAgentConfig.Apps = apps | ||||||||||||||||||||||||||||||||||||
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 |
---|---|---|
@@ -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.