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

chore: pull in cherry picks for v2.24#18674

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

Merged
stirby merged 33 commits intorelease/2.24fromcherry-picks-2.24
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
33 commits
Select commitHold shift + click to select a range
73ffb71
chore: remove chats experiment (#18535)
dannykoppingJun 25, 2025
cc51308
feat: allow new immutable parameters for existing workspaces (#18579)
EmyrkJun 25, 2025
fac6263
chore: upgrade aisdk-go lib, remove vestigial code (#18577)
dannykoppingJun 25, 2025
4c938c0
refactor: remove beta label from 'select a preset' menu (#18538)
BrunoQuaresmaJun 25, 2025
19d8a40
fix: hide the preset parameter visibility switch when it has no effec…
SasSwartJun 26, 2025
a4a5892
feat: graduate prebuilds to general availability (#18607)
SasSwartJun 26, 2025
8e6417a
fix(agent): start devcontainers through agentcontainers package (#18471)
DanielleMaywoodJun 25, 2025
63b619c
fix(agent/agentcontainers): filter out "is test run" devcontainers (#…
mafredriJun 25, 2025
03d1570
feat(agent/agentcontainers): add feature options as envs (#18576)
mafredriJun 25, 2025
5be5bf3
fix(coderd/agentapi): make sub agent slugs more unique (#18581)
DanielleMaywoodJun 25, 2025
cf6d208
feat(agent/agentcontainers): add more envs to readconfig for app URL …
mafredriJun 26, 2025
226aec1
fix!: use devcontainer ID when rebuilding a devcontainer (#18604)
DanielleMaywoodJun 26, 2025
766fc4c
fix(agent/agentcontainers): chown coder binary (#18611)
DanielleMaywoodJun 26, 2025
07d749c
fix(agent/agentcontainers): stop logging empty lines (#18605)
DanielleMaywoodJun 26, 2025
aab5059
chore: parse app status link (#18439)
code-asherJun 26, 2025
cbc97de
fix(agent): delay containerAPI init to ensure startup scripts run bef…
mafredriJun 27, 2025
5058d1b
feat: add task link in the workspace page when it is running a task (…
BrunoQuaresmaJun 27, 2025
b7c7d1a
refactor: move required external auth buttons to the submit side (#18…
BrunoQuaresmaJun 27, 2025
b8930ec
fix(agent): fix script filtering for devcontainers (#18635)
mafredriJun 27, 2025
1891c6f
refactor: show the apps as soon as possible (#18625)
BrunoQuaresmaJun 27, 2025
99f3664
feat: redirect to the task page after creation (#18626)
BrunoQuaresmaJun 27, 2025
19089ad
fix: use default preset when creating a workspace for task (#18623)
BrunoQuaresmaJun 27, 2025
47f813e
fix(agent/agentcontainers): ensure proper channel closure for updateT…
mafredriJun 27, 2025
2a68b01
fix(agent/agentcontainers): split Init into Init and Start for early …
mafredriJun 27, 2025
2daec01
feat: make task panels resizable (#18590)
BrunoQuaresmaJun 27, 2025
9e923f9
fix: use only template version ID to create task workspace (#18642)
BrunoQuaresmaJun 27, 2025
830a9ed
chore: add beta badge to tasks (#18656)
dannykoppingJun 30, 2025
da71915
fix(agent/agentcontainers): always derive devcontainer name from work…
mafredriJun 30, 2025
9a9dd5d
fix: handle health status when displaying task apps (#18675)
hugodutkaJun 30, 2025
4bcbc96
fix: improve reliability of app statuses (#18622)
code-asherJun 30, 2025
2d210aa
chore: fix idle state icon when disabled (#18554)
code-asherJun 25, 2025
459b9d9
docs: add warning about prebuilds incompatibility with certain featur…
ssncferreiraJul 1, 2025
b975443
Merge branch 'release/2.24' into cherry-picks-2.24
stirbyJul 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 92 additions & 28 deletionsagent/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,7 @@ type Options struct {
Execer agentexec.Execer
Devcontainers bool
DevcontainerAPIOptions []agentcontainers.Option // Enable Devcontainers for these to be effective.
Clock quartz.Clock
}

type Client interface {
Expand DownExpand Up@@ -144,6 +145,9 @@ func New(options Options) Agent {
if options.PortCacheDuration == 0 {
options.PortCacheDuration = 1 * time.Second
}
if options.Clock == nil {
options.Clock = quartz.NewReal()
}

prometheusRegistry := options.PrometheusRegistry
if prometheusRegistry == nil {
Expand All@@ -157,6 +161,7 @@ func New(options Options) Agent {
hardCtx, hardCancel := context.WithCancel(context.Background())
gracefulCtx, gracefulCancel := context.WithCancel(hardCtx)
a := &agent{
clock: options.Clock,
tailnetListenPort: options.TailnetListenPort,
reconnectingPTYTimeout: options.ReconnectingPTYTimeout,
logger: options.Logger,
Expand DownExpand Up@@ -204,6 +209,7 @@ func New(options Options) Agent {
}

type agent struct {
clock quartz.Clock
logger slog.Logger
client Client
exchangeToken func(ctx context.Context) (string, error)
Expand DownExpand Up@@ -273,7 +279,7 @@ type agent struct {

devcontainers bool
containerAPIOptions []agentcontainers.Option
containerAPIatomic.Pointer[agentcontainers.API] // Set by apiHandler.
containerAPI*agentcontainers.API
}

func (a *agent) TailnetConn() *tailnet.Conn {
Expand DownExpand Up@@ -330,6 +336,19 @@ func (a *agent) init() {
// will not report anywhere.
a.scriptRunner.RegisterMetrics(a.prometheusRegistry)

if a.devcontainers {
containerAPIOpts := []agentcontainers.Option{
agentcontainers.WithExecer(a.execer),
agentcontainers.WithCommandEnv(a.sshServer.CommandEnv),
agentcontainers.WithScriptLogger(func(logSourceID uuid.UUID) agentcontainers.ScriptLogger {
return a.logSender.GetScriptLogger(logSourceID)
}),
}
containerAPIOpts = append(containerAPIOpts, a.containerAPIOptions...)

a.containerAPI = agentcontainers.NewAPI(a.logger.Named("containers"), containerAPIOpts...)
}

a.reconnectingPTYServer = reconnectingpty.NewServer(
a.logger.Named("reconnecting-pty"),
a.sshServer,
Expand DownExpand Up@@ -1141,17 +1160,27 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
}

var (
scripts = manifest.Scripts
scriptRunnerOpts []agentscripts.InitOption
scripts= manifest.Scripts
devcontainerScripts map[uuid.UUID]codersdk.WorkspaceAgentScript
)
if a.devcontainers {
var dcScripts []codersdk.WorkspaceAgentScript
scripts, dcScripts = agentcontainers.ExtractAndInitializeDevcontainerScripts(manifest.Devcontainers, scripts)
// See ExtractAndInitializeDevcontainerScripts for motivation
// behind running dcScripts as post start scripts.
scriptRunnerOpts = append(scriptRunnerOpts, agentscripts.WithPostStartScripts(dcScripts...))
if a.containerAPI != nil {
// Init the container API with the manifest and client so that
// we can start accepting requests. The final start of the API
// happens after the startup scripts have been executed to
// ensure the presence of required tools. This means we can
// return existing devcontainers but actual container detection
// and creation will be deferred.
a.containerAPI.Init(
agentcontainers.WithManifestInfo(manifest.OwnerName, manifest.WorkspaceName, manifest.AgentName),
agentcontainers.WithDevcontainers(manifest.Devcontainers, manifest.Scripts),
agentcontainers.WithSubAgentClient(agentcontainers.NewSubAgentClientFromAPI(a.logger, aAPI)),
)

// Since devcontainer are enabled, remove devcontainer scripts
// from the main scripts list to avoid showing an error.
scripts, devcontainerScripts = agentcontainers.ExtractDevcontainerScripts(manifest.Devcontainers, scripts)
}
err = a.scriptRunner.Init(scripts, aAPI.ScriptCompleted, scriptRunnerOpts...)
err = a.scriptRunner.Init(scripts, aAPI.ScriptCompleted)
if err != nil {
return xerrors.Errorf("init script runner: %w", err)
}
Expand All@@ -1168,7 +1197,18 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
// finished (both start and post start). For instance, an
// autostarted devcontainer will be included in this time.
err := a.scriptRunner.Execute(a.gracefulCtx, agentscripts.ExecuteStartScripts)
err = errors.Join(err, a.scriptRunner.Execute(a.gracefulCtx, agentscripts.ExecutePostStartScripts))

if a.containerAPI != nil {
// Start the container API after the startup scripts have
// been executed to ensure that the required tools can be
// installed.
a.containerAPI.Start()
for _, dc := range manifest.Devcontainers {
cErr := a.createDevcontainer(ctx, aAPI, dc, devcontainerScripts[dc.ID])
err = errors.Join(err, cErr)
}
}

dur := time.Since(start).Seconds()
if err != nil {
a.logger.Warn(ctx, "startup script(s) failed", slog.Error(err))
Expand All@@ -1187,14 +1227,6 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
}
a.metrics.startupScriptSeconds.WithLabelValues(label).Set(dur)
a.scriptRunner.StartCron()

// If the container API is enabled, trigger an immediate refresh
// for quick sub agent injection.
if cAPI := a.containerAPI.Load(); cAPI != nil {
if err := cAPI.RefreshContainers(ctx); err != nil {
a.logger.Error(ctx, "failed to refresh containers", slog.Error(err))
}
}
})
if err != nil {
return xerrors.Errorf("track conn goroutine: %w", err)
Expand All@@ -1204,6 +1236,38 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
}
}

func (a *agent) createDevcontainer(
ctx context.Context,
aAPI proto.DRPCAgentClient26,
dc codersdk.WorkspaceAgentDevcontainer,
script codersdk.WorkspaceAgentScript,
) (err error) {
var (
exitCode = int32(0)
startTime = a.clock.Now()
status = proto.Timing_OK
)
if err = a.containerAPI.CreateDevcontainer(dc.WorkspaceFolder, dc.ConfigPath); err != nil {
exitCode = 1
status = proto.Timing_EXIT_FAILURE
}
endTime := a.clock.Now()

if _, scriptErr := aAPI.ScriptCompleted(ctx, &proto.WorkspaceAgentScriptCompletedRequest{
Timing: &proto.Timing{
ScriptId: script.ID[:],
Start: timestamppb.New(startTime),
End: timestamppb.New(endTime),
ExitCode: exitCode,
Stage: proto.Timing_START,
Status: status,
},
}); scriptErr != nil {
a.logger.Warn(ctx, "reporting script completed failed", slog.Error(scriptErr))
}
return err
}

// createOrUpdateNetwork waits for the manifest to be set using manifestOK, then creates or updates
// the tailnet using the information in the manifest
func (a *agent) createOrUpdateNetwork(manifestOK, networkOK *checkpoint) func(context.Context, proto.DRPCAgentClient26) error {
Expand All@@ -1227,7 +1291,6 @@ func (a *agent) createOrUpdateNetwork(manifestOK, networkOK *checkpoint) func(co
// agent API.
network, err = a.createTailnet(
a.gracefulCtx,
aAPI,
manifest.AgentID,
manifest.DERPMap,
manifest.DERPForceWebSockets,
Expand DownExpand Up@@ -1262,9 +1325,9 @@ func (a *agent) createOrUpdateNetwork(manifestOK, networkOK *checkpoint) func(co
network.SetBlockEndpoints(manifest.DisableDirectConnections)

// Update the subagent client if the container API is available.
ifcAPI :=a.containerAPI.Load(); cAPI != nil {
if a.containerAPI != nil {
client := agentcontainers.NewSubAgentClientFromAPI(a.logger, aAPI)
cAPI.UpdateSubAgentClient(client)
a.containerAPI.UpdateSubAgentClient(client)
}
}
return nil
Expand DownExpand Up@@ -1382,7 +1445,6 @@ func (a *agent) trackGoroutine(fn func()) error {

func (a *agent) createTailnet(
ctx context.Context,
aAPI proto.DRPCAgentClient26,
agentID uuid.UUID,
derpMap *tailcfg.DERPMap,
derpForceWebSockets, disableDirectConnections bool,
Expand DownExpand Up@@ -1515,10 +1577,7 @@ func (a *agent) createTailnet(
}()
if err = a.trackGoroutine(func() {
defer apiListener.Close()
apiHandler, closeAPIHAndler := a.apiHandler(aAPI)
defer func() {
_ = closeAPIHAndler()
}()
apiHandler := a.apiHandler()
server := &http.Server{
BaseContext: func(net.Listener) context.Context { return ctx },
Handler: apiHandler,
Expand All@@ -1532,7 +1591,6 @@ func (a *agent) createTailnet(
case <-ctx.Done():
case <-a.hardCtx.Done():
}
_ = closeAPIHAndler()
_ = server.Close()
}()

Expand DownExpand Up@@ -1871,6 +1929,12 @@ func (a *agent) Close() error {
a.logger.Error(a.hardCtx, "script runner close", slog.Error(err))
}

if a.containerAPI != nil {
if err := a.containerAPI.Close(); err != nil {
a.logger.Error(a.hardCtx, "container API close", slog.Error(err))
}
}

// Wait for the graceful shutdown to complete, but don't wait forever so
// that we don't break user expectations.
go func() {
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp