-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathRunStep.ts
More file actions
61 lines (53 loc) · 3.23 KB
/
RunStep.ts
File metadata and controls
61 lines (53 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { DockerBuildRequest as AcrDockerBuildRequest } from "@azure/arm-containerregistry";
import { AzExtFsExtra, GenericTreeItem } from "@microsoft/vscode-azext-utils";
import * as path from 'path';
import { type Progress } from "vscode";
import { activityFailContext, activityFailIcon } from "../../../../constants";
import { ExecuteActivityOutput, ExecuteActivityOutputStepBase } from "../../../../utils/activity/ExecuteActivityOutputStepBase";
import { createActivityChildContext } from "../../../../utils/activity/activityUtils";
import { localize } from "../../../../utils/localize";
import { BuildImageInAzureImageSourceContext } from "./BuildImageInAzureImageSourceContext";
export class RunStep extends ExecuteActivityOutputStepBase<BuildImageInAzureImageSourceContext> {
public priority: number = 440;
protected async executeCore(context: BuildImageInAzureImageSourceContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
// Need to keep the additional try wrapper here to execute finally, then we can catch any error that percolates up and display its output
try {
const runRequest: AcrDockerBuildRequest = {
type: 'DockerBuildRequest',
imageNames: [context.imageName],
isPushEnabled: true,
sourceLocation: context.uploadedSourceLocation,
platform: { os: context.os },
dockerFilePath: path.basename(context.dockerfilePath) /* Assume the dockerfile is always in the root of the source */
};
const building: string = localize('buildingImage', 'Building image...');
progress.report({ message: building });
context.run = await context.client.registries.beginScheduleRunAndWait(context.resourceGroupName, context.registryName, runRequest);
} finally {
if (await AzExtFsExtra.pathExists(context.tarFilePath)) {
await AzExtFsExtra.deleteResource(context.tarFilePath);
}
}
}
public shouldExecute(context: BuildImageInAzureImageSourceContext): boolean {
return !context.run;
}
protected createSuccessOutput(): ExecuteActivityOutput {
// Skip here, success will be output by the build image step
return {};
}
protected createFailOutput(context: BuildImageInAzureImageSourceContext): ExecuteActivityOutput {
return {
item: new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['runStep', activityFailContext]),
label: localize('runLabel', 'Build image "{0}" in registry "{1}"', context.imageName, context.registryName),
iconPath: activityFailIcon
}),
message: localize('runFail', 'Failed to build image "{0}" in registry "{1}".', context.imageName, context.registryName)
};
}
}