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

Commit3e5d292

Browse files
authored
feat: add support forcoder_env (#11102)
Fixes#10166
1 parent4612c28 commit3e5d292

File tree

7 files changed

+550
-382
lines changed

7 files changed

+550
-382
lines changed

‎coderd/provisionerdserver/provisionerdserver.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,13 +1388,27 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
13881388
Valid:true,
13891389
}
13901390
}
1391-
varenv pqtype.NullRawMessage
1392-
ifprAgent.Env!=nil {
1393-
data,err:=json.Marshal(prAgent.Env)
1391+
1392+
env:=make(map[string]string)
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+
for_,e:=rangeprAgent.ExtraEnvs {
1398+
env[e.Name]=e.Value
1399+
}
1400+
// Allow the agent defined envs to override extra envs.
1401+
fork,v:=rangeprAgent.Env {
1402+
env[k]=v
1403+
}
1404+
1405+
varenvJSON pqtype.NullRawMessage
1406+
iflen(env)>0 {
1407+
data,err:=json.Marshal(env)
13941408
iferr!=nil {
13951409
returnxerrors.Errorf("marshal env: %w",err)
13961410
}
1397-
env= pqtype.NullRawMessage{
1411+
envJSON= pqtype.NullRawMessage{
13981412
RawMessage:data,
13991413
Valid:true,
14001414
}
@@ -1417,7 +1431,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
14171431
AuthToken:authToken,
14181432
AuthInstanceID:instanceID,
14191433
Architecture:prAgent.Architecture,
1420-
EnvironmentVariables:env,
1434+
EnvironmentVariables:envJSON,
14211435
Directory:prAgent.Directory,
14221436
OperatingSystem:prAgent.OperatingSystem,
14231437
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