Skip to content

Commit 0153b09

Browse files
authored
Add custom ActivityAttributes for deployWorkspaceProject (#894)
1 parent f2b368b commit 0153b09

File tree

5 files changed

+73
-14
lines changed

5 files changed

+73
-14
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@
850850
"@azure/storage-blob": "^12.4.1",
851851
"@microsoft/vscode-azext-azureutils": "^3.3.3",
852852
"@microsoft/vscode-azext-github": "^1.0.2",
853-
"@microsoft/vscode-azext-utils": "^3.1.1",
853+
"@microsoft/vscode-azext-utils": "^3.2.1",
854854
"@microsoft/vscode-azureresources-api": "^2.0.2",
855855
"buffer": "^6.0.3",
856856
"dayjs": "^1.11.3",

src/commands/deployWorkspaceProject/internal/deployWorkspaceProjectInternal.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,19 @@ export async function deployWorkspaceProjectInternal(
9494
const wizardContext: DeployWorkspaceProjectInternalContext = {
9595
...context,
9696
...activityContext,
97-
...startingConfiguration
97+
...startingConfiguration,
98+
activityAttributes: {
99+
description: `Takes a workspace project with a Dockerfile and deploys it to an Azure Container App.
100+
Automatically creates any required resources (resource group, managed environment, container registry, container app, log analytics workspace).
101+
Supports single repo and monorepo, with deployment settings saved and reused via local VS Code settings (.vscode/settings.json).
102+
Deployment settings are saved under "containerApps.deploymentConfigurations".
103+
Deployment is agnostic to project runtime and language.`,
104+
troubleshooting: [
105+
`When ACR build errors are present, try to inspect the Dockerfile and ACR build logs.
106+
When an error is related to the Dockerfile, offer to make direct fixes for the user.
107+
If the Dockerfile and project dependencies don't match, focus on updating the Dockerfile to reflect the project, not the other way around.`
108+
],
109+
},
98110
};
99111

100112
const promptSteps: AzureWizardPromptStep<DeployWorkspaceProjectInternalContext>[] = [

src/commands/image/imageSource/buildImageInAzure/BuildImageStep.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { sendRequestWithTimeout, type AzExtPipelineResponse } from "@microsoft/vscode-azext-azureutils";
7-
import { ActivityChildItem, ActivityChildType, AzureWizardExecuteStep, activityFailContext, activityFailIcon, activityProgressContext, activityProgressIcon, activitySuccessContext, activitySuccessIcon, createContextValue, nonNullProp, nonNullValue, nonNullValueAndProp, type ActivityChildItemOptions, type ExecuteActivityOutput } from "@microsoft/vscode-azext-utils";
7+
import { ActivityChildItem, ActivityChildType, AzureWizardExecuteStep, activityFailContext, activityFailIcon, activityProgressContext, activityProgressIcon, activitySuccessContext, activitySuccessIcon, createContextValue, nonNullProp, nonNullValue, nonNullValueAndProp, type ActivityChildItemOptions, type ExecuteActivityOutput, type LogActivityAttributes } from "@microsoft/vscode-azext-utils";
88
import { ThemeColor, ThemeIcon, TreeItemCollapsibleState, window, type MessageItem } from "vscode";
99
import { acrDomain } from "../../../../constants";
1010
import { localize } from "../../../../utils/localize";
@@ -107,6 +107,16 @@ export class BuildImageStep<T extends BuildImageInAzureImageSourceContext> exten
107107
});
108108
return Promise.resolve([buildImageLogsItem]);
109109
};
110+
111+
const logs: LogActivityAttributes = {
112+
name: `ACR Build Logs - ${this.acrBuildError.name}`,
113+
description: 'Build logs are provided by Azure Container Registry (ACR) after a failed build. The build was attempted on an uploaded project using a Dockerfile, which ACR followed to try and build the image.',
114+
content: this.acrBuildError.content,
115+
};
116+
117+
context.activityAttributes ??= {};
118+
context.activityAttributes.logs ??= [];
119+
context.activityAttributes.logs.push(logs);
110120
}
111121

112122
return {

src/commands/image/imageSource/buildImageInAzure/DockerfileItemStep.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,54 @@
33
* Licensed under the MIT License. See License.md in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { AzureWizardPromptStep, nonNullValue } from '@microsoft/vscode-azext-utils';
6+
import { AzExtFsExtra, AzureWizardPromptStep, nonNullValue, type FileActivityAttributes } from '@microsoft/vscode-azext-utils';
77
import { dockerFilePick, dockerfileGlobPattern } from "../../../../constants";
88
import { selectWorkspaceFile } from "../../../../utils/workspaceUtils";
99
import { type BuildImageInAzureImageSourceContext } from './BuildImageInAzureImageSourceContext';
1010

11-
export class DockerfileItemStep extends AzureWizardPromptStep<BuildImageInAzureImageSourceContext> {
12-
public async prompt(context: BuildImageInAzureImageSourceContext): Promise<void> {
11+
const dockerfileAttributeName: string = 'Dockerfile';
12+
13+
export class DockerfileItemStep<T extends BuildImageInAzureImageSourceContext> extends AzureWizardPromptStep<T> {
14+
public async configureBeforePrompt(context: T): Promise<void> {
15+
if (context.dockerfilePath) {
16+
await this.addDockerfileAttributes(context, context.dockerfilePath);
17+
}
18+
}
19+
20+
public async prompt(context: T): Promise<void> {
1321
context.dockerfilePath = nonNullValue(await selectWorkspaceFile(context, dockerFilePick, { filters: {}, autoSelectIfOne: true }, `**/${dockerfileGlobPattern}`));
22+
await this.addDockerfileAttributes(context, context.dockerfilePath);
1423
}
1524

16-
public shouldPrompt(context: BuildImageInAzureImageSourceContext): boolean {
25+
public shouldPrompt(context: T): boolean {
1726
return !context.dockerfilePath;
1827
}
28+
29+
private async addDockerfileAttributes(context: T, dockerfilePath: string): Promise<void> {
30+
if (context.activityAttributes?.files?.some(f => f.path === dockerfilePath)) {
31+
// If this dockerfile already exists in activity attributes, don't add it again
32+
return;
33+
}
34+
35+
const dockerfile: FileActivityAttributes = {
36+
name: dockerfileAttributeName,
37+
description: 'A Dockerfile from the user\'s VS Code workspace that was used to build the project.',
38+
path: dockerfilePath,
39+
content: await AzExtFsExtra.readFile(dockerfilePath),
40+
};
41+
42+
context.activityAttributes ??= {};
43+
context.activityAttributes.files ??= [];
44+
context.activityAttributes.files.push(dockerfile);
45+
}
46+
47+
public undo(context: T): void {
48+
const files: FileActivityAttributes[] = context.activityAttributes?.files ?? [];
49+
if (files[files.length - 1]) {
50+
const lastFile = files[files.length - 1];
51+
if (lastFile.name === dockerfileAttributeName) {
52+
context.activityAttributes?.files?.pop();
53+
}
54+
}
55+
}
1956
}

0 commit comments

Comments
 (0)