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

Commitb63880b

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

File tree

6 files changed

+549
-382
lines changed

6 files changed

+549
-382
lines changed

‎coderd/provisionerdserver/provisionerdserver.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,13 +1387,27 @@ 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+
1391+
env:=make(map[string]string)
1392+
// For now, we only support adding extra envs, not overriding
1393+
// existing ones or performing other manipulations. In future
1394+
// we may write these to a separate table so we can perform
1395+
// conditional logic on the agent.
1396+
for_,e:=rangeprAgent.ExtraEnvs {
1397+
env[e.Name]=e.Value
1398+
}
1399+
// Allow the agent defined envs to override extra envs.
1400+
fork,v:=rangeprAgent.Env {
1401+
env[k]=v
1402+
}
1403+
1404+
varenvJSON pqtype.NullRawMessage
1405+
iflen(env)>0 {
1406+
data,err:=json.Marshal(env)
13931407
iferr!=nil {
13941408
returnxerrors.Errorf("marshal env: %w",err)
13951409
}
1396-
env= pqtype.NullRawMessage{
1410+
envJSON= pqtype.NullRawMessage{
13971411
RawMessage:data,
13981412
Valid:true,
13991413
}
@@ -1416,7 +1430,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
14161430
AuthToken:authToken,
14171431
AuthInstanceID:instanceID,
14181432
Architecture:prAgent.Architecture,
1419-
EnvironmentVariables:env,
1433+
EnvironmentVariables:envJSON,
14201434
Directory:prAgent.Directory,
14211435
OperatingSystem:prAgent.OperatingSystem,
14221436
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