mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd): add support for external agents to API's and provisioner (#19286)
This pull request introduces support for external workspace management, allowing users to register and manage workspaces that are provisioned and managed outside of the Coder. Depends on: https://github.com/coder/terraform-provider-coder/pull/424 * GET /api/v2/init-script - Gets the agent initialization script * By default, it returns a script for Linux (amd64), but with query parameters (os and arch) you can get the init script for different platforms * GET /api/v2/workspaces/{workspace}/external-agent/{agent}/credentials - Gets credentials for an external agent **(enterprise)** * Updated queries to filter workspaces/templates by the has_external_agent field
This commit is contained in:
@@ -1733,11 +1733,14 @@ func (s *server) completeTemplateImportJob(ctx context.Context, job database.Pro
|
||||
Bool: jobType.TemplateImport.HasAiTasks,
|
||||
Valid: true,
|
||||
},
|
||||
HasExternalAgent: sql.NullBool{},
|
||||
UpdatedAt: now,
|
||||
HasExternalAgent: sql.NullBool{
|
||||
Bool: jobType.TemplateImport.HasExternalAgents,
|
||||
Valid: true,
|
||||
},
|
||||
UpdatedAt: now,
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("update template version external auth providers: %w", err)
|
||||
return xerrors.Errorf("update template version ai task and external agent: %w", err)
|
||||
}
|
||||
|
||||
// Process terraform values
|
||||
@@ -2027,6 +2030,14 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
|
||||
sidebarAppID = uuid.NullUUID{}
|
||||
}
|
||||
|
||||
hasExternalAgent := false
|
||||
for _, resource := range jobType.WorkspaceBuild.Resources {
|
||||
if resource.Type == "coder_external_agent" {
|
||||
hasExternalAgent = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Regardless of whether there is an AI task or not, update the field to indicate one way or the other since it
|
||||
// always defaults to nil. ONLY if has_ai_task=true MUST ai_task_sidebar_app_id be set.
|
||||
if err := db.UpdateWorkspaceBuildFlagsByID(ctx, database.UpdateWorkspaceBuildFlagsByIDParams{
|
||||
@@ -2035,11 +2046,14 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
|
||||
Bool: hasAITask,
|
||||
Valid: true,
|
||||
},
|
||||
HasExternalAgent: sql.NullBool{},
|
||||
SidebarAppID: sidebarAppID,
|
||||
UpdatedAt: now,
|
||||
HasExternalAgent: sql.NullBool{
|
||||
Bool: hasExternalAgent,
|
||||
Valid: true,
|
||||
},
|
||||
SidebarAppID: sidebarAppID,
|
||||
UpdatedAt: now,
|
||||
}); err != nil {
|
||||
return xerrors.Errorf("update workspace build ai tasks flag: %w", err)
|
||||
return xerrors.Errorf("update workspace build ai tasks and external agent flag: %w", err)
|
||||
}
|
||||
|
||||
// Insert timings inside the transaction now
|
||||
|
||||
Reference in New Issue
Block a user