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

Commitef8ddee

Browse files
committed
Merge branch 'main' into lilac/go-122-range-fix
2 parents8353313 +556b095 commitef8ddee

File tree

124 files changed

+5791
-1600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+5791
-1600
lines changed

‎agent/agent_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ func TestAgent_EnvironmentVariableExpansion(t *testing.T) {
12021202
funcTestAgent_CoderEnvVars(t*testing.T) {
12031203
t.Parallel()
12041204

1205-
for_,key:=range []string{"CODER","CODER_WORKSPACE_NAME","CODER_WORKSPACE_AGENT_NAME"} {
1205+
for_,key:=range []string{"CODER","CODER_WORKSPACE_NAME","CODER_WORKSPACE_OWNER_NAME","CODER_WORKSPACE_AGENT_NAME"} {
12061206
t.Run(key,func(t*testing.T) {
12071207
t.Parallel()
12081208

@@ -3067,6 +3067,9 @@ func setupAgent(t *testing.T, metadata agentsdk.Manifest, ptyTimeout time.Durati
30673067
ifmetadata.WorkspaceName=="" {
30683068
metadata.WorkspaceName="test-workspace"
30693069
}
3070+
ifmetadata.OwnerName=="" {
3071+
metadata.OwnerName="test-user"
3072+
}
30703073
ifmetadata.WorkspaceID==uuid.Nil {
30713074
metadata.WorkspaceID=uuid.New()
30723075
}

‎agent/agentcontainers/api.go

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package agentcontainers
22

33
import (
4-
"bytes"
54
"context"
65
"errors"
76
"fmt"
8-
"io"
97
"net/http"
108
"os"
119
"path"
@@ -28,6 +26,7 @@ import (
2826
"github.com/coder/coder/v2/coderd/httpapi"
2927
"github.com/coder/coder/v2/codersdk"
3028
"github.com/coder/coder/v2/codersdk/agentsdk"
29+
"github.com/coder/coder/v2/provisioner"
3130
"github.com/coder/quartz"
3231
)
3332

@@ -1113,27 +1112,6 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
11131112
ifproc.agent.ID==uuid.Nil||maybeRecreateSubAgent {
11141113
subAgentConfig.Architecture=arch
11151114

1116-
// Detect workspace folder by executing `pwd` in the container.
1117-
// NOTE(mafredri): This is a quick and dirty way to detect the
1118-
// workspace folder inside the container. In the future we will
1119-
// rely more on `devcontainer read-configuration`.
1120-
varpwdBuf bytes.Buffer
1121-
err=api.dccli.Exec(ctx,dc.WorkspaceFolder,dc.ConfigPath,"pwd", []string{},
1122-
WithExecOutput(&pwdBuf,io.Discard),
1123-
WithExecContainerID(container.ID),
1124-
)
1125-
iferr!=nil {
1126-
returnxerrors.Errorf("check workspace folder in container: %w",err)
1127-
}
1128-
directory:=strings.TrimSpace(pwdBuf.String())
1129-
ifdirectory=="" {
1130-
logger.Warn(ctx,"detected workspace folder is empty, using default workspace folder",
1131-
slog.F("default_workspace_folder",DevcontainerDefaultContainerWorkspaceFolder),
1132-
)
1133-
directory=DevcontainerDefaultContainerWorkspaceFolder
1134-
}
1135-
subAgentConfig.Directory=directory
1136-
11371115
displayAppsMap:=map[codersdk.DisplayApp]bool{
11381116
// NOTE(DanielleMaywood):
11391117
// We use the same defaults here as set in terraform-provider-coder.
@@ -1145,18 +1123,55 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
11451123
codersdk.DisplayAppPortForward:true,
11461124
}
11471125

1148-
varappsWithPossibleDuplicates []SubAgentApp
1126+
var (
1127+
appsWithPossibleDuplicates []SubAgentApp
1128+
workspaceFolder=DevcontainerDefaultContainerWorkspaceFolder
1129+
)
1130+
1131+
iferr:=func()error {
1132+
var (
1133+
configDevcontainerConfig
1134+
configOutdatedbool
1135+
)
1136+
1137+
readConfig:=func() (DevcontainerConfig,error) {
1138+
returnapi.dccli.ReadConfig(ctx,dc.WorkspaceFolder,dc.ConfigPath, []string{
1139+
fmt.Sprintf("CODER_WORKSPACE_AGENT_NAME=%s",subAgentConfig.Name),
1140+
fmt.Sprintf("CODER_WORKSPACE_OWNER_NAME=%s",api.ownerName),
1141+
fmt.Sprintf("CODER_WORKSPACE_NAME=%s",api.workspaceName),
1142+
fmt.Sprintf("CODER_URL=%s",api.subAgentURL),
1143+
})
1144+
}
1145+
1146+
ifconfig,err=readConfig();err!=nil {
1147+
returnerr
1148+
}
1149+
1150+
workspaceFolder=config.Workspace.WorkspaceFolder
1151+
1152+
// NOTE(DanielleMaywood):
1153+
// We only want to take an agent name specified in the root customization layer.
1154+
// This restricts the ability for a feature to specify the agent name. We may revisit
1155+
// this in the future, but for now we want to restrict this behavior.
1156+
ifname:=config.Configuration.Customizations.Coder.Name;name!="" {
1157+
// We only want to pick this name if it is a valid name.
1158+
ifprovisioner.AgentNameRegex.Match([]byte(name)) {
1159+
subAgentConfig.Name=name
1160+
configOutdated=true
1161+
}else {
1162+
logger.Warn(ctx,"invalid name in devcontainer customization, ignoring",
1163+
slog.F("name",name),
1164+
slog.F("regex",provisioner.AgentNameRegex.String()),
1165+
)
1166+
}
1167+
}
1168+
1169+
ifconfigOutdated {
1170+
ifconfig,err=readConfig();err!=nil {
1171+
returnerr
1172+
}
1173+
}
11491174

1150-
ifconfig,err:=api.dccli.ReadConfig(ctx,dc.WorkspaceFolder,dc.ConfigPath,
1151-
[]string{
1152-
fmt.Sprintf("CODER_WORKSPACE_AGENT_NAME=%s",dc.Name),
1153-
fmt.Sprintf("CODER_WORKSPACE_OWNER_NAME=%s",api.ownerName),
1154-
fmt.Sprintf("CODER_WORKSPACE_NAME=%s",api.workspaceName),
1155-
fmt.Sprintf("CODER_URL=%s",api.subAgentURL),
1156-
},
1157-
);err!=nil {
1158-
api.logger.Error(ctx,"unable to read devcontainer config",slog.Error(err))
1159-
}else {
11601175
coderCustomization:=config.MergedConfiguration.Customizations.Coder
11611176

11621177
for_,customization:=rangecoderCustomization {
@@ -1173,6 +1188,10 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
11731188

11741189
appsWithPossibleDuplicates=append(appsWithPossibleDuplicates,customization.Apps...)
11751190
}
1191+
1192+
returnnil
1193+
}();err!=nil {
1194+
api.logger.Error(ctx,"unable to read devcontainer config",slog.Error(err))
11761195
}
11771196

11781197
displayApps:=make([]codersdk.DisplayApp,0,len(displayAppsMap))
@@ -1204,6 +1223,7 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
12041223

12051224
subAgentConfig.DisplayApps=displayApps
12061225
subAgentConfig.Apps=apps
1226+
subAgentConfig.Directory=workspaceFolder
12071227
}
12081228

12091229
deleteSubAgent:=proc.agent.ID!=uuid.Nil&&maybeRecreateSubAgent&&!proc.agent.EqualConfig(subAgentConfig)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp