Skip to content

Commit 1c9350d

Browse files
authored
Integrate with the Buildx Dockerfile debugger (#27)
Buildx implements DAP to allow users to debug Dockerfile builds. <img width="1666" height="842" alt="image" src="https://github.com/user-attachments/assets/9cda3d58-6d04-48b4-a204-9009a6264908" /> <img width="3106" height="1319" alt="image" src="https://github.com/user-attachments/assets/88092f52-d251-4090-acca-0792f01fbe58" /> --------- Signed-off-by: Remy Suen <remy.suen@docker.com>
1 parent bc4577c commit 1c9350d

File tree

6 files changed

+265
-37
lines changed

6 files changed

+265
-37
lines changed

Cargo.lock

Lines changed: 58 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ publish = false
88
crate-type = ["cdylib"]
99

1010
[dependencies]
11+
serde = {version = "1.0", features = ["derive"]}
12+
serde_json = "1.0"
1113
zed_extension_api = "0.7.0"

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,34 @@ To support matching filenames other than `Dockerfile` you can add [`file_types`]
1010
```json
1111
{
1212
"file_types": {
13-
"Dockerfile": [ "Dockerfile.*" ]
13+
"Dockerfile": ["Dockerfile.*"]
1414
}
1515
}
1616
```
17+
18+
## Debugging
19+
20+
The extension supports debugging Dockerfile builds with [Buildx](https://github.com/docker/buildx). The minimal required version of Buildx is v0.28.0. To get Buildx, we recommend installing or updating [Docker Desktop](https://docs.docker.com/install/). You may alternatively install Buildx manually by following the instructions [here](https://github.com/docker/buildx?tab=readme-ov-file#manual-download).
21+
22+
You can validate your Buildx installation by running `BUILDX_EXPERIMENTAL=1 docker buildx dap`.
23+
24+
You can create a debug configuration by modifying your project's `.zed/debug.json`.
25+
26+
```json
27+
{
28+
"label": "Docker: Build", // required, configurable
29+
"adapter": "buildx-dockerfile", // required, must not be modified
30+
"request": "launch", // required, must not be modified
31+
"contextPath": "/home/username/worktree", // optional, defaults to ${ZED_WORKTREE_ROOT}
32+
"dockerfile": "/home/username/worktree/Dockerfile", // optional, defaults to ${ZED_WORKTREE_ROOT}/Dockerfile
33+
"target": "test", // optional, should be a build stage in the Dockerfile
34+
"stopOnEntry": true, // if the debugger should suspend on the first line, defaults to false
35+
"args": [
36+
// additional arguments for the build command
37+
"--build-arg",
38+
"NODE_ENV=development"
39+
]
40+
}
41+
```
42+
43+
While a build has been suspended, you can evaluate `exec` to open a shell into the Docker image that has been built up to that point in time.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"type": "object",
3+
"required": ["request"],
4+
"properties": {
5+
"dockerfile": {
6+
"type": "string",
7+
"description": "The absolute path to the Dockerfile to debug",
8+
"default": "${ZED_WORKTREE_ROOT}/Dockerfile"
9+
},
10+
"contextPath": {
11+
"type": "string",
12+
"description": "Path to the context of the Docker build",
13+
"default": "${ZED_WORKTREE_ROOT}"
14+
},
15+
"request": {
16+
"type": "string",
17+
"description": "The type of debug session to run, must be launch",
18+
"enum": ["launch"],
19+
"default": "launch"
20+
},
21+
"target": {
22+
"type": "string",
23+
"description": "The build stage target to build"
24+
},
25+
"stopOnEntry": {
26+
"type": "boolean",
27+
"description": "Whether the build should stop in the beginning"
28+
},
29+
"args": {
30+
"type": "array",
31+
"description": "Command line arguments to pass to the build command",
32+
"items": {
33+
"type": "string"
34+
},
35+
"default": []
36+
}
37+
}
38+
}

extension.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ language = "Dockerfile"
1313
[grammars.dockerfile]
1414
repository = "https://github.com/camdencheek/tree-sitter-dockerfile"
1515
commit = "868e44ce378deb68aac902a9db68ff82d2299dd0"
16+
17+
[debug_adapters.buildx-dockerfile]
18+
schema_path = "./debug_adapter_schemas/buildx-dockerfile.json"

0 commit comments

Comments
 (0)