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

Commit84ccd92

Browse files
committed
reflect devcontainer status in container and fix story
1 parent7d9f43c commit84ccd92

File tree

9 files changed

+110
-27
lines changed

9 files changed

+110
-27
lines changed

‎agent/agentcontainers/api.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
403403
// Check if the container is running and update the known devcontainers.
404404
fori:=rangeupdated.Containers {
405405
container:=&updated.Containers[i]// Grab a reference to the container to allow mutating it.
406+
container.DevcontainerStatus=""// Reset the status for the container (updated later).
406407
container.DevcontainerDirty=false// Reset dirty state for the container (updated later).
407408

408409
workspaceFolder:=container.Labels[DevcontainerLocalFolderLabel]
@@ -463,6 +464,11 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
463464
// Iterate through all known devcontainers and update their status
464465
// based on the current state of the containers.
465466
for_,dc:=rangeapi.knownDevcontainers {
467+
ifdc.Container!=nil {
468+
dc.Container.DevcontainerStatus=dc.Status
469+
dc.Container.DevcontainerDirty=dc.Dirty
470+
}
471+
466472
switch {
467473
casedc.Status==codersdk.WorkspaceAgentDevcontainerStatusStarting:
468474
continue// This state is handled by the recreation routine.
@@ -608,6 +614,9 @@ func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Reques
608614
// Update the status so that we don't try to recreate the
609615
// devcontainer multiple times in parallel.
610616
dc.Status=codersdk.WorkspaceAgentDevcontainerStatusStarting
617+
ifdc.Container!=nil {
618+
dc.Container.DevcontainerStatus=dc.Status
619+
}
611620
api.knownDevcontainers[dc.WorkspaceFolder]=dc
612621
api.recreateWg.Add(1)
613622
goapi.recreateDevcontainer(dc,configPath)
@@ -680,6 +689,9 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
680689
api.mu.Lock()
681690
dc=api.knownDevcontainers[dc.WorkspaceFolder]
682691
dc.Status=codersdk.WorkspaceAgentDevcontainerStatusError
692+
ifdc.Container!=nil {
693+
dc.Container.DevcontainerStatus=dc.Status
694+
}
683695
api.knownDevcontainers[dc.WorkspaceFolder]=dc
684696
api.recreateErrorTimes[dc.WorkspaceFolder]=api.clock.Now("recreate","errorTimes")
685697
api.mu.Unlock()
@@ -695,10 +707,12 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
695707
// allows the update routine to update the devcontainer status, but
696708
// to minimize the time between API consistency, we guess the status
697709
// based on the container state.
698-
ifdc.Container!=nil&&dc.Container.Running {
699-
dc.Status=codersdk.WorkspaceAgentDevcontainerStatusRunning
700-
}else {
701-
dc.Status=codersdk.WorkspaceAgentDevcontainerStatusStopped
710+
dc.Status=codersdk.WorkspaceAgentDevcontainerStatusStopped
711+
ifdc.Container!=nil {
712+
ifdc.Container.Running {
713+
dc.Status=codersdk.WorkspaceAgentDevcontainerStatusRunning
714+
}
715+
dc.Container.DevcontainerStatus=dc.Status
702716
}
703717
dc.Dirty=false
704718
api.recreateSuccessTimes[dc.WorkspaceFolder]=api.clock.Now("recreate","successTimes")

‎coderd/apidoc/docs.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎codersdk/workspaceagents.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ type WorkspaceAgentContainer struct {
450450
// Volumes is a map of "things" mounted into the container. Again, this
451451
// is somewhat implementation-dependent.
452452
Volumesmap[string]string`json:"volumes"`
453+
// DevcontainerStatus is the status of the devcontainer, if this
454+
// container is a devcontainer. This is used to determine if the
455+
// devcontainer is running, stopped, starting, or in an error state.
456+
DevcontainerStatusWorkspaceAgentDevcontainerStatus`json:"devcontainer_status,omitempty"`
453457
// DevcontainerDirty is true if the devcontainer configuration has changed
454458
// since the container was created. This is used to determine if the
455459
// container needs to be rebuilt.

‎docs/reference/api/agents.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎docs/reference/api/schemas.md

Lines changed: 34 additions & 14 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎site/src/api/typesGenerated.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎site/src/modules/resources/AgentDevcontainerCard.stories.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
importtype{Meta,StoryObj}from"@storybook/react";
2-
import{within,userEvent}from"@storybook/test";
32
import{
43
MockWorkspace,
54
MockWorkspaceAgent,
@@ -48,14 +47,8 @@ export const Recreating: Story = {
4847
container:{
4948
...MockWorkspaceAgentContainer,
5049
devcontainer_dirty:true,
50+
devcontainer_status:"starting",
5151
ports:MockWorkspaceAgentContainerPorts,
5252
},
5353
},
54-
play:async({ canvasElement})=>{
55-
constcanvas=within(canvasElement);
56-
constrecreateButton=awaitcanvas.findByRole("button",{
57-
name:/recreate/i,
58-
});
59-
awaituserEvent.click(recreateButton);
60-
},
6154
};

‎site/src/modules/resources/AgentDevcontainerCard.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
}from"components/Tooltip/Tooltip";
2121
import{ExternalLinkIcon,Loader2Icon}from"lucide-react";
2222
importtype{FC}from"react";
23-
import{useState}from"react";
23+
import{useEffect,useState}from"react";
2424
import{portForwardURL}from"utils/portForward";
2525
import{AgentButton}from"./AgentButton";
2626
import{AgentDevcontainerSSHButton}from"./SSHButton/SSHButton";
@@ -78,6 +78,15 @@ export const AgentDevcontainerCard: FC<AgentDevcontainerCardProps> = ({
7878
}
7979
};
8080

81+
// If the container is starting, reflect this in the recreate button.
82+
useEffect(()=>{
83+
if(container.devcontainer_status==="starting"){
84+
setIsRecreating(true);
85+
}else{
86+
setIsRecreating(false);
87+
}
88+
},[container.devcontainer_status]);
89+
8190
return(
8291
<section
8392
className="border border-border border-dashed rounded p-6 "

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp