Skip to content

Commit 4e0b461

Browse files
authored
Expand image source selection for creating Container Apps (#273)
1 parent e33e848 commit 4e0b461

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

src/commands/createContainerApp/IContainerAppContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
import { IResourceGroupWizardContext } from '@microsoft/vscode-azext-azureutils';
77
import { ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
8+
import { ImageSourceValues } from '../../constants';
89
import { ContainerAppModel } from "../../tree/ContainerAppItem";
910
import { IDeployImageContext } from '../deployImage/IDeployImageContext';
1011
export interface IContainerAppContext extends IResourceGroupWizardContext, IDeployImageContext {
1112
managedEnvironmentId: string;
1213
newContainerAppName?: string;
14+
imageSource?: ImageSourceValues;
1315

1416
enableIngress?: boolean;
1517
enableExternal?: boolean;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { AzureWizardPromptStep, IAzureQuickPickItem, IWizardOptions } from "@microsoft/vscode-azext-utils";
7+
import { ImageSource, ImageSourceValues } from "../../constants";
8+
import { localize } from "../../utils/localize";
9+
import { ContainerRegistryListStep } from "../deployImage/ContainerRegistryListStep";
10+
import { EnvironmentVariablesListStep } from "./EnvironmentVariablesListStep";
11+
import { IContainerAppContext } from './IContainerAppContext';
12+
13+
export class ImageSourceListStep extends AzureWizardPromptStep<IContainerAppContext> {
14+
public async prompt(context: IContainerAppContext): Promise<void> {
15+
const imageSourceLabels: string[] = [
16+
localize('quickStartImage', 'Use quickstart image'),
17+
localize('externalRegistry', 'Use existing image'),
18+
// localize('buildFromProject', 'Build from project'),
19+
];
20+
21+
const placeHolder: string = localize('imageBuildSourcePrompt', 'Select an image source for the container app');
22+
const picks: IAzureQuickPickItem<ImageSourceValues | undefined>[] = [
23+
{ label: imageSourceLabels[0], data: ImageSource.QuickStartImage, suppressPersistence: true },
24+
{ label: imageSourceLabels[1], data: ImageSource.ExternalRegistry, suppressPersistence: true },
25+
// { label: imageSourceLabels[2], data: undefined, suppressPersistence: true },
26+
];
27+
28+
context.imageSource = (await context.ui.showQuickPick(picks, { placeHolder })).data;
29+
}
30+
31+
public shouldPrompt(context: IContainerAppContext): boolean {
32+
return !context.imageSource;
33+
}
34+
35+
public async getSubWizard(context: IContainerAppContext): Promise<IWizardOptions<IContainerAppContext> | undefined> {
36+
const promptSteps: AzureWizardPromptStep<IContainerAppContext>[] = [];
37+
38+
switch (context.imageSource) {
39+
case ImageSource.QuickStartImage:
40+
// Todo: @mmott
41+
throw new Error('Not implemented yet');
42+
case ImageSource.ExternalRegistry:
43+
promptSteps.push(new ContainerRegistryListStep(), new EnvironmentVariablesListStep());
44+
break;
45+
default:
46+
// Todo: Steps that lead to additional 'Build from project' options
47+
}
48+
49+
return { promptSteps };
50+
}
51+
}

src/commands/createContainerApp/createContainerApp.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import { ManagedEnvironmentItem } from "../../tree/ManagedEnvironmentItem";
1212
import { createActivityContext } from "../../utils/activityUtils";
1313
import { localize } from "../../utils/localize";
1414
import { containerAppEnvironmentExperience } from "../../utils/pickContainerApp";
15-
import { ContainerRegistryListStep } from "../deployImage/ContainerRegistryListStep";
1615
import { ContainerAppCreateStep } from "./ContainerAppCreateStep";
1716
import { ContainerAppNameStep } from "./ContainerAppNameStep";
1817
import { EnableIngressStep } from "./EnableIngressStep";
19-
import { EnvironmentVariablesListStep } from "./EnvironmentVariablesListStep";
2018
import { IContainerAppContext, IContainerAppWithActivityContext } from "./IContainerAppContext";
19+
import { ImageSourceListStep } from "./ImageSourceListStep";
2120
import { showContainerAppCreated } from "./showContainerAppCreated";
2221

2322
export async function createContainerApp(context: IActionContext & Partial<ICreateChildImplContext> & Partial<IContainerAppContext>, node?: ManagedEnvironmentItem): Promise<ContainerAppItem> {
@@ -36,8 +35,7 @@ export async function createContainerApp(context: IActionContext & Partial<ICrea
3635

3736
const promptSteps: AzureWizardPromptStep<IContainerAppWithActivityContext>[] = [
3837
new ContainerAppNameStep(),
39-
new ContainerRegistryListStep(),
40-
new EnvironmentVariablesListStep(),
38+
new ImageSourceListStep(),
4139
new EnableIngressStep(),
4240
];
4341

src/constants.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ export enum ScaleRuleTypes {
3636
Queue = "Azure queue"
3737
}
3838

39+
export enum ImageSource {
40+
/*
41+
* Uses the default hello-world image with preset configurations
42+
*/
43+
QuickStartImage = 'quickStartImage',
44+
/*
45+
* Use an image stored in ACR or a third party registry
46+
*/
47+
ExternalRegistry = 'externalRegistry',
48+
/*
49+
* Build the image from your project locally using Docker (reqs. Dockerfile)
50+
*/
51+
LocalDockerBuild = 'localDockerBuild',
52+
/*
53+
* Build the image from your project remotely using ACR (reqs. Dockerfile)
54+
*/
55+
RemoteAcrBuild = 'remoteAcrBuild'
56+
}
57+
58+
export type ImageSourceValues = typeof ImageSource[keyof typeof ImageSource];
59+
3960
export const acrDomain = 'azurecr.io';
4061
export const dockerHubDomain = 'docker.io';
4162
export const dockerHubRegistry = 'index.docker.io';

0 commit comments

Comments
 (0)