Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/test/workspace"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
Expand Down
57 changes: 47 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"publisher": "docker",
"categories": [
"Programming Languages",
"Linters"
"Linters",
"Debuggers"
],
"repository": {
"type": "git",
Expand All @@ -34,6 +35,10 @@
"title": "Scan for CVEs with Docker Scout",
"command": "docker.scout.imageScan",
"enablement": "(view == dockerImages || view == vscode-containers.views.images) && viewItem == image"
},
{
"title": "Build with Debugger",
"command": "docker.debug.editorContents"
}
],
"languages": [
Expand Down Expand Up @@ -67,21 +72,54 @@
"languages": [
"dockerfile"
],
"label": "Dockerfile Debug",
"label": "Docker: Build",
"configurationAttributes": {
"launch": {
"required": [
"dockerfile"
],
"required": [],
"properties": {
"dockerfile": {
"type": "string",
"description": "Path to a Dockerfile",
"default": "${workspaceFolder}/Dockerfile"
"description": "Relative path from the context to the dockerfile.",
"default": "Dockerfile"
},
"contextPath": {
"type": "string",
"description": "Path to the context.",
"default": "${workspaceFolder}"
},
"target": {
"type": "string",
"description": "Target build stage to build."
},
"args": {
"type": "array",
"description": "Arguments to pass to the build."
}
}
}
}
},
"initialConfigurations": [
{
"type": "dockerfile",
"request": "launch",
"name": "Docker: Build",
"dockerfile": "Dockerfile",
"contextPath": "${workspaceFolder}"
}
],
"configurationSnippets": [
{
"label": "Docker: Build",
"description": "A new configuration for debugging a user selected Dockerfile.",
"body": {
"type": "dockerfile",
"request": "launch",
"name": "Docker: Build",
"dockerfile": "${2:Dockerfile}",
"contextPath": "^\"\\${workspaceFolder}\""
}
}
]
}
],
"configuration": {
Expand All @@ -90,9 +128,8 @@
"docker.extension.enableBuildDebugging": {
"type": "boolean",
"description": "Enables build debugging. Note that changing this value requires a restart of Visual Studio Code to take effect.",
"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.",
"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.",
"default": false,
"scope": "application",
"tags": [
"experimental"
]
Expand Down
53 changes: 35 additions & 18 deletions src/dap/config.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import * as path from 'path';
import * as vscode from 'vscode';
import { getExtensionSetting } from '../utils/settings';

export const DebugEditorContentsCommandId = 'docker.debug.editorContents';

class DebugAdapterExecutableFactory
implements vscode.DebugAdapterDescriptorFactory
{
createDebugAdapterDescriptor(
session: vscode.DebugSession,
): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
const parent = path.dirname(session.configuration.dockerfile);
return new vscode.DebugAdapterExecutable(
'docker',
[
'buildx',
'dap',
'build',
'-f',
session.configuration.dockerfile,
parent,
],
{
cwd: parent,
env: { BUILDX_EXPERIMENTAL: '1' },
},
);
var args = ['buildx', 'dap', 'build'];
if (session.configuration?.args) {
args = args.concat(session.configuration?.args);
}

const options = {
cwd: session.workspaceFolder?.uri.path,
};

return new vscode.DebugAdapterExecutable('docker', args, options);
}
}

Expand All @@ -39,9 +34,10 @@ class DockerfileConfigurationProvider
const editor = vscode.window.activeTextEditor;
if (editor !== undefined && editor.document.languageId === 'dockerfile') {
config.type = 'dockerfile';
config.name = 'Debug Dockerfile';
config.name = 'Docker: Build';
config.request = 'launch';
config.dockerfile = editor.document.uri.fsPath;
config.contextPath = '${workspaceFolder}';
}
}
return config;
Expand Down Expand Up @@ -109,6 +105,27 @@ export function setupDebugging(ctx: vscode.ExtensionContext) {

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

ctx.subscriptions.push(
vscode.commands.registerCommand(
DebugEditorContentsCommandId,
async (resource: vscode.Uri) => {
let targetResource = resource;
if (!targetResource && vscode.window.activeTextEditor) {
targetResource = vscode.window.activeTextEditor.document.uri;
}
if (targetResource) {
vscode.debug.startDebugging(undefined, {
type: 'dockerfile',
name: 'Docker: Build',
request: 'launch',
dockerfile: targetResource.fsPath,
contextPath: '${workspaceFolder}',
});
}
},
),
);

ctx.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider(
'dockerfile',
Expand Down
15 changes: 15 additions & 0 deletions test/workspace/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG FOO="init"
ARG AAA="init"

FROM busybox AS build1
RUN echo hello > /hello

FROM busybox AS build2
ARG FOO
ARG AAA
RUN echo hi > /hi && cat /fail

FROM scratch
COPY --from=build1 /hello /
RUN cat fail > /
COPY --from=build2 /hi /