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

feat: add support forcoder_env#11102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 2 commits intomainfrommafredri/feat-coder-env
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletionscoderd/provisionerdserver/provisionerdserver.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1387,13 +1387,27 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
Valid: true,
}
}
var env pqtype.NullRawMessage
if prAgent.Env != nil {
data, err := json.Marshal(prAgent.Env)

env := make(map[string]string)
// For now, we only support adding extra envs, not overriding
// existing ones or performing other manipulations. In future
// we may write these to a separate table so we can perform
// conditional logic on the agent.
for _, e := range prAgent.ExtraEnvs {
env[e.Name] = e.Value
}
// Allow the agent defined envs to override extra envs.
for k, v := range prAgent.Env {
env[k] = v
}

var envJSON pqtype.NullRawMessage
if len(env) > 0 {
data, err := json.Marshal(env)
if err != nil {
return xerrors.Errorf("marshal env: %w", err)
}
env = pqtype.NullRawMessage{
envJSON = pqtype.NullRawMessage{
RawMessage: data,
Valid: true,
}
Expand All@@ -1416,7 +1430,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
AuthToken: authToken,
AuthInstanceID: instanceID,
Architecture: prAgent.Architecture,
EnvironmentVariables:env,
EnvironmentVariables:envJSON,
Directory: prAgent.Directory,
OperatingSystem: prAgent.OperatingSystem,
ConnectionTimeoutSeconds: prAgent.GetConnectionTimeoutSeconds(),
Expand Down
11 changes: 11 additions & 0 deletionscoderd/provisionerdserver/provisionerdserver_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1585,6 +1585,16 @@ func TestInsertWorkspaceResource(t *testing.T) {
Apps: []*sdkproto.App{{
Slug: "a",
}},
ExtraEnvs: []*sdkproto.Env{
{
Name: "something", // Duplicate, already set by Env.
Value: "I should be discarded!",
},
{
Name: "else",
Value: "I laugh in the face of danger.",
},
},
Scripts: []*sdkproto.Script{{
DisplayName: "Startup",
Icon: "/test.png",
Expand All@@ -1609,6 +1619,7 @@ func TestInsertWorkspaceResource(t *testing.T) {
require.Equal(t, "linux", agent.OperatingSystem)
want, err := json.Marshal(map[string]string{
"something": "test",
"else": "I laugh in the face of danger.",
})
require.NoError(t, err)
got, err := agent.EnvironmentVariables.RawMessage.MarshalJSON()
Expand Down
34 changes: 33 additions & 1 deletionprovisioner/terraform/resources.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,6 +77,12 @@ type agentAppAttributes struct {
Healthcheck []appHealthcheckAttributes `mapstructure:"healthcheck"`
}

type agentEnvAttributes struct {
AgentID string `mapstructure:"agent_id"`
Name string `mapstructure:"name"`
Value string `mapstructure:"value"`
}

type agentScriptAttributes struct {
AgentID string `mapstructure:"agent_id"`
DisplayName string `mapstructure:"display_name"`
Expand DownExpand Up@@ -435,6 +441,32 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
}
}

// Associate envs with agents.
for _, resources := range tfResourcesByLabel {
for _, resource := range resources {
if resource.Type != "coder_env" {
continue
}
var attrs agentEnvAttributes
err = mapstructure.Decode(resource.AttributeValues, &attrs)
if err != nil {
return nil, xerrors.Errorf("decode env attributes: %w", err)
}
for _, agents := range resourceAgents {
for _, agent := range agents {
// Find agents with the matching ID and associate them!
if agent.Id != attrs.AgentID {
continue
}
agent.ExtraEnvs = append(agent.ExtraEnvs, &proto.Env{
Name: attrs.Name,
Value: attrs.Value,
})
}
}
}
}

// Associate scripts with agents.
for _, resources := range tfResourcesByLabel {
for _, resource := range resources {
Expand All@@ -444,7 +476,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
var attrs agentScriptAttributes
err = mapstructure.Decode(resource.AttributeValues, &attrs)
if err != nil {
return nil, xerrors.Errorf("decodeapp attributes: %w", err)
return nil, xerrors.Errorf("decodescript attributes: %w", err)
}
for _, agents := range resourceAgents {
for _, agent := range agents {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp