Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registries V2 #4021

Merged
merged 6 commits into from
Aug 8, 2023
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
46 changes: 41 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@
},
{
"command": "vscode-docker.registries.pullRepository",
"when": "view == dockerRegistries && viewItem =~ /Repository;/",
"when": "view == dockerRegistries && viewItem =~ /commonrepository/",
"group": "regs_repo_1_general@1"
},
{
Expand All @@ -501,17 +501,17 @@
},
{
"command": "vscode-docker.registries.pullImage",
"when": "view == dockerRegistries && viewItem =~ /Tag;/",
"when": "view == dockerRegistries && viewItem =~ /commontag/i",
"group": "regs_tag_1_general@1"
},
{
"command": "vscode-docker.registries.copyRemoteFullTag",
"when": "view == dockerRegistries && viewItem =~ /(DockerV2|DockerHubV2);Tag;/",
"when": "view == dockerRegistries && viewItem =~ /(dockerHubTag|registryV2Tag)/i",
"group": "regs_tag_1_general@2"
},
{
"command": "vscode-docker.registries.copyImageDigest",
"when": "view == dockerRegistries && viewItem =~ /DockerV2;Tag;/",
"when": "view == dockerRegistries && viewItem =~ /registryV2Tag/",
"group": "regs_tag_1_general@3"
},
{
Expand Down Expand Up @@ -551,7 +551,7 @@
},
{
"command": "vscode-docker.registries.disconnectRegistry",
"when": "view == dockerRegistries && viewItem =~ /RegistryProvider;/",
"when": "view == dockerRegistries && viewItem =~ /commonregistryroot/i && !(viewItem =~ /genericregistryrootv2/i)",
"group": "regs_yyy_destructive@1"
},
{
Expand Down Expand Up @@ -3031,9 +3031,11 @@
"@azure/storage-blob": "^12.14.0",
"@microsoft/compose-language-service": "^0.2.0",
"@microsoft/vscode-azext-azureappservice": "^1.0.2",
"@microsoft/vscode-azext-azureauth": "^1.1.2",
"@microsoft/vscode-azext-azureutils": "^1.1.5",
"@microsoft/vscode-azext-utils": "^1.2.2",
"@microsoft/vscode-container-client": "^0.1.0",
"@microsoft/vscode-docker-registries": "file:../vscode-docker-extensibility/packages/vscode-docker-registries/microsoft-vscode-docker-registries-0.0.1-alpha.tgz",
"dayjs": "^1.11.7",
"dockerfile-language-server-nodejs": "^0.10.2",
"fs-extra": "^11.1.1",
Expand Down
160 changes: 80 additions & 80 deletions src/commands/images/buildImage.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IActionContext, UserCancelledError } from "@microsoft/vscode-azext-utils";
import * as path from "path";
import * as vscode from "vscode";
import { ext } from "../../extensionVariables";
import { TaskCommandRunnerFactory } from "../../runtimes/runners/TaskCommandRunnerFactory";
import { getOfficialBuildTaskForDockerfile } from "../../tasks/TaskHelper";
import { getValidImageNameFromPath } from "../../utils/getValidImageName";
import { delay } from "../../utils/promiseUtils";
import { quickPickDockerFileItem } from "../../utils/quickPickFile";
import { quickPickWorkspaceFolder } from "../../utils/quickPickWorkspaceFolder";
import { selectBuildCommand } from "../selectCommandTemplate";
import { addImageTaggingTelemetry, getTagFromUserInput } from "./tagImage";

const tagRegex: RegExp = /\$\{tag\}/i;

export async function buildImage(context: IActionContext, dockerFileUri: vscode.Uri | undefined): Promise<void> {
if (!vscode.workspace.isTrusted) {
throw new UserCancelledError('enforceTrust');
}

const configOptions: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('docker');
const defaultContextPath = configOptions.get('imageBuildContextPath', '');

let rootFolder: vscode.WorkspaceFolder;
if (dockerFileUri) {
rootFolder = vscode.workspace.getWorkspaceFolder(dockerFileUri);
}

rootFolder = rootFolder || await quickPickWorkspaceFolder(context, vscode.l10n.t('To build Docker files you must first open a folder or workspace in VS Code.'));

const dockerFileItem = await quickPickDockerFileItem(context, dockerFileUri, rootFolder);
const task = await getOfficialBuildTaskForDockerfile(context, dockerFileItem.absoluteFilePath, rootFolder);

if (task) {
await vscode.tasks.executeTask(task);
} else {
const contextPath: string = defaultContextPath || dockerFileItem.relativeFolderPath;

const terminalCommand = await selectBuildCommand(
context,
rootFolder,
dockerFileItem.relativeFilePath,
contextPath
);

// Replace '${tag}' if needed. Tag is a special case because we don't want to prompt unless necessary, so must manually replace it.
if (tagRegex.test(terminalCommand.command)) {
const absFilePath: string = path.join(rootFolder.uri.fsPath, dockerFileItem.relativeFilePath);
const dockerFileKey = `buildTag_${absFilePath}`;
const prevImageName: string | undefined = ext.context.workspaceState.get(dockerFileKey);

// Get imageName based previous entries, else on name of subfolder containing the Dockerfile
const suggestedImageName = prevImageName || getValidImageNameFromPath(dockerFileItem.absoluteFolderPath, 'latest');

// Temporary work-around for vscode bug where valueSelection can be messed up if a quick pick is followed by a showInputBox
await delay(500);

addImageTaggingTelemetry(context, suggestedImageName, '.before');
const imageName: string = await getTagFromUserInput(context, suggestedImageName);
addImageTaggingTelemetry(context, imageName, '.after');

await ext.context.workspaceState.update(dockerFileKey, imageName);
terminalCommand.command = terminalCommand.command.replace(tagRegex, imageName);
}

const client = await ext.runtimeManager.getClient();
const taskCRF = new TaskCommandRunnerFactory({
taskName: client.displayName,
workspaceFolder: rootFolder,
focus: true,
});

await taskCRF.getCommandRunner()(terminalCommand);
}
}
// /*---------------------------------------------------------------------------------------------
// * Copyright (c) Microsoft Corporation. All rights reserved.
// * Licensed under the MIT License. See LICENSE.md in the project root for license information.
// *--------------------------------------------------------------------------------------------*/

// import { IActionContext, UserCancelledError } from "@microsoft/vscode-azext-utils";
// import * as path from "path";
// import * as vscode from "vscode";
// import { ext } from "../../extensionVariables";
// import { TaskCommandRunnerFactory } from "../../runtimes/runners/TaskCommandRunnerFactory";
// import { getOfficialBuildTaskForDockerfile } from "../../tasks/TaskHelper";
// import { getValidImageNameFromPath } from "../../utils/getValidImageName";
// import { delay } from "../../utils/promiseUtils";
// import { quickPickDockerFileItem } from "../../utils/quickPickFile";
// import { quickPickWorkspaceFolder } from "../../utils/quickPickWorkspaceFolder";
// import { selectBuildCommand } from "../selectCommandTemplate";
// import { addImageTaggingTelemetry, getTagFromUserInput } from "./tagImage";

// const tagRegex: RegExp = /\$\{tag\}/i;

// export async function buildImage(context: IActionContext, dockerFileUri: vscode.Uri | undefined): Promise<void> {
// if (!vscode.workspace.isTrusted) {
// throw new UserCancelledError('enforceTrust');
// }

// const configOptions: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('docker');
// const defaultContextPath = configOptions.get('imageBuildContextPath', '');

// let rootFolder: vscode.WorkspaceFolder;
// if (dockerFileUri) {
// rootFolder = vscode.workspace.getWorkspaceFolder(dockerFileUri);
// }

// rootFolder = rootFolder || await quickPickWorkspaceFolder(context, vscode.l10n.t('To build Docker files you must first open a folder or workspace in VS Code.'));

// const dockerFileItem = await quickPickDockerFileItem(context, dockerFileUri, rootFolder);
// const task = await getOfficialBuildTaskForDockerfile(context, dockerFileItem.absoluteFilePath, rootFolder);

// if (task) {
// await vscode.tasks.executeTask(task);
// } else {
// const contextPath: string = defaultContextPath || dockerFileItem.relativeFolderPath;

// const terminalCommand = await selectBuildCommand(
// context,
// rootFolder,
// dockerFileItem.relativeFilePath,
// contextPath
// );

// // Replace '${tag}' if needed. Tag is a special case because we don't want to prompt unless necessary, so must manually replace it.
// if (tagRegex.test(terminalCommand.command)) {
// const absFilePath: string = path.join(rootFolder.uri.fsPath, dockerFileItem.relativeFilePath);
// const dockerFileKey = `buildTag_${absFilePath}`;
// const prevImageName: string | undefined = ext.context.workspaceState.get(dockerFileKey);

// // Get imageName based previous entries, else on name of subfolder containing the Dockerfile
// const suggestedImageName = prevImageName || getValidImageNameFromPath(dockerFileItem.absoluteFolderPath, 'latest');

// // Temporary work-around for vscode bug where valueSelection can be messed up if a quick pick is followed by a showInputBox
// await delay(500);

// addImageTaggingTelemetry(context, suggestedImageName, '.before');
// const imageName: string = await getTagFromUserInput(context, suggestedImageName);
// addImageTaggingTelemetry(context, imageName, '.after');

// await ext.context.workspaceState.update(dockerFileKey, imageName);
// terminalCommand.command = terminalCommand.command.replace(tagRegex, imageName);
// }

// const client = await ext.runtimeManager.getClient();
// const taskCRF = new TaskCommandRunnerFactory({
// taskName: client.displayName,
// workspaceFolder: rootFolder,
// focus: true,
// });

// await taskCRF.getCommandRunner()(terminalCommand);
// }
// }
Loading