Commit 2d3f49e
authored
dev_container: Handle devcontainer.metadata label as JSON object or array (#53557)
Self-Review Checklist:
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable
## Details
- The [devcontainer CLI writes the `devcontainer.metadata` label as a
bare JSON object](devcontainers/cli#1054) when
there is only one metadata entry (e.g. docker-compose devcontainer with
a Dockerfile and no features)
- Zed's `deserialize_metadata` only accepted a JSON array, causing
deserialization to fail with `invalid type: map, expected a sequence`
- This made it impossible to attach to existing docker-compose
devcontainers created by the devcontainer CLI or VS Code
The fix tries parsing as an array first, then falls back to parsing as a
single object wrapped in a vec. This mirrors how the [devcontainer CLI
itself reads the
label](https://github.com/devcontainers/cli/blob/main/src/spec-node/imageMetadata.ts#L476-L493).
An upstream fix has also been submitted:
devcontainers/cli#1199
## Reproduction
1. Create a docker-compose devcontainer with a Dockerfile and no
features:
`.devcontainer/devcontainer.json`:
```json
{
"name": "repro",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"remoteUser": "root"
}
```
`.devcontainer/docker-compose.yml`:
```yaml
services:
app:
build:
context: .
dockerfile: Dockerfile
command: sleep infinity
volumes:
- ..:/workspace
```
`.devcontainer/Dockerfile`:
```dockerfile
FROM ubuntu:24.04
```
2. `devcontainer up --workspace-folder .`
3. Open the folder in Zed, fails with metadata deserialization error
Release Notes:
- Fixed attaching to a devcontainer that has a single metadata element
which was started with `devcontainer-cli`1 parent 5a9f825 commit 2d3f49e
1 file changed
Lines changed: 35 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
490 | 494 | | |
491 | | - | |
492 | | - | |
493 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
494 | 502 | | |
495 | 503 | | |
496 | 504 | | |
| |||
936 | 944 | | |
937 | 945 | | |
938 | 946 | | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
939 | 971 | | |
940 | 972 | | |
941 | 973 | | |
| |||
0 commit comments