Skip to content

Commit a675b88

Browse files
committed
debugger: update debugger components
Debugger options have been updated to reflect the current version on master more closely. The names have been renamed to `Docker: Build` instead of `Dockerfile Debug`. The reason for this is to make the naming more consistent and make it so the bake target could be called `Docker: Bake`. Initial configurations and configuration snippets now more closely align with the default attributes most projects should expect. The vscode extension host debugging now uses `test/workspace` as the workspace folder and included a default dockerfile that can be used for testing debugging. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
1 parent bb084fb commit a675b88

File tree

4 files changed

+101
-28
lines changed

4 files changed

+101
-28
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"type": "extensionHost",
1111
"request": "launch",
1212
"args": [
13-
"--extensionDevelopmentPath=${workspaceFolder}"
13+
"--extensionDevelopmentPath=${workspaceFolder}",
14+
"${workspaceFolder}/test/workspace"
1415
],
1516
"outFiles": [
1617
"${workspaceFolder}/dist/**/*.js"

package.json

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"publisher": "docker",
1212
"categories": [
1313
"Programming Languages",
14-
"Linters"
14+
"Linters",
15+
"Debuggers"
1516
],
1617
"repository": {
1718
"type": "git",
@@ -34,6 +35,12 @@
3435
"title": "Scan for CVEs with Docker Scout",
3536
"command": "docker.scout.imageScan",
3637
"enablement": "(view == dockerImages || view == vscode-containers.views.images) && viewItem == image"
38+
},
39+
{
40+
"title": "Build with Debugger",
41+
"command": "docker.debug.editorContents",
42+
"enablement": "!inDebugMode",
43+
"icon": "$(debug-alt)"
3744
}
3845
],
3946
"languages": [
@@ -67,21 +74,54 @@
6774
"languages": [
6875
"dockerfile"
6976
],
70-
"label": "Dockerfile Debug",
77+
"label": "Docker: Build",
7178
"configurationAttributes": {
7279
"launch": {
73-
"required": [
74-
"dockerfile"
75-
],
80+
"required": [],
7681
"properties": {
7782
"dockerfile": {
7883
"type": "string",
79-
"description": "Path to a Dockerfile",
80-
"default": "${workspaceFolder}/Dockerfile"
84+
"description": "Relative path from the context to the dockerfile.",
85+
"default": "Dockerfile"
86+
},
87+
"contextPath": {
88+
"type": "string",
89+
"description": "Path to the context.",
90+
"default": "${workspaceFolder}"
91+
},
92+
"target": {
93+
"type": "string",
94+
"description": "Target build stage to build."
95+
},
96+
"args": {
97+
"type": "array",
98+
"description": "Arguments to pass to the build."
8199
}
82100
}
83101
}
84-
}
102+
},
103+
"initialConfigurations": [
104+
{
105+
"type": "dockerfile",
106+
"request": "launch",
107+
"name": "Docker: Build",
108+
"dockerfile": "Dockerfile",
109+
"contextPath": "${workspaceFolder}"
110+
}
111+
],
112+
"configurationSnippets": [
113+
{
114+
"label": "Docker: Build",
115+
"description": "A new configuration for debugging a user selected Dockerfile.",
116+
"body": {
117+
"type": "dockerfile",
118+
"request": "launch",
119+
"name": "Docker: Build",
120+
"dockerfile": "${2:Dockerfile}",
121+
"contextPath": "^\"\\${workspaceFolder}\""
122+
}
123+
}
124+
]
85125
}
86126
],
87127
"configuration": {
@@ -90,9 +130,8 @@
90130
"docker.extension.enableBuildDebugging": {
91131
"type": "boolean",
92132
"description": "Enables build debugging. Note that changing this value requires a restart of Visual Studio Code to take effect.",
93-
"markdownDescription": "Enable Compose editing features from the Docker DX extension. Note that changing this value requires a **restart** of Visual Studio Code to take effect.",
133+
"markdownDescription": "Enable build debugging features from the Docker DX extension. Note that changing this value requires a **restart** of Visual Studio Code to take effect.",
94134
"default": false,
95-
"scope": "application",
96135
"tags": [
97136
"experimental"
98137
]

src/dap/config.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@ import * as path from 'path';
22
import * as vscode from 'vscode';
33
import { getExtensionSetting } from '../utils/settings';
44

5+
export const DebugEditorContentsCommandId = 'docker.debug.editorContents';
6+
57
class DebugAdapterExecutableFactory
68
implements vscode.DebugAdapterDescriptorFactory
79
{
810
createDebugAdapterDescriptor(
911
session: vscode.DebugSession,
1012
): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
11-
const parent = path.dirname(session.configuration.dockerfile);
12-
return new vscode.DebugAdapterExecutable(
13-
'docker',
14-
[
15-
'buildx',
16-
'dap',
17-
'build',
18-
'-f',
19-
session.configuration.dockerfile,
20-
parent,
21-
],
22-
{
23-
cwd: parent,
24-
env: { BUILDX_EXPERIMENTAL: '1' },
25-
},
26-
);
13+
var args = ['buildx', 'dap', 'build'];
14+
if (session.configuration?.args) {
15+
args = args.concat(session.configuration?.args);
16+
}
17+
18+
const options = {
19+
cwd: session.workspaceFolder?.uri.path,
20+
};
21+
22+
return new vscode.DebugAdapterExecutable('docker', args, options);
2723
}
2824
}
2925

@@ -39,9 +35,10 @@ class DockerfileConfigurationProvider
3935
const editor = vscode.window.activeTextEditor;
4036
if (editor !== undefined && editor.document.languageId === 'dockerfile') {
4137
config.type = 'dockerfile';
42-
config.name = 'Debug Dockerfile';
38+
config.name = 'Docker: Build';
4339
config.request = 'launch';
4440
config.dockerfile = editor.document.uri.fsPath;
41+
config.contextPath = '${workspaceFolder}';
4542
}
4643
}
4744
return config;
@@ -109,6 +106,27 @@ export function setupDebugging(ctx: vscode.ExtensionContext) {
109106

110107
let channel = vscode.window.createOutputChannel('Dockerfile Debug', 'log');
111108

109+
ctx.subscriptions.push(
110+
vscode.commands.registerCommand(
111+
DebugEditorContentsCommandId,
112+
async (resource: vscode.Uri) => {
113+
let targetResource = resource;
114+
if (!targetResource && vscode.window.activeTextEditor) {
115+
targetResource = vscode.window.activeTextEditor.document.uri;
116+
}
117+
if (targetResource) {
118+
vscode.debug.startDebugging(undefined, {
119+
type: 'dockerfile',
120+
name: 'Docker: Build',
121+
request: 'launch',
122+
dockerfile: targetResource.fsPath,
123+
contextPath: '${workspaceFolder}',
124+
});
125+
}
126+
},
127+
),
128+
);
129+
112130
ctx.subscriptions.push(
113131
vscode.debug.registerDebugConfigurationProvider(
114132
'dockerfile',

test/workspace/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG FOO="init"
2+
ARG AAA="init"
3+
4+
FROM busybox AS build1
5+
RUN echo hello > /hello
6+
7+
FROM busybox AS build2
8+
ARG FOO
9+
ARG AAA
10+
RUN echo hi > /hi && cat /fail
11+
12+
FROM scratch
13+
COPY --from=build1 /hello /
14+
RUN cat fail > /
15+
COPY --from=build2 /hi /

0 commit comments

Comments
 (0)