Skip to content

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

Merged
merged 8 commits into from
Mar 18, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: remoteEnv null value handling
  • Loading branch information
johnstcn committed Mar 18, 2025
commit 8752e6edd6058579c1e7023551988adc8b240f35
6 changes: 5 additions & 1 deletion agent/agentcontainers/containers_dockercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"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"
Expand Down Expand Up @@ -194,7 +195,10 @@ func devcontainerEnv(ctx context.Context, execer agentexec.Execer, container str
for _, m := range meta {
for k, v := range m.RemoteEnv {
if v == nil { // *string per spec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I interpret this as env var k should be removed. Does the spec specify more concretely what null means in this context (or do we have to try it out)?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

@mafredri mafredri Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems @devcontainer/cli has a poor implementation, from:

	"remoteEnv": {
		"FOO": "bar",
		"NODE_OPTIONS": "",
		"GOPRIVATE": null
	},

We get this.

NODE_OPTIONS=
GOPRIVATE=null
FOO=bar

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 @devcontainer/cli exactly here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a null sneak in is suprising behaviour to me. I'd honestly prefer an empty string, but we can revisit this if it causes compat issues.

continue
// 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))
}
Expand Down