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

Commitd18e00c

Browse files
committed
feat: add support forcoder_env
Fixes#10166
1 parent4ca4736 commitd18e00c

File tree

6 files changed

+548
-382
lines changed

6 files changed

+548
-382
lines changed

‎coderd/provisionerdserver/provisionerdserver.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,13 +1387,26 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
13871387
Valid:true,
13881388
}
13891389
}
1390-
varenv pqtype.NullRawMessage
1391-
ifprAgent.Env!=nil {
1392-
data,err:=json.Marshal(prAgent.Env)
1390+
varenvJSON pqtype.NullRawMessage
1391+
env:=prAgent.Env
1392+
ifenv!=nil {
1393+
// For now, we only support adding extra envs, not overriding
1394+
// existing ones or performing other manipulations. In future
1395+
// we may write these to a separate table so we can perform
1396+
// conditional logic on the agent.
1397+
iflen(prAgent.ExtraEnvs)>0 {
1398+
env=maps.Clone(env)
1399+
for_,extraEnv:=rangeprAgent.ExtraEnvs {
1400+
if_,ok:=env[extraEnv.Name];!ok {
1401+
env[extraEnv.Name]=extraEnv.Value
1402+
}
1403+
}
1404+
}
1405+
data,err:=json.Marshal(env)
13931406
iferr!=nil {
13941407
returnxerrors.Errorf("marshal env: %w",err)
13951408
}
1396-
env= pqtype.NullRawMessage{
1409+
envJSON= pqtype.NullRawMessage{
13971410
RawMessage:data,
13981411
Valid:true,
13991412
}
@@ -1416,7 +1429,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
14161429
AuthToken:authToken,
14171430
AuthInstanceID:instanceID,
14181431
Architecture:prAgent.Architecture,
1419-
EnvironmentVariables:env,
1432+
EnvironmentVariables:envJSON,
14201433
Directory:prAgent.Directory,
14211434
OperatingSystem:prAgent.OperatingSystem,
14221435
ConnectionTimeoutSeconds:prAgent.GetConnectionTimeoutSeconds(),

‎coderd/provisionerdserver/provisionerdserver_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,16 @@ func TestInsertWorkspaceResource(t *testing.T) {
15851585
Apps: []*sdkproto.App{{
15861586
Slug:"a",
15871587
}},
1588+
ExtraEnvs: []*sdkproto.Env{
1589+
{
1590+
Name:"something",// Duplicate, already set by Env.
1591+
Value:"I should be discarded!",
1592+
},
1593+
{
1594+
Name:"else",
1595+
Value:"I laugh in the face of danger.",
1596+
},
1597+
},
15881598
Scripts: []*sdkproto.Script{{
15891599
DisplayName:"Startup",
15901600
Icon:"/test.png",
@@ -1609,6 +1619,7 @@ func TestInsertWorkspaceResource(t *testing.T) {
16091619
require.Equal(t,"linux",agent.OperatingSystem)
16101620
want,err:=json.Marshal(map[string]string{
16111621
"something":"test",
1622+
"else":"I laugh in the face of danger.",
16121623
})
16131624
require.NoError(t,err)
16141625
got,err:=agent.EnvironmentVariables.RawMessage.MarshalJSON()

‎provisioner/terraform/resources.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ type agentAppAttributes struct {
7777
Healthcheck []appHealthcheckAttributes`mapstructure:"healthcheck"`
7878
}
7979

80+
typeagentEnvAttributesstruct {
81+
AgentIDstring`mapstructure:"agent_id"`
82+
Namestring`mapstructure:"name"`
83+
Valuestring`mapstructure:"value"`
84+
}
85+
8086
typeagentScriptAttributesstruct {
8187
AgentIDstring`mapstructure:"agent_id"`
8288
DisplayNamestring`mapstructure:"display_name"`
@@ -435,6 +441,32 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
435441
}
436442
}
437443

444+
// Associate envs with agents.
445+
for_,resources:=rangetfResourcesByLabel {
446+
for_,resource:=rangeresources {
447+
ifresource.Type!="coder_env" {
448+
continue
449+
}
450+
varattrsagentEnvAttributes
451+
err=mapstructure.Decode(resource.AttributeValues,&attrs)
452+
iferr!=nil {
453+
returnnil,xerrors.Errorf("decode env attributes: %w",err)
454+
}
455+
for_,agents:=rangeresourceAgents {
456+
for_,agent:=rangeagents {
457+
// Find agents with the matching ID and associate them!
458+
ifagent.Id!=attrs.AgentID {
459+
continue
460+
}
461+
agent.ExtraEnvs=append(agent.ExtraEnvs,&proto.Env{
462+
Name:attrs.Name,
463+
Value:attrs.Value,
464+
})
465+
}
466+
}
467+
}
468+
}
469+
438470
// Associate scripts with agents.
439471
for_,resources:=rangetfResourcesByLabel {
440472
for_,resource:=rangeresources {
@@ -444,7 +476,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
444476
varattrsagentScriptAttributes
445477
err=mapstructure.Decode(resource.AttributeValues,&attrs)
446478
iferr!=nil {
447-
returnnil,xerrors.Errorf("decodeapp attributes: %w",err)
479+
returnnil,xerrors.Errorf("decodescript attributes: %w",err)
448480
}
449481
for_,agents:=rangeresourceAgents {
450482
for_,agent:=rangeagents {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp