Add support for creating functions projects with dockerfiles (#3929)

* Add support for creating dockerfile projects

* change to javascript

* Refactor

* requested changes
This commit is contained in:
Megan Mott 2024-02-16 13:51:36 -08:00 коммит произвёл GitHub
Родитель c433add755
Коммит 040dbb99ff
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
6 изменённых файлов: 52 добавлений и 3 удалений

Просмотреть файл

@ -181,6 +181,12 @@
},
"enablement": "!virtualWorkspace"
},
{
"command": "azureFunctions.createNewProjectWithDockerfile",
"title": "%azureFunctions.createNewProjectWithDockerfile%",
"category": "Azure Functions",
"enablement": "!virtualWorkspace"
},
{
"command": "azureFunctions.createSlot",
"title": "%azureFunctions.createSlot%",
@ -366,6 +372,10 @@
"command": "azureFunctions.createNewProject",
"group": "1_projects@2"
},
{
"command": "azureFunctions.createNewProjectWithDockerfile",
"group": "1_projects@3"
},
{
"command": "azureFunctions.deploy",
"group": "2_deploy@1"

Просмотреть файл

@ -18,6 +18,7 @@
"azureFunctions.createFunctionAppAdvanced": "Create Function App in Azure... (Advanced)",
"azureFunctions.createFunctionAppDetail": "For serverless, event driven apps and automation.",
"azureFunctions.createNewProject": "Create New Project...",
"azureFunctions.createNewProjectWithDockerfile": "Create New Containerized Project...",
"azureFunctions.createPythonVenv": "Create a virtual environment when creating a new Python project.",
"azureFunctions.createSlot": "Create Slot...",
"azureFunctions.deleteFunction": "Delete Function...",

Просмотреть файл

@ -3,13 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizard, type IActionContext } from '@microsoft/vscode-azext-utils';
import { AzureWizard, UserCancelledError, type IActionContext } from '@microsoft/vscode-azext-utils';
import { window } from 'vscode';
import { latestGAVersion, tryParseFuncVersion } from '../../FuncVersion';
import { funcVersionSetting, projectLanguageSetting, projectOpenBehaviorSetting, projectTemplateKeySetting, type ProjectLanguage } from '../../constants';
import { ext } from '../../extensionVariables';
import { addLocalFuncTelemetry } from '../../funcCoreTools/getLocalFuncCoreToolsVersion';
import { tryGetLocalFuncVersion } from '../../funcCoreTools/tryGetLocalFuncVersion';
import { validateFuncCoreToolsInstalled } from '../../funcCoreTools/validateFuncCoreToolsInstalled';
import { localize } from '../../localize';
import { getGlobalSetting, getWorkspaceSetting } from '../../vsCodeConfig/settings';
import type * as api from '../../vscode-azurefunctions.api';
@ -18,6 +19,7 @@ import { FolderListStep } from './FolderListStep';
import { NewProjectLanguageStep } from './NewProjectLanguageStep';
import { OpenBehaviorStep } from './OpenBehaviorStep';
import { OpenFolderStep } from './OpenFolderStep';
import { CreateDockerfileProjectStep } from './dockerfileSteps/CreateDockerfileProjectStep';
/**
* @deprecated Use AzureFunctionsExtensionApi.createFunction instead
@ -54,6 +56,13 @@ export async function createNewProjectInternal(context: IActionContext, options:
const wizardContext: Partial<IFunctionWizardContext> & IActionContext = Object.assign(context, options, { language, version: tryParseFuncVersion(version), projectTemplateKey });
const optionalExecuteStep = options.executeStep;
if (optionalExecuteStep instanceof CreateDockerfileProjectStep) {
const message: string = localize('installFuncTools', 'You must have the Azure Functions Core Tools installed to run this command.');
if (!await validateFuncCoreToolsInstalled(context, message)) {
throw new UserCancelledError('validateFuncCoreToolsInstalled');
}
}
if (options.folderPath) {
FolderListStep.setProjectPath(wizardContext, options.folderPath);
}
@ -70,6 +79,7 @@ export async function createNewProjectInternal(context: IActionContext, options:
promptSteps: [new FolderListStep(), new NewProjectLanguageStep(options.templateId, options.functionSettings), new OpenBehaviorStep()],
executeSteps: optionalExecuteStep ? [optionalExecuteStep, new OpenFolderStep()] : [new OpenFolderStep()]
});
await wizard.prompt();
await wizard.execute();

Просмотреть файл

@ -0,0 +1,26 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ext } from "@microsoft/vscode-azext-serviceconnector";
import { AzureWizardExecuteStep, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
import { cpUtils } from "../../../utils/cpUtils";
import { type IFunctionWizardContext } from "../../createFunction/IFunctionWizardContext";
export class CreateDockerfileProjectStep extends AzureWizardExecuteStep<IFunctionWizardContext>{
public priority: number = 100;
public async execute(context: IFunctionWizardContext): Promise<void> {
let language = nonNullValueAndProp(context, 'language').toLowerCase();
if (language === 'c#') {
language = 'csharp';
}
await cpUtils.executeCommand(ext.outputChannel, nonNullValueAndProp(context, 'projectPath'), "func", "init", "--worker-runtime", language, "--docker");
}
public shouldExecute(): boolean {
return true;
}
}

Просмотреть файл

@ -25,7 +25,8 @@ import { copyFunctionUrl } from './copyFunctionUrl';
import { createChildNode } from './createChildNode';
import { createFunctionFromCommand } from './createFunction/createFunction';
import { createFunctionApp, createFunctionAppAdvanced } from './createFunctionApp/createFunctionApp';
import { createNewProjectFromCommand } from './createNewProject/createNewProject';
import { createNewProjectFromCommand, createNewProjectInternal } from './createNewProject/createNewProject';
import { CreateDockerfileProjectStep } from './createNewProject/dockerfileSteps/CreateDockerfileProjectStep';
import { createSlot } from './createSlot';
import { deleteFunction } from './deleteFunction';
import { deleteFunctionApp } from './deleteFunctionApp';
@ -79,6 +80,7 @@ export function registerCommands(): void {
registerCommandWithTreeNodeUnwrapping('azureFunctions.createFunctionApp', createFunctionApp);
registerCommandWithTreeNodeUnwrapping('azureFunctions.createFunctionAppAdvanced', createFunctionAppAdvanced);
registerCommand('azureFunctions.createNewProject', createNewProjectFromCommand);
registerCommandWithTreeNodeUnwrapping('azureFunctions.createNewProjectWithDockerfile', async (context: IActionContext) => await createNewProjectInternal(context, { executeStep: new CreateDockerfileProjectStep(), languageFilter: /Python|C\#|(Java|Type)Script|PowerShell$/i }));
registerCommandWithTreeNodeUnwrapping('azureFunctions.createSlot', createSlot);
registerCommandWithTreeNodeUnwrapping('azureFunctions.deleteFunction', deleteFunction);
registerCommandWithTreeNodeUnwrapping('azureFunctions.deleteFunctionApp', deleteFunctionApp);

Просмотреть файл

@ -18,7 +18,7 @@ import { getFuncCliPath, hasFuncCliSetting } from './getFuncCliPath';
import { getFuncPackageManagers } from './getFuncPackageManagers';
import { installFuncCoreTools, lastCoreToolsInstallCommand } from './installFuncCoreTools';
export async function validateFuncCoreToolsInstalled(context: IActionContext, message: string, workspacePath: string): Promise<boolean> {
export async function validateFuncCoreToolsInstalled(context: IActionContext, message: string, workspacePath?: string): Promise<boolean> {
let input: MessageItem | undefined;
let installed: boolean = false;
let failedInstall: string = localize('failedInstallFuncTools', 'Core Tools installation has failed and will have to be installed manually.');