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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 8 commits intomainfromcj/gen-devcontainer-schema
Mar 18, 2025
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
1 change: 1 addition & 0 deletions.gitattributes
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
# Generated files
agent/agentcontainers/acmock/acmock.golinguist-generated=true
agent/agentcontainers/dcspec/dcspec_gen.golinguist-generated=true
coderd/apidoc/docs.golinguist-generated=true
docs/reference/api/*.mdlinguist-generated=true
docs/reference/cli/*.mdlinguist-generated=true
Expand Down
8 changes: 6 additions & 2 deletionsMakefile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -564,8 +564,8 @@ GEN_FILES := \
examples/examples.gen.json \
$(TAILNETTEST_MOCKS) \
coderd/database/pubsub/psmock/psmock.go \
agent/agentcontainers/acmock/acmock.go

agent/agentcontainers/acmock/acmock.go \
agent/agentcontainers/dcspec/dcspec_gen.go

# all gen targets should be added here and to gen/mark-fresh
gen: gen/db $(GEN_FILES)
Expand DownExpand Up@@ -600,6 +600,7 @@ gen/mark-fresh:
$(TAILNETTEST_MOCKS) \
coderd/database/pubsub/psmock/psmock.go \
agent/agentcontainers/acmock/acmock.go \
agent/agentcontainers/dcspec/dcspec_gen.go \
"

for file in $$files; do
Expand DownExpand Up@@ -634,6 +635,9 @@ coderd/database/pubsub/psmock/psmock.go: coderd/database/pubsub/pubsub.go
agent/agentcontainers/acmock/acmock.go: agent/agentcontainers/containers.go
go generate ./agent/agentcontainers/acmock/

agent/agentcontainers/dcspec/dcspec_gen.go: agent/agentcontainers/dcspec/devContainer.base.schema.json
go generate ./agent/agentcontainers/dcspec/

$(TAILNETTEST_MOCKS): tailnet/coordinator.go tailnet/service.go
go generate ./tailnet/tailnettest/

Expand Down
14 changes: 11 additions & 3 deletionsagent/agentcontainers/containers_dockercli.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"
Expand DownExpand Up@@ -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 {
Copy link
Member

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 viadec := 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.

johnstcn reacted with thumbs up emoji
return nil, xerrors.Errorf("unmarshal devcontainer.metadata: %w", err)
}
Expand All@@ -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
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 vark 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
MemberAuthor

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

@mafredrimafredriMar 14, 2025
edited
Loading

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=nullFOO=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?

johnstcn reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

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

// 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)
Expand DownExpand Up@@ -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 {
Expand Down
9 changes: 5 additions & 4 deletionsagent/agentcontainers/containers_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,8 +34,9 @@ import (
// It can be run manually as follows:
//
// CODER_TEST_USE_DOCKER=1 go test ./agent/agentcontainers -run TestDockerCLIContainerLister
//
//nolint:paralleltest // This test tends to flake when lots of containers start and stop in parallel.
func TestIntegrationDocker(t *testing.T) {
t.Parallel()
if ctud, ok := os.LookupEnv("CODER_TEST_USE_DOCKER"); !ok || ctud != "1" {
t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test")
}
Expand DownExpand Up@@ -418,8 +419,9 @@ func TestConvertDockerVolume(t *testing.T) {
// It can be run manually as follows:
//
// CODER_TEST_USE_DOCKER=1 go test ./agent/agentcontainers -run TestDockerEnvInfoer
//
//nolint:paralleltest // This test tends to flake when lots of containers start and stop in parallel.
func TestDockerEnvInfoer(t *testing.T) {
t.Parallel()
if ctud, ok := os.LookupEnv("CODER_TEST_USE_DOCKER"); !ok || ctud != "1" {
t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test")
}
Expand DownExpand Up@@ -483,9 +485,8 @@ func TestDockerEnvInfoer(t *testing.T) {
expectedUserShell: "/bin/bash",
},
} {
//nolint:paralleltest // variable recapture no longer required
t.Run(fmt.Sprintf("#%d", idx), func(t *testing.T) {
t.Parallel()

// Start a container with the given image
// and environment variables
image := strings.Split(tt.image, ":")[0]
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp