Skip to content

Commit aac4f3a

Browse files
authored
Create container on flex app creation and allow flex nodes to be passed into deploy (#4088)
* Create a container at time of flex app creation * Add flex context for deploy * Remove extra break
1 parent 65810d6 commit aac4f3a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/commands/createFunctionApp/FunctionAppCreateStep.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { type NameValuePair, type Site, type SiteConfig, type WebSiteManagementClient } from '@azure/arm-appservice';
77
import { createHttpHeaders, createPipelineRequest, type RequestBodyType } from '@azure/core-rest-pipeline';
8+
import { BlobServiceClient } from '@azure/storage-blob';
89
import { ParsedSite, WebsiteOS, type CustomLocation, type IAppServiceWizardContext } from '@microsoft/vscode-azext-azureappservice';
910
import { LocationListStep, createGenericClient, type AzExtPipelineResponse, type AzExtRequestPrepareOptions } from '@microsoft/vscode-azext-azureutils';
1011
import { AzureWizardExecuteStep, parseError, randomUtils } from '@microsoft/vscode-azext-utils';
@@ -245,6 +246,9 @@ export class FunctionAppCreateStep extends AzureWizardExecuteStep<IFunctionAppWi
245246
const client = await createGenericClient(context, context);
246247
const result = await client.sendRequest(createPipelineRequest(options)) as AzExtPipelineResponse;
247248
if (result && result.status >= 200 && result.status < 300) {
249+
const site = result.parsedBody as Site & { properties: FlexFunctionAppProperties };
250+
const storageConnectionString: string = (await getStorageConnectionString(context)).connectionString;
251+
await tryCreateStorageContainer(site, storageConnectionString);
248252
const client: WebSiteManagementClient = await createWebSiteClient(context);
249253
// the payload for the new API version "2023-12-01" is incompatiable with our current SiteClient so get the old payload
250254
try {
@@ -275,6 +279,18 @@ function getSiteKind(context: IAppServiceWizardContext): string {
275279
return kind;
276280
}
277281

282+
// storage container is needed for flex deployment, but it is not created automatically
283+
async function tryCreateStorageContainer(site: Site & { properties: FlexFunctionAppProperties }, storageConnectionString: string): Promise<void> {
284+
const blobClient = BlobServiceClient.fromConnectionString(storageConnectionString);
285+
const containerName = site.properties?.functionAppConfig?.deployment.storage.value.split('/').pop();
286+
if (containerName) {
287+
const client = blobClient.getContainerClient(containerName);
288+
if (!await client.exists()) {
289+
await blobClient.createContainer(containerName);
290+
}
291+
}
292+
}
293+
278294
type FlexFunctionAppProperties = {
279295
containerSize?: number,
280296
sku?: 'FlexConsumption',

src/commands/deploy/deploy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ async function deploy(actionContext: IActionContext, arg1: vscode.Uri | string |
6161

6262
if (treeUtils.isAzExtTreeItem(arg1)) {
6363
if (!arg1.contextValue.match(ResolvedFunctionAppResource.pickSlotContextValue) &&
64-
!arg1.contextValue.match(ResolvedFunctionAppResource.productionContextValue)) {
64+
!arg1.contextValue.match(ResolvedFunctionAppResource.productionContextValue) &&
65+
!arg1.contextValue.match(ResolvedFunctionAppResource.flexContextValue)) {
6566
// if the user uses the deploy button, it's possible for the local project node to be passed in, so we should reset it to undefined
6667
arg1 = undefined;
6768
}

src/tree/ResolvedFunctionAppResource.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class ResolvedFunctionAppResource extends ResolvedFunctionAppBase impleme
5555
public static pickSlotContextValue: RegExp = new RegExp(/azFuncSlot(?!s)/);
5656
public static productionContextValue: string = 'azFuncProductionSlot';
5757
public static slotContextValue: string = 'azFuncSlot';
58+
public static flexContextValue: string = 'azFuncFlex';
5859

5960
private _isFlex: boolean;
6061

@@ -69,7 +70,7 @@ export class ResolvedFunctionAppResource extends ResolvedFunctionAppBase impleme
6970
this.contextValuesToAdd = [];
7071
this._isFlex = !!isFlex;
7172
if (this._isFlex) {
72-
this.contextValuesToAdd.push('azFuncFlex');
73+
this.contextValuesToAdd.push(ResolvedFunctionAppResource.flexContextValue);
7374
} else if (this.site.isSlot) {
7475
this.contextValuesToAdd.push(ResolvedFunctionAppResource.slotContextValue);
7576
} else {

0 commit comments

Comments
 (0)