-
Notifications
You must be signed in to change notification settings - Fork 897
fix(agent/agentcontainers): generate devcontainer metadata from schema #16881
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bf15dcb
d4a36a2
4fa1954
2a565b3
94b7e20
b5069f6
8752e6e
e513e0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,10 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"github.com/coder/coder/v2/agent/agentcontainers/dcspec" | ||
"github.com/coder/coder/v2/agent/agentexec" | ||
"github.com/coder/coder/v2/agent/usershell" | ||
"github.com/coder/coder/v2/coderd/util/ptr" | ||
"github.com/coder/coder/v2/codersdk" | ||
|
||
"golang.org/x/exp/maps" | ||
|
@@ -183,7 +185,7 @@ func devcontainerEnv(ctx context.Context, execer agentexec.Execer, container str | |
return nil, nil | ||
} | ||
|
||
meta := make([]DevContainerMeta, 0) | ||
meta := make([]dcspec.DevContainer, 0) | ||
if err := json.Unmarshal([]byte(rawMeta), &meta); err != nil { | ||
return nil, xerrors.Errorf("unmarshal devcontainer.metadata: %w", err) | ||
} | ||
|
@@ -192,7 +194,13 @@ func devcontainerEnv(ctx context.Context, execer agentexec.Execer, container str | |
env := make([]string, 0) | ||
for _, m := range meta { | ||
for k, v := range m.RemoteEnv { | ||
env = append(env, fmt.Sprintf("%s=%s", k, v)) | ||
if v == nil { // *string per spec | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I interpret this as env var There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, no. I think we'll have to either try it out or read the implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems "remoteEnv": {
"FOO": "bar",
"NODE_OPTIONS": "",
"GOPRIVATE": null
}, We get this.
I'm not a fan of the null handling here. But if we want to retain a similar behavior, we shouldn't just skip it. I'd suggest setting it to an empty string when "none", does that sound reasonable? Or do we want to mimic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a |
||
// devcontainer-cli will set this to the string "null" if the value is | ||
// not set. Explicitly setting to an empty string here as this would be | ||
// more expected here. | ||
v = ptr.Ref("") | ||
} | ||
env = append(env, fmt.Sprintf("%s=%s", k, *v)) | ||
} | ||
} | ||
slices.Sort(env) | ||
|
@@ -276,7 +284,7 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi | |
// log this error, but I'm not sure it's worth it. | ||
ins, dockerInspectStderr, err := runDockerInspect(ctx, dcl.execer, ids...) | ||
if err != nil { | ||
return codersdk.WorkspaceAgentListContainersResponse{}, xerrors.Errorf("run docker inspect: %w", err) | ||
return codersdk.WorkspaceAgentListContainersResponse{}, xerrors.Errorf("run docker inspect: %w: %s", err, dockerInspectStderr) | ||
} | ||
|
||
for _, in := range ins { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: We could first attempt a strict unmarshal via
dec := json.NewDecoder(), dec.DisallowUnknownFields()
, if it catches an issue we can log it and fall-back to non-strict unmarshaling.Not strictly necessary, but may help provide hints down the line why something isn't working.