-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployImageApi.ts
More file actions
59 lines (51 loc) · 3.24 KB
/
deployImageApi.ts
File metadata and controls
59 lines (51 loc) · 3.24 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { callWithMaskHandling, createSubscriptionContext, type ExecuteActivityContext, type IActionContext, type ISubscriptionActionContext } from "@microsoft/vscode-azext-utils";
import { ImageSource, acrDomain } from "../../../constants";
import { type SetTelemetryProps } from "../../../telemetry/SetTelemetryProps";
import { type DeployImageApiTelemetryProps as TelemetryProps } from "../../../telemetry/commandTelemetryProps";
import { getDomainFromRegistryName, getRegistryFromAcrName } from "../../../utils/imageNameUtils";
import { pickContainerApp } from "../../../utils/pickItem/pickContainerApp";
import { type ImageSourceBaseContext } from "../imageSource/ImageSourceContext";
import { type ContainerRegistryImageSourceContext } from "../imageSource/containerRegistry/ContainerRegistryImageSourceContext";
import { deployImage } from "./deployImage";
// The interface of the command options passed to the Azure Container Apps extension's deployImageToAca command
// This interface is shared with the Docker extension (https://github.com/microsoft/vscode-docker)
interface DeployImageToAcaOptionsContract {
image: string;
registryName: string;
username?: string;
secret?: string;
}
export type DeployImageApiContext = ImageSourceBaseContext & ExecuteActivityContext & SetTelemetryProps<TelemetryProps>;
/**
* A command shared with the `vscode-docker` extension.
* It uses our old `deployImage` command flow which immediately tries to deploy the image to a container app without creating a draft.
* This command cannot be used to bundle template changes.
*/
export async function deployImageApi(context: IActionContext & Partial<ContainerRegistryImageSourceContext>, deployImageOptions: DeployImageToAcaOptionsContract): Promise<void> {
const node = await pickContainerApp(context);
const { subscription } = node;
Object.assign(context, { ...createSubscriptionContext(subscription), imageSource: ImageSource.ContainerRegistry }, deployImageOptions);
context.registryDomain = getDomainFromRegistryName(deployImageOptions.registryName);
if (context.registryDomain === acrDomain) {
context.registry = await getRegistryFromAcrName(<ISubscriptionActionContext>context, deployImageOptions.registryName);
}
// Mask sensitive data
if (deployImageOptions.secret) {
context.valuesToMask.push(deployImageOptions.secret);
}
if (deployImageOptions.username) {
context.valuesToMask.push(deployImageOptions.username);
}
context.valuesToMask.push(deployImageOptions.image);
if (deployImageOptions.secret) {
context.telemetry.properties.hasRegistrySecrets = 'true';
return callWithMaskHandling<void>(() => deployImage(context, node), deployImageOptions.secret);
} else {
context.telemetry.properties.hasRegistrySecrets = 'false';
return deployImage(context, node);
}
}