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

Commitae82770

Browse files
authored
Merge branch 'main' into stevenmasley/dynamic_param_pkg
2 parents21ce54b +d61353f commitae82770

File tree

70 files changed

+3724
-1081
lines changed

Some content is hidden

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

70 files changed

+3724
-1081
lines changed

‎agent/agent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,7 @@ func (a *agent) updateCommandEnv(current []string) (updated []string, err error)
12971297
"CODER":"true",
12981298
"CODER_WORKSPACE_NAME":manifest.WorkspaceName,
12991299
"CODER_WORKSPACE_AGENT_NAME":manifest.AgentName,
1300+
"CODER_WORKSPACE_OWNER_NAME":manifest.OwnerName,
13001301

13011302
// Specific Coder subcommands require the agent token exposed!
13021303
"CODER_AGENT_TOKEN":*a.sessionToken.Load(),

‎agent/agent_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ func TestAgent_EnvironmentVariableExpansion(t *testing.T) {
12091209
funcTestAgent_CoderEnvVars(t*testing.T) {
12101210
t.Parallel()
12111211

1212-
for_,key:=range []string{"CODER","CODER_WORKSPACE_NAME","CODER_WORKSPACE_AGENT_NAME"} {
1212+
for_,key:=range []string{"CODER","CODER_WORKSPACE_NAME","CODER_WORKSPACE_OWNER_NAME","CODER_WORKSPACE_AGENT_NAME"} {
12131213
key:=key
12141214
t.Run(key,func(t*testing.T) {
12151215
t.Parallel()
@@ -3079,6 +3079,9 @@ func setupAgent(t *testing.T, metadata agentsdk.Manifest, ptyTimeout time.Durati
30793079
ifmetadata.WorkspaceName=="" {
30803080
metadata.WorkspaceName="test-workspace"
30813081
}
3082+
ifmetadata.OwnerName=="" {
3083+
metadata.OwnerName="test-user"
3084+
}
30823085
ifmetadata.WorkspaceID==uuid.Nil {
30833086
metadata.WorkspaceID=uuid.New()
30843087
}

‎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