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

Commit075d291

Browse files
committed
fix(agent/agentcontainers): generate devcontainer metadata from schema
1 parent78df786 commit075d291

File tree

8 files changed

+407
-12
lines changed

8 files changed

+407
-12
lines changed

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated files
22
agent/agentcontainers/acmock/acmock.golinguist-generated=true
3+
agent/agentcontainers/dcspec/dcspec_gen.golinguist-generated=true
34
coderd/apidoc/docs.golinguist-generated=true
45
docs/reference/api/*.mdlinguist-generated=true
56
docs/reference/cli/*.mdlinguist-generated=true

‎Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ coderd/database/pubsub/psmock/psmock.go: coderd/database/pubsub/pubsub.go
634634
agent/agentcontainers/acmock/acmock.go: agent/agentcontainers/containers.go
635635
go generate ./agent/agentcontainers/acmock/
636636

637+
agent/agentcontainers/dcspec/dcspec_gen.go:
638+
go generate ./agent/agentcontainers/dcspec/
639+
637640
$(TAILNETTEST_MOCKS): tailnet/coordinator.go tailnet/service.go
638641
go generate ./tailnet/tailnettest/
639642

‎agent/agentcontainers/containers_dockercli.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16+
"github.com/coder/coder/v2/agent/agentcontainers/dcspec"
1617
"github.com/coder/coder/v2/agent/agentexec"
1718
"github.com/coder/coder/v2/agent/usershell"
1819
"github.com/coder/coder/v2/codersdk"
@@ -183,7 +184,7 @@ func devcontainerEnv(ctx context.Context, execer agentexec.Execer, container str
183184
returnnil,nil
184185
}
185186

186-
meta:=make([]DevContainerMeta,0)
187+
meta:=make([]dcspec.DevContainer,0)
187188
iferr:=json.Unmarshal([]byte(rawMeta),&meta);err!=nil {
188189
returnnil,xerrors.Errorf("unmarshal devcontainer.metadata: %w",err)
189190
}
@@ -192,7 +193,10 @@ func devcontainerEnv(ctx context.Context, execer agentexec.Execer, container str
192193
env:=make([]string,0)
193194
for_,m:=rangemeta {
194195
fork,v:=rangem.RemoteEnv {
195-
env=append(env,fmt.Sprintf("%s=%s",k,v))
196+
ifv==nil {// *string per spec
197+
continue
198+
}
199+
env=append(env,fmt.Sprintf("%s=%s",k,*v))
196200
}
197201
}
198202
slices.Sort(env)
@@ -276,7 +280,7 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi
276280
// log this error, but I'm not sure it's worth it.
277281
ins,dockerInspectStderr,err:=runDockerInspect(ctx,dcl.execer,ids...)
278282
iferr!=nil {
279-
return codersdk.WorkspaceAgentListContainersResponse{},xerrors.Errorf("run docker inspect: %w",err)
283+
return codersdk.WorkspaceAgentListContainersResponse{},xerrors.Errorf("run docker inspect: %w: %s",err,dockerInspectStderr)
280284
}
281285

282286
for_,in:=rangeins {

‎agent/agentcontainers/containers_internal_test.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ import (
3434
// It can be run manually as follows:
3535
//
3636
// CODER_TEST_USE_DOCKER=1 go test ./agent/agentcontainers -run TestDockerCLIContainerLister
37+
//
38+
//nolint:paralleltest // This test tends to flake when lots of containers start and stop in parallel.
3739
funcTestIntegrationDocker(t*testing.T) {
38-
t.Parallel()
3940
ifctud,ok:=os.LookupEnv("CODER_TEST_USE_DOCKER");!ok||ctud!="1" {
4041
t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test")
4142
}
@@ -418,8 +419,9 @@ func TestConvertDockerVolume(t *testing.T) {
418419
// It can be run manually as follows:
419420
//
420421
// CODER_TEST_USE_DOCKER=1 go test ./agent/agentcontainers -run TestDockerEnvInfoer
422+
//
423+
//nolint:paralleltest // This test tends to flake when lots of containers start and stop in parallel.
421424
funcTestDockerEnvInfoer(t*testing.T) {
422-
t.Parallel()
423425
ifctud,ok:=os.LookupEnv("CODER_TEST_USE_DOCKER");!ok||ctud!="1" {
424426
t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test")
425427
}
@@ -483,9 +485,8 @@ func TestDockerEnvInfoer(t *testing.T) {
483485
expectedUserShell:"/bin/bash",
484486
},
485487
} {
488+
//nolint:paralleltest // variable recapture no longer required
486489
t.Run(fmt.Sprintf("#%d",idx),func(t*testing.T) {
487-
t.Parallel()
488-
489490
// Start a container with the given image
490491
// and environment variables
491492
image:=strings.Split(tt.image,":")[0]

‎agent/agentcontainers/dcspec/dcspec_gen.go‎

Lines changed: 357 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package dcspec
2+
3+
//go:generate ./gen.sh
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# This script requires quicktype to be installed.
5+
if!command -v quicktype&>/dev/null;then
6+
echo"quicktype could not be found. Please install it to use this script:"
7+
echo">>> npm install -g quicktype"
8+
exit 1
9+
fi
10+
11+
DEST_FILENAME="dcspec_gen.go"
12+
SCRIPT_DIR=$(cd"$(dirname"${BASH_SOURCE[0]}")"&& pwd)
13+
DEST_PATH="${SCRIPT_DIR}/${DEST_FILENAME}"
14+
SCHEMA_SRC="https://raw.githubusercontent.com/devcontainers/spec/refs/heads/main/schemas/devContainer.base.schema.json"
15+
16+
# Location of the JSON schema for the devcontainer specification.
17+
TMPDIR=$(mktemp -d)
18+
trap'rm -rfv "$TMPDIR"' EXIT
19+
curl --fail --silent --show-error --location --output"${TMPDIR}/schema.json""${SCHEMA_SRC}"
20+
rm -f"${DEST_PATH}"
21+
quicktype \
22+
--src-lang schema \
23+
--lang go \
24+
--just-types-and-package \
25+
--top-level"DevContainer" \
26+
--out"${DEST_PATH}" \
27+
--package"dcspec" \
28+
"${TMPDIR}/schema.json"
29+
30+
# Add a header so that Go recognizes this as a generated file.
31+
sed -i'1s/^/\/\/ Code generated by quicktype. DO NOT EDIT.\n/'"${DEST_PATH}"

‎agent/agentcontainers/devcontainer_meta.go‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp