private static (WorkerRuntime, string) ResolveWorkerRuntimeAndLanguage(string workerRuntimeString, string languageString) { WorkerRuntime workerRuntime; string language; if (!string.IsNullOrEmpty(workerRuntimeString)) { workerRuntime = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntimeString); language = languageString ?? WorkerRuntimeLanguageHelper.NormalizeLanguage(workerRuntimeString); } else if (GlobalCoreToolsSettings.CurrentWorkerRuntimeOrNone == Helpers.WorkerRuntime.None) { SelectionMenuHelper.DisplaySelectionWizardPrompt("worker runtime"); workerRuntime = SelectionMenuHelper.DisplaySelectionWizard(WorkerRuntimeLanguageHelper.AvailableWorkersList); ColoredConsole.WriteLine(TitleColor(workerRuntime.ToString())); language = LanguageSelectionIfRelevant(workerRuntime); } else { workerRuntime = GlobalCoreToolsSettings.CurrentWorkerRuntime; language = GlobalCoreToolsSettings.CurrentLanguageOrNull ?? languageString ?? WorkerRuntimeLanguageHelper.NormalizeLanguage(workerRuntime.ToString()); } return(workerRuntime, language); }
private static (WorkerRuntime, string) ResolveWorkerRuntimeAndLanguage(string workerRuntimeString, string languageString) { WorkerRuntime workerRuntime; string language; if (!string.IsNullOrEmpty(workerRuntimeString)) { workerRuntime = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntimeString); language = languageString ?? WorkerRuntimeLanguageHelper.NormalizeLanguage(workerRuntimeString); } else if (GlobalCoreToolsSettings.CurrentWorkerRuntimeOrNone == Helpers.WorkerRuntime.None) { ColoredConsole.Write("Select a worker runtime: "); IDictionary <WorkerRuntime, string> workerRuntimeToDisplayString = WorkerRuntimeLanguageHelper.GetWorkerToDisplayStrings(); workerRuntimeString = SelectionMenuHelper.DisplaySelectionWizard(workerRuntimeToDisplayString.Values); workerRuntime = workerRuntimeToDisplayString.FirstOrDefault(wr => wr.Value.Equals(workerRuntimeString)).Key; ColoredConsole.WriteLine(TitleColor(workerRuntime.ToString())); language = LanguageSelectionIfRelevant(workerRuntime); } else { workerRuntime = GlobalCoreToolsSettings.CurrentWorkerRuntime; language = GlobalCoreToolsSettings.CurrentLanguageOrNull ?? languageString ?? WorkerRuntimeLanguageHelper.NormalizeLanguage(workerRuntime.ToString()); } return(workerRuntime, language); }
public override async Task RunAsync() { var functionAppRoot = string.IsNullOrEmpty(FolderName) ? Path.Combine(Environment.CurrentDirectory, FolderName) : ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); string outputPath; if (string.IsNullOrEmpty(OutputPath)) { outputPath = Path.Combine(Environment.CurrentDirectory, $"{Path.GetFileName(functionAppRoot)}.zip"); } else { outputPath = Path.Combine(Environment.CurrentDirectory, OutputPath); if (FileSystemHelpers.DirectoryExists(outputPath)) { outputPath = Path.Combine(outputPath, $"{Path.GetFileName(functionAppRoot)}.zip"); } } if (!FileSystemHelpers.FileExists(Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName))) { throw new CliException($"Can't find {Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName)}"); } var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); var zipStream = await ZipHelper.GetAppZipFile(workerRuntime, functionAppRoot, BuildNativeDeps); await FileSystemHelpers.WriteToFile(outputPath, zipStream); }
public override async Task RunAsync() { var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); if (workerRuntime == WorkerRuntime.None) { throw new CliException("your worker runtime is not set. As of 2.0.1-beta.26 a worker runtime setting is required.\n" + $"Please run `func settings add {Constants.FunctionsWorkerRuntime} <option>`\n" + $"Available options: {WorkerRuntimeLanguageHelper.AvailableWorkersRuntimeString}"); } await PreRunConditions(workerRuntime); Utilities.PrintLogo(); var settings = SelfHostWebHostSettingsFactory.Create(Environment.CurrentDirectory); (var baseAddress, var certificate) = Setup(); IWebHost host = await BuildWebHost(settings, workerRuntime, baseAddress, certificate); var runTask = host.RunAsync(); var manager = host.Services.GetRequiredService <WebScriptHostManager>(); await manager.DelayUntilHostReady(); ColoredConsole.WriteLine($"Listening on {baseAddress}"); ColoredConsole.WriteLine("Hit CTRL-C to exit..."); DisplayHttpFunctionsInfo(manager, baseAddress); DisplayDisabledFunctions(manager); await SetupDebuggerAsync(baseAddress); await runTask; }
public override async Task RunAsync() { // Get function app var functionApp = await AzureHelper.GetFunctionApp(FunctionAppName, AccessToken, ManagementURL); // Get the GitIgnoreParser from the functionApp root var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); var ignoreParser = PublishHelper.GetIgnoreParser(functionAppRoot); // Get the WorkerRuntime var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); // Check for any additional conditions or app settings that need to change // before starting any of the publish activity. var additionalAppSettings = await ValidateFunctionAppPublish(functionApp, workerRuntime); if (workerRuntime == WorkerRuntime.dotnet && !Csx && !NoBuild) { if (DotnetHelpers.CanDotnetBuild()) { var outputPath = Path.Combine("bin", "publish"); await DotnetHelpers.BuildDotnetProject(outputPath, DotnetCliParameters); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } else if (StaticSettings.IsDebug) { ColoredConsole.WriteLine("Could not find a valid .csproj file. Skipping the build."); } } if (workerRuntime != WorkerRuntime.dotnet || Csx) { // Restore all valid extensions var installExtensionAction = new InstallExtensionAction(_secretsManager, false); await installExtensionAction.RunAsync(); } if (ListIncludedFiles) { InternalListIncludedFiles(ignoreParser); } else if (ListIgnoredFiles) { InternalListIgnoredFiles(ignoreParser); } else { if (PublishLocalSettingsOnly) { await PublishLocalAppSettings(functionApp, additionalAppSettings); } else { await PublishFunctionApp(functionApp, ignoreParser, additionalAppSettings); } } }
public override async Task RunAsync() { var functionAppRoot = string.IsNullOrEmpty(FolderName) ? Path.Combine(Environment.CurrentDirectory, FolderName) : ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); string outputPath; if (string.IsNullOrEmpty(OutputPath)) { outputPath = Path.Combine(Environment.CurrentDirectory, $"{Path.GetFileName(functionAppRoot)}"); } else { outputPath = Path.Combine(Environment.CurrentDirectory, OutputPath); if (FileSystemHelpers.DirectoryExists(outputPath)) { outputPath = Path.Combine(outputPath, $"{Path.GetFileName(functionAppRoot)}"); } } if (!FileSystemHelpers.FileExists(Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName))) { throw new CliException($"Can't find {Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName)}"); } var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); outputPath += Squashfs ? ".squashfs" : ".zip"; if (FileSystemHelpers.FileExists(outputPath)) { ColoredConsole.WriteLine($"Deleting the old package {outputPath}"); try { FileSystemHelpers.FileDelete(outputPath); } catch (Exception) { throw new CliException($"Could not delete {outputPath}"); } } // Restore all valid extensions var installExtensionAction = new InstallExtensionAction(_secretsManager, false); await installExtensionAction.RunAsync(); var stream = await ZipHelper.GetAppZipFile(functionAppRoot, BuildNativeDeps, noBuild : false, buildOption : BuildOption.Default, additionalPackages : AdditionalPackages); if (Squashfs) { stream = await PythonHelpers.ZipToSquashfsStream(stream); } ColoredConsole.WriteLine($"Creating a new package {outputPath}"); await FileSystemHelpers.WriteToFile(outputPath, stream); }
private async Task InitDockerFileOnly() { var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); if (workerRuntime == Helpers.WorkerRuntime.None) { (workerRuntime, _) = ResolveWorkerRuntimeAndLanguage(WorkerRuntime, Language); } await WriteDockerfile(workerRuntime); }
public override async Task RunAsync() { if (SourceControl != SourceControl.Git) { throw new Exception("Only Git is supported right now for vsc"); } if (!string.IsNullOrEmpty(FolderName)) { var folderPath = Path.Combine(Environment.CurrentDirectory, FolderName); FileSystemHelpers.EnsureDirectory(folderPath); Environment.CurrentDirectory = folderPath; } WorkerRuntime workerRuntime; if (Csx) { workerRuntime = Helpers.WorkerRuntime.dotnet; } else if (string.IsNullOrEmpty(WorkerRuntime)) { ColoredConsole.Write("Select a worker runtime: "); IDictionary <WorkerRuntime, string> workerRuntimeToDisplayString = WorkerRuntimeLanguageHelper.GetWorkerToDisplayStrings(); var workerRuntimeString = SelectionMenuHelper.DisplaySelectionWizard(workerRuntimeToDisplayString.Values); workerRuntime = workerRuntimeToDisplayString.FirstOrDefault(wr => wr.Value.Equals(workerRuntimeString)).Key; ColoredConsole.WriteLine(TitleColor(workerRuntime.ToString())); LanguageSelectionIfRelevant(workerRuntime); } else { workerRuntime = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(WorkerRuntime); Language = Language ?? WorkerRuntimeLanguageHelper.NormalizeLanguage(WorkerRuntime); } if (workerRuntime == Helpers.WorkerRuntime.dotnet && !Csx) { await DotnetHelpers.DeployDotnetProject(Utilities.SanitizeLiteral(Path.GetFileName(Environment.CurrentDirectory), allowed: "-"), Force); } else { await InitLanguageSpecificArtifacts(workerRuntime); await WriteFiles(); await WriteLocalSettingsJson(workerRuntime); } await WriteExtensionsJson(); await SetupSourceControl(); await WriteDockerfile(workerRuntime); }
public override async Task RunAsync() { if (SourceControl != SourceControl.Git) { throw new Exception("Only Git is supported right now for vsc"); } if (!string.IsNullOrEmpty(FolderName)) { var folderPath = Path.Combine(Environment.CurrentDirectory, FolderName); FileSystemHelpers.EnsureDirectory(folderPath); Environment.CurrentDirectory = folderPath; } WorkerRuntime workerRuntime; if (Csx) { workerRuntime = Helpers.WorkerRuntime.dotnet; } else if (string.IsNullOrEmpty(WorkerRuntime)) { ColoredConsole.Write("Select a worker runtime: "); workerRuntime = SelectionMenuHelper.DisplaySelectionWizard(WorkerRuntimeLanguageHelper.AvailableWorkersList); ColoredConsole.WriteLine(TitleColor(workerRuntime.ToString())); } else { workerRuntime = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(WorkerRuntime); } if (workerRuntime == Helpers.WorkerRuntime.dotnet && !Csx) { await DotnetHelpers.DeployDotnetProject(Path.GetFileName(Environment.CurrentDirectory), Force); } else { await InitLanguageSpecificArtifacts(workerRuntime); await WriteFiles(); await WriteLocalSettingsJson(workerRuntime); } await WriteExtensionsJson(); await SetupSourceControl(); await WriteDockerfile(workerRuntime); // PostInit(); }
public override async Task RunAsync() { var functionAppRoot = string.IsNullOrEmpty(FolderName) ? Path.Combine(Environment.CurrentDirectory, FolderName) : ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); string outputPath; if (string.IsNullOrEmpty(OutputPath)) { outputPath = Path.Combine(Environment.CurrentDirectory, $"{Path.GetFileName(functionAppRoot)}.zip"); } else { outputPath = Path.Combine(Environment.CurrentDirectory, OutputPath); if (FileSystemHelpers.DirectoryExists(outputPath)) { outputPath = Path.Combine(outputPath, $"{Path.GetFileName(functionAppRoot)}.zip"); } } if (!FileSystemHelpers.FileExists(Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName))) { throw new CliException($"Can't find {Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName)}"); } var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); if (FileSystemHelpers.FileExists(outputPath)) { ColoredConsole.WriteLine($"Deleting the old package {outputPath}"); try { FileSystemHelpers.FileDelete(outputPath); } catch (Exception) { throw new CliException($"Could not delete {outputPath}"); } } var zipStream = await ZipHelper.GetAppZipFile(workerRuntime, functionAppRoot, BuildNativeDeps, NoBundler, additionalPackages : AdditionalPackages); ColoredConsole.WriteLine($"Creating a new package {outputPath}"); await FileSystemHelpers.WriteToFile(outputPath, zipStream); }
private async Task InternalPublishFunctionApp(GitIgnoreParser ignoreParser) { ColoredConsole.WriteLine("Getting site publishing info..."); var functionApp = await _armManager.GetFunctionAppAsync(FunctionAppName); var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); if (functionApp.IsLinux && !functionApp.IsDynamicLinux && RunFromZipDeploy) { ColoredConsole .WriteLine(ErrorColor("--zip is not supported with dedicated linux apps.")); return; } var workerRuntime = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsWorkerRuntime, StringComparison.OrdinalIgnoreCase)).Value; if (!string.IsNullOrWhiteSpace(workerRuntime)) { var worker = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); if (worker == WorkerRuntime.python) { if (!SkipWheelRestore) { await PythonHelpers.InstallPipWheel(); await PythonHelpers.DownloadWheels(); } else { ColoredConsole.WriteLine("Skipping wheels download"); } } } // if consumption linux, or --zip, run from zip if (functionApp.IsDynamicLinux || RunFromZipDeploy) { await PublishRunFromZip(functionApp, functionAppRoot, ignoreParser); } else { await PublishZipDeploy(functionApp, functionAppRoot, ignoreParser); } }
public override async Task RunAsync() { GitIgnoreParser ignoreParser = null; try { var path = Path.Combine(Environment.CurrentDirectory, Constants.FuncIgnoreFile); if (FileSystemHelpers.FileExists(path)) { ignoreParser = new GitIgnoreParser(FileSystemHelpers.ReadAllTextFromFile(path)); } } catch { } var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); if (workerRuntime == WorkerRuntime.dotnet && !Csx) { const string outputPath = "bin/publish"; await DotnetHelpers.BuildDotnetProject(outputPath); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } if (ListIncludedFiles) { InternalListIncludedFiles(ignoreParser); } else if (ListIgnoredFiles) { InternalListIgnoredFiles(ignoreParser); } else { if (PublishLocalSettingsOnly) { await InternalPublishLocalSettingsOnly(); } else { await InternalPublishFunctionApp(ignoreParser); } } }
public override async Task RunAsync() { // Get function app var functionApp = await AzureHelper.GetFunctionApp(FunctionAppName, AccessToken); // Get the GitIgnoreParser from the functionApp root var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); var ignoreParser = PublishHelper.GetIgnoreParser(functionAppRoot); // Get the WorkerRuntime var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); // Check for any additional conditions or app settings that need to change // before starting any of the publish activity. var additionalAppSettings = ValidateFunctionAppPublish(functionApp, workerRuntime); if (workerRuntime == WorkerRuntime.dotnet && !Csx && !NoBuild) { const string outputPath = "bin/publish"; await DotnetHelpers.BuildDotnetProject(outputPath, DotnetCliParameters); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } if (ListIncludedFiles) { InternalListIncludedFiles(ignoreParser); } else if (ListIgnoredFiles) { InternalListIgnoredFiles(ignoreParser); } else { if (PublishLocalSettingsOnly) { await PublishLocalAppSettings(functionApp, additionalAppSettings); } else { await PublishFunctionApp(functionApp, ignoreParser, additionalAppSettings); } } }
public override async Task RunAsync() { var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); if (workerRuntime == WorkerRuntime.None) { ColoredConsole.WriteLine(WarningColor("your worker runtime is not set. As of 2.0.1-beta.26 a worker runtime setting is required.")) .WriteLine(WarningColor($"Please run `{AdditionalInfoColor($"func settings add {Constants.FunctionsWorkerRuntime} <option>")}` or add {Constants.FunctionsWorkerRuntime} to your local.settings.json")) .WriteLine(WarningColor($"Available options: {WorkerRuntimeLanguageHelper.AvailableWorkersRuntimeString}")); } await PreRunConditions(workerRuntime); Utilities.PrintLogo(); Utilities.PrintVersion(); var settings = SelfHostWebHostSettingsFactory.Create(Environment.CurrentDirectory); (var listenUri, var baseUri, var certificate) = await Setup(); IWebHost host = await BuildWebHost(settings, workerRuntime, listenUri, certificate); var runTask = host.RunAsync(); var hostService = host.Services.GetRequiredService <WebJobsScriptHostService>(); await hostService.DelayUntilHostReady(); ColoredConsole.WriteLine($"Listening on {listenUri}"); ColoredConsole.WriteLine("Hit CTRL-C to exit..."); var scriptHost = hostService.Services.GetRequiredService <IScriptJobHost>(); var httpOptions = hostService.Services.GetRequiredService <IOptions <HttpOptions> >(); DisplayHttpFunctionsInfo(scriptHost, httpOptions.Value, baseUri); DisplayDisabledFunctions(scriptHost); await SetupDebuggerAsync(baseUri); await runTask; }
public async override Task RunAsync() { if (Console.IsOutputRedirected || Console.IsInputRedirected) { if (string.IsNullOrEmpty(TemplateName) || string.IsNullOrEmpty(FunctionName)) { ColoredConsole .Error .WriteLine(ErrorColor("Running with stdin\\stdout redirected. Command must specify --template, and --name explicitly.")) .WriteLine(ErrorColor("See 'func help function' for more details")); return; } } var templates = await _templatesManager.Templates; var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); if (workerRuntime != WorkerRuntime.None && !string.IsNullOrWhiteSpace(Language)) { // validate var language = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(Language); if (workerRuntime != language) { throw new CliException("Selected language doesn't match worker set in local.settings.json." + $"Selected worker is: {workerRuntime} and selected language is: {language}"); } } else if (string.IsNullOrWhiteSpace(Language)) { if (workerRuntime == WorkerRuntime.None) { ColoredConsole.Write("Select a language: "); Language = SelectionMenuHelper.DisplaySelectionWizard(templates.Select(t => t.Metadata.Language).Where(l => !l.Equals("python", StringComparison.OrdinalIgnoreCase)).Distinct()); workerRuntime = WorkerRuntimeLanguageHelper.SetWorkerRuntime(_secretsManager, Language); } else if (workerRuntime != WorkerRuntime.dotnet) { var languages = WorkerRuntimeLanguageHelper.LanguagesForWorker(workerRuntime); ColoredConsole.Write("Select a language: "); var displayList = templates .Select(t => t.Metadata.Language) .Where(l => languages.Contains(l, StringComparer.OrdinalIgnoreCase)) .Distinct() .ToArray(); if (displayList.Length == 1) { Language = displayList.First(); } else { Language = SelectionMenuHelper.DisplaySelectionWizard(displayList); } } } else if (!string.IsNullOrWhiteSpace(Language)) { workerRuntime = WorkerRuntimeLanguageHelper.SetWorkerRuntime(_secretsManager, Language); } if (workerRuntime == WorkerRuntime.dotnet) { ColoredConsole.Write("Select a template: "); var templateName = TemplateName ?? SelectionMenuHelper.DisplaySelectionWizard(DotnetHelpers.GetTemplates()); ColoredConsole.Write("Function name: "); var functionName = FunctionName ?? Console.ReadLine(); ColoredConsole.WriteLine(functionName); var namespaceStr = Path.GetFileName(Environment.CurrentDirectory); await DotnetHelpers.DeployDotnetFunction(templateName, functionName, namespaceStr); } else { ColoredConsole.Write("Select a template: "); var name = TemplateName ?? SelectionMenuHelper.DisplaySelectionWizard(templates.Where(t => t.Metadata.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)).Select(t => t.Metadata.Name).Distinct()); ColoredConsole.WriteLine(TitleColor(name)); var template = templates.FirstOrDefault(t => t.Metadata.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && t.Metadata.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)); if (template == null) { ColoredConsole.Error.WriteLine(ErrorColor($"Can't find template \"{name}\" in \"{Language}\"")); } else { ColoredConsole.Write($"Function name: [{template.Metadata.DefaultFunctionName}] "); var functionName = FunctionName ?? Console.ReadLine(); functionName = string.IsNullOrEmpty(functionName) ? template.Metadata.DefaultFunctionName : functionName; await _templatesManager.Deploy(functionName, template); } } }
public override async Task RunAsync() { var functionAppRoot = string.IsNullOrEmpty(FolderName) ? Path.Combine(Environment.CurrentDirectory, FolderName) : ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); string outputPath; if (string.IsNullOrEmpty(OutputPath)) { outputPath = Path.Combine(Environment.CurrentDirectory, $"{Path.GetFileName(functionAppRoot)}.zip"); } else { outputPath = Path.Combine(Environment.CurrentDirectory, OutputPath); if (FileSystemHelpers.DirectoryExists(outputPath)) { outputPath = Path.Combine(outputPath, $"{Path.GetFileName(functionAppRoot)}.zip"); } } if (!FileSystemHelpers.FileExists(Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName))) { throw new CliException($"Can't find {Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName)}"); } var workerRuntime = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsWorkerRuntime, StringComparison.OrdinalIgnoreCase)).Value; var workerRuntimeEnum = string.IsNullOrEmpty(workerRuntime) ? WorkerRuntime.None : WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); var zipStream = await GetAppZipFile(workerRuntimeEnum, functionAppRoot); await FileSystemHelpers.WriteToFile(outputPath, zipStream); }
private async Task <IDictionary <string, string> > ValidateFunctionAppPublish(Site functionApp, WorkerRuntime workerRuntime) { var result = new Dictionary <string, string>(); // Check version if (!functionApp.IsLinux) { if (functionApp.AzureAppSettings.TryGetValue(Constants.FunctionsExtensionVersion, out string version)) { // v2 can be either "~2", "beta", or an exact match like "2.0.11961-alpha" if (!version.Equals("~2") && !version.StartsWith("2.0") && !version.Equals("beta", StringComparison.OrdinalIgnoreCase)) { if (Force) { result.Add(Constants.FunctionsExtensionVersion, "~2"); } else { throw new CliException("You're trying to publish to a non-v2 function app from v2 tooling.\n" + "You can pass --force to force update the app to v2, or switch to v1 or v3 tooling for publishing"); } } } } if (functionApp.AzureAppSettings.TryGetValue(Constants.FunctionsWorkerRuntime, out string workerRuntimeStr)) { var resolution = $"You can pass --force to update your Azure app with '{workerRuntime}' as a '{Constants.FunctionsWorkerRuntime}'"; try { var azureWorkerRuntime = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntimeStr); if (azureWorkerRuntime != workerRuntime) { if (Force) { ColoredConsole.WriteLine(WarningColor($"Setting '{Constants.FunctionsWorkerRuntime}' to '{workerRuntime}' because --force was passed")); result[Constants.FunctionsWorkerRuntime] = workerRuntime.ToString(); } else { throw new CliException($"Your Azure Function App has '{Constants.FunctionsWorkerRuntime}' set to '{azureWorkerRuntime}' while your local project is set to '{workerRuntime}'.\n" + resolution); } } } catch (ArgumentException) when(Force) { result[Constants.FunctionsWorkerRuntime] = workerRuntime.ToString(); } catch (ArgumentException) when(!Force) { throw new CliException($"Your app has an unknown {Constants.FunctionsWorkerRuntime} defined '{workerRuntimeStr}'. Only {WorkerRuntimeLanguageHelper.AvailableWorkersRuntimeString} are supported.\n" + resolution); } } if (!functionApp.AzureAppSettings.ContainsKey("AzureWebJobsStorage") && functionApp.IsDynamic) { throw new CliException($"'{FunctionAppName}' app is missing AzureWebJobsStorage app setting. That setting is required for publishing consumption linux apps."); } if (functionApp.IsLinux && !functionApp.IsDynamic && !string.IsNullOrEmpty(functionApp.LinuxFxVersion)) { // If linuxFxVersion does not match any of our images if (PublishHelper.IsLinuxFxVersionUsingCustomImage(functionApp.LinuxFxVersion)) { ColoredConsole.WriteLine($"Your functionapp is using a custom image {functionApp.LinuxFxVersion}.\nAssuming that the image contains the correct framework.\n"); } // If there the functionapp is our image but does not match the worker runtime image, we either fail or force update else if (!PublishHelper.IsLinuxFxVersionRuntimeMatched(functionApp.LinuxFxVersion, workerRuntime)) { if (Force) { var updatedSettings = new Dictionary <string, string> { [Constants.LinuxFxVersion] = $"DOCKER|{Constants.WorkerRuntimeImages.GetValueOrDefault(workerRuntime).FirstOrDefault()}" }; var settingsResult = await AzureHelper.UpdateWebSettings(functionApp, updatedSettings, AccessToken, ManagementURL); if (!settingsResult.IsSuccessful) { ColoredConsole.Error .WriteLine(ErrorColor("Error updating linux image version:")) .WriteLine(ErrorColor(settingsResult.ErrorResult)); } } else { throw new CliException($"Your Linux dedicated app has the container image version (LinuxFxVersion) set to {functionApp.LinuxFxVersion} which is not expected for the worker runtime {workerRuntime}. " + $"To force publish use --force. This will update your app to the expected image for worker runtime {workerRuntime}\n"); } } } return(result); }
private async Task PublishFunctionApp(Site functionApp, GitIgnoreParser ignoreParser, IDictionary <string, string> additionalAppSettings) { ColoredConsole.WriteLine("Getting site publishing info..."); var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); // For dedicated linux apps, we do not support run from package right now var isFunctionAppDedicated = !functionApp.IsDynamic && !functionApp.IsElasticPremium; if (functionApp.IsLinux && isFunctionAppDedicated && RunFromPackageDeploy) { ColoredConsole.WriteLine("Assuming --nozip (do not run from package) for publishing to Linux dedicated plan."); RunFromPackageDeploy = false; } var workerRuntime = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsWorkerRuntime, StringComparison.OrdinalIgnoreCase)).Value; var workerRuntimeEnum = string.IsNullOrEmpty(workerRuntime) ? WorkerRuntime.None : WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); if (workerRuntimeEnum == WorkerRuntime.python && !functionApp.IsLinux) { throw new CliException("Publishing Python functions is only supported for Linux FunctionApps"); } Func <Task <Stream> > zipStreamFactory = () => ZipHelper.GetAppZipFile(workerRuntimeEnum, functionAppRoot, BuildNativeDeps, NoBuild, ignoreParser, AdditionalPackages, ignoreDotNetCheck: true); // If Consumption Linux or Elastic Premium Linux if (functionApp.IsLinux && (functionApp.IsDynamic || functionApp.IsElasticPremium)) { await PublishRunFromPackage(functionApp, await zipStreamFactory()); } // If Windows default else if (RunFromPackageDeploy) { await PublishRunFromPackageLocal(functionApp, zipStreamFactory); } // If Dedicated Linux or "--no-zip" else { await PublishZipDeploy(functionApp, zipStreamFactory); } if (PublishLocalSettings) { await PublishLocalAppSettings(functionApp, additionalAppSettings); } else if (additionalAppSettings.Any()) { await PublishAppSettings(functionApp, new Dictionary <string, string>(), additionalAppSettings); } // Syncing triggers is not required when using zipdeploy api if ((functionApp.IsLinux && (functionApp.IsDynamic || functionApp.IsElasticPremium)) || RunFromPackageDeploy) { await Task.Delay(TimeSpan.FromSeconds(5)); await SyncTriggers(functionApp); } // Linux Elastic Premium functions take longer to deploy. Right now, we cannot guarantee that functions info will be most up to date. // So, we only show the info, if Function App is not Linux Elastic Premium if (!(functionApp.IsLinux && functionApp.IsElasticPremium)) { await AzureHelper.PrintFunctionsInfo(functionApp, AccessToken, ManagementURL, showKeys : true); } }
private async Task PublishFunctionApp(Site functionApp, GitIgnoreParser ignoreParser, IDictionary <string, string> additionalAppSettings) { ColoredConsole.WriteLine("Getting site publishing info..."); var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); // For dedicated linux apps, we do not support run from package right now var isFunctionAppDedicated = !functionApp.IsDynamic && !functionApp.IsElasticPremium; if (functionApp.IsLinux && isFunctionAppDedicated && RunFromPackageDeploy) { ColoredConsole.WriteLine("Assuming --nozip (do not run from package) for publishing to Linux dedicated plan."); RunFromPackageDeploy = false; } var workerRuntime = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsWorkerRuntime, StringComparison.OrdinalIgnoreCase)).Value; var workerRuntimeEnum = string.IsNullOrEmpty(workerRuntime) ? WorkerRuntime.None : WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); if (workerRuntimeEnum == WorkerRuntime.python && !functionApp.IsLinux) { throw new CliException("Publishing Python functions is only supported for Linux FunctionApps"); } Func <Task <Stream> > zipStreamFactory = () => ZipHelper.GetAppZipFile(workerRuntimeEnum, functionAppRoot, BuildNativeDeps, NoBuild, ignoreParser, AdditionalPackages, ignoreDotNetCheck: true); bool shouldSyncTriggers = true; var fileNameNoExtension = string.Format("{0}-{1}", DateTimeOffset.UtcNow.ToString("yyyyMMddHHmmss"), Guid.NewGuid()); if (functionApp.IsLinux && functionApp.IsDynamic) { // Consumption Linux, try squashfs as a package format. if (workerRuntimeEnum == WorkerRuntime.python && !NoBuild && BuildNativeDeps) { await PublishRunFromPackage(functionApp, await PythonHelpers.ZipToSquashfsStream(await zipStreamFactory()), $"{fileNameNoExtension}.squashfs"); } else { await PublishRunFromPackage(functionApp, await zipStreamFactory(), $"{fileNameNoExtension}.zip"); } } else if (functionApp.IsLinux && functionApp.IsElasticPremium) { // Elastic Premium Linux await PublishRunFromPackage(functionApp, await zipStreamFactory(), $"{fileNameNoExtension}.zip"); } else if (RunFromPackageDeploy) { // Windows default await PublishRunFromPackageLocal(functionApp, zipStreamFactory); } else { // ZipDeploy takes care of the SyncTriggers operation so we don't // need to perform one shouldSyncTriggers = false; // Dedicated Linux or "--no-zip" await PublishZipDeploy(functionApp, zipStreamFactory); } if (PublishLocalSettings) { await PublishLocalAppSettings(functionApp, additionalAppSettings); } else if (additionalAppSettings.Any()) { await PublishAppSettings(functionApp, new Dictionary <string, string>(), additionalAppSettings); } if (shouldSyncTriggers) { await Task.Delay(TimeSpan.FromSeconds(5)); await SyncTriggers(functionApp); } // Linux Elastic Premium functions take longer to deploy. Right now, we cannot guarantee that functions info will be most up to date. // So, we only show the info, if Function App is not Linux Elastic Premium if (!(functionApp.IsLinux && functionApp.IsElasticPremium)) { await AzureHelper.PrintFunctionsInfo(functionApp, AccessToken, ManagementURL, showKeys : true); } }
private async Task PublishFunctionApp(Site functionApp, GitIgnoreParser ignoreParser, IDictionary <string, string> additionalAppSettings) { ColoredConsole.WriteLine("Getting site publishing info..."); var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); if (functionApp.IsLinux && !functionApp.IsDynamic && RunFromZipDeploy) { throw new CliException("Run from package is not supported with dedicated linux apps. Please use --nozip"); } var workerRuntime = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsWorkerRuntime, StringComparison.OrdinalIgnoreCase)).Value; var workerRuntimeEnum = string.IsNullOrEmpty(workerRuntime) ? WorkerRuntime.None : WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); if (workerRuntimeEnum == WorkerRuntime.python && !functionApp.IsLinux) { throw new CliException("Publishing Python functions is only supported for Linux FunctionApps"); } Func <Task <Stream> > zipStreamFactory = () => ZipHelper.GetAppZipFile(workerRuntimeEnum, functionAppRoot, BuildNativeDeps, ignoreParser, AdditionalPackages, ignoreDotNetCheck: true); // if consumption Linux, or run from zip if ((functionApp.IsLinux && functionApp.IsDynamic) || RunFromZipDeploy) { await PublishRunFromZip(functionApp, await zipStreamFactory()); } else { await PublishZipDeploy(functionApp, zipStreamFactory); } if (PublishLocalSettings) { await PublishLocalAppSettings(functionApp, additionalAppSettings); } else if (additionalAppSettings.Any()) { await PublishAppSettings(functionApp, new Dictionary <string, string>(), additionalAppSettings); } // Syncing triggers is not required when using zipdeploy api if ((functionApp.IsLinux && functionApp.IsDynamic) || RunFromZipDeploy) { await Task.Delay(TimeSpan.FromSeconds(5)); await SyncTriggers(functionApp); } await AzureHelper.PrintFunctionsInfo(functionApp, AccessToken, showKeys : true); }
private IDictionary <string, string> ValidateFunctionAppPublish(Site functionApp, WorkerRuntime workerRuntime) { var result = new Dictionary <string, string>(); // Check version if (!functionApp.IsLinux) { if (functionApp.AzureAppSettings.TryGetValue(Constants.FunctionsExtensionVersion, out string version)) { // v2 can be either "~2", "beta", or an exact match like "2.0.11961-alpha" if (!version.Equals("~2") && !version.StartsWith("2.0") && !version.Equals("beta", StringComparison.OrdinalIgnoreCase)) { if (Force) { result.Add(Constants.FunctionsExtensionVersion, "~2"); } else { throw new CliException("You're trying to publish to a v1 function app from v2 tooling.\n" + "You can pass --force to force update the app to v2, or downgrade to v1 tooling for publishing"); } } } } if (functionApp.AzureAppSettings.TryGetValue(Constants.FunctionsWorkerRuntime, out string workerRuntimeStr)) { var resolution = $"You can pass --force to update your Azure app with '{workerRuntime}' as a '{Constants.FunctionsWorkerRuntime}'"; try { var azureWorkerRuntime = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntimeStr); if (azureWorkerRuntime != workerRuntime) { if (Force) { ColoredConsole.WriteLine(WarningColor($"Setting '{Constants.FunctionsWorkerRuntime}' to '{workerRuntime}' because --force was passed")); result[Constants.FunctionsWorkerRuntime] = workerRuntime.ToString(); } else { throw new CliException($"Your Azure Function App has '{Constants.FunctionsWorkerRuntime}' set to '{azureWorkerRuntime}' while your local project is set to '{workerRuntime}'.\n" + resolution); } } } catch (ArgumentException) when(Force) { result[Constants.FunctionsWorkerRuntime] = workerRuntime.ToString(); } catch (ArgumentException) when(!Force) { throw new CliException($"Your app has an unknown {Constants.FunctionsWorkerRuntime} defined '{workerRuntimeStr}'. Only {WorkerRuntimeLanguageHelper.AvailableWorkersRuntimeString} are supported.\n" + resolution); } } if (!functionApp.AzureAppSettings.ContainsKey("AzureWebJobsStorage") && functionApp.IsDynamic) { throw new CliException($"'{FunctionAppName}' app is missing AzureWebJobsStorage app setting. That setting is required for publishing consumption linux apps."); } if (functionApp.IsLinux && functionApp.IsDynamic && functionApp.AzureAppSettings.ContainsKey("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING")) { if (Force) { result.Add("WEBSITE_CONTENTSHARE", null); result.Add("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING", null); } else { throw new CliException("Your app is configured with Azure Files for editing from Azure Portal.\nTo force publish use --force. This will remove Azure Files from your app."); } } return(result); }
public async override Task RunAsync() { if (Console.IsOutputRedirected || Console.IsInputRedirected) { if (string.IsNullOrEmpty(TemplateName) || string.IsNullOrEmpty(FunctionName)) { ColoredConsole .Error .WriteLine(ErrorColor("Running with stdin\\stdout redirected. Command must specify --template, and --name explicitly.")) .WriteLine(ErrorColor("See 'func help function' for more details")); return; } } var templates = await _templatesManager.Templates; var workerRuntime = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsWorkerRuntime, StringComparison.OrdinalIgnoreCase)).Value; if (!string.IsNullOrWhiteSpace(workerRuntime) && !string.IsNullOrWhiteSpace(Language)) { // validate var worker = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); var language = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(Language); if (worker != language) { throw new CliException("Selected language doesn't match worker set in local.settings.json." + $"Selected worker is: {worker} and selected language is: {language}"); } } else if (string.IsNullOrWhiteSpace(Language)) { if (string.IsNullOrWhiteSpace(workerRuntime)) { ColoredConsole.Write("Select a language: "); Language = SelectionMenuHelper.DisplaySelectionWizard(templates.Select(t => t.Metadata.Language).Where(l => !l.Equals("python", StringComparison.OrdinalIgnoreCase)).Distinct()); var worker = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(Language); _secretsManager.SetSecret(Constants.FunctionsWorkerRuntime, worker.ToString()); ColoredConsole .WriteLine(WarningColor("Starting from 2.0.1-beta.26 it's required to set a language for your project in your settings")) .WriteLine(WarningColor($"'{worker}' has been set in your local.settings.json")); } else { var worker = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); var languages = WorkerRuntimeLanguageHelper.LanguagesForWorker(worker); ColoredConsole.Write("Select a language: "); var displayList = templates .Select(t => t.Metadata.Language) .Where(l => languages.Contains(l, StringComparer.OrdinalIgnoreCase)) .Distinct() .ToArray(); if (displayList.Length == 1) { Language = displayList.First(); } else { Language = SelectionMenuHelper.DisplaySelectionWizard(displayList); } } } else if (!string.IsNullOrWhiteSpace(Language)) { var worker = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(Language); _secretsManager.SetSecret(Constants.FunctionsWorkerRuntime, worker.ToString()); ColoredConsole .WriteLine(WarningColor("Starting from 2.0.1-beta.26 it's required to set a language for your project in your settings")) .WriteLine(WarningColor($"'{worker}' has been set in your local.settings.json")); } ColoredConsole.Write("Select a template: "); var name = TemplateName ?? SelectionMenuHelper.DisplaySelectionWizard(templates.Where(t => t.Metadata.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)).Select(t => t.Metadata.Name).Distinct()); ColoredConsole.WriteLine(TitleColor(name)); var template = templates.FirstOrDefault(t => t.Metadata.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && t.Metadata.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)); if (template == null) { ColoredConsole.Error.WriteLine(ErrorColor($"Can't find template \"{name}\" in \"{Language}\"")); } else { ColoredConsole.Write($"Function name: [{template.Metadata.DefaultFunctionName}] "); var functionName = FunctionName ?? Console.ReadLine(); functionName = string.IsNullOrEmpty(functionName) ? template.Metadata.DefaultFunctionName : functionName; await _templatesManager.Deploy(functionName, template); } }
public async override Task RunAsync() { if (Console.IsOutputRedirected || Console.IsInputRedirected) { if (string.IsNullOrEmpty(TemplateName) || string.IsNullOrEmpty(FunctionName)) { ColoredConsole .Error .WriteLine(ErrorColor("Running with stdin\\stdout redirected. Command must specify --template, and --name explicitly.")) .WriteLine(ErrorColor("See 'func help function' for more details")); return; } } var templates = await _templatesManager.Templates; var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); if (workerRuntime != WorkerRuntime.None && !string.IsNullOrWhiteSpace(Language)) { // validate var workerRuntimeSelected = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(Language); if (workerRuntime != workerRuntimeSelected) { throw new CliException("Selected language doesn't match worker set in local.settings.json." + $"Selected worker is: {workerRuntime} and selected language is: {workerRuntimeSelected}"); } } else if (string.IsNullOrWhiteSpace(Language)) { if (workerRuntime == WorkerRuntime.None) { ColoredConsole.Write("Select a language: "); Language = SelectionMenuHelper.DisplaySelectionWizard(templates.Select(t => t.Metadata.Language).Where(l => !l.Equals("python", StringComparison.OrdinalIgnoreCase)).Distinct()); workerRuntime = WorkerRuntimeLanguageHelper.SetWorkerRuntime(_secretsManager, Language); } else if (workerRuntime != WorkerRuntime.dotnet || Csx) { var languages = WorkerRuntimeLanguageHelper.LanguagesForWorker(workerRuntime); var displayList = templates .Select(t => t.Metadata.Language) .Where(l => languages.Contains(l, StringComparer.OrdinalIgnoreCase)) .Distinct() .ToArray(); if (displayList.Length == 1) { Language = displayList.First(); } else if (!InferAndUpdateLanguage(workerRuntime)) { ColoredConsole.Write("Select a language: "); Language = SelectionMenuHelper.DisplaySelectionWizard(displayList); } } } else if (!string.IsNullOrWhiteSpace(Language)) { workerRuntime = WorkerRuntimeLanguageHelper.SetWorkerRuntime(_secretsManager, Language); } if (workerRuntime == WorkerRuntime.dotnet && !Csx) { ColoredConsole.Write("Select a template: "); TemplateName = TemplateName ?? SelectionMenuHelper.DisplaySelectionWizard(DotnetHelpers.GetTemplates()); ColoredConsole.Write("Function name: "); FunctionName = FunctionName ?? Console.ReadLine(); ColoredConsole.WriteLine(FunctionName); var namespaceStr = Path.GetFileName(Environment.CurrentDirectory); await DotnetHelpers.DeployDotnetFunction(TemplateName.Replace(" ", string.Empty), Utilities.SanitizeClassName(FunctionName), Utilities.SanitizeNameSpace(namespaceStr)); } else { ColoredConsole.Write("Select a template: "); string templateLanguage; try { templateLanguage = WorkerRuntimeLanguageHelper.NormalizeLanguage(Language); } catch (Exception) { // Ideally this should never happen. templateLanguage = WorkerRuntimeLanguageHelper.GetDefaultTemplateLanguageFromWorker(workerRuntime); } TemplateName = TemplateName ?? SelectionMenuHelper.DisplaySelectionWizard(templates.Where(t => t.Metadata.Language.Equals(templateLanguage, StringComparison.OrdinalIgnoreCase)).Select(t => t.Metadata.Name).Distinct()); ColoredConsole.WriteLine(TitleColor(TemplateName)); var template = templates.FirstOrDefault(t => Utilities.EqualsIgnoreCaseAndSpace(t.Metadata.Name, TemplateName) && t.Metadata.Language.Equals(templateLanguage, StringComparison.OrdinalIgnoreCase)); if (template == null) { throw new CliException($"Can't find template \"{TemplateName}\" in \"{Language}\""); } else { ExtensionsHelper.EnsureDotNetForExtensions(template); ColoredConsole.Write($"Function name: [{template.Metadata.DefaultFunctionName}] "); FunctionName = FunctionName ?? Console.ReadLine(); FunctionName = string.IsNullOrEmpty(FunctionName) ? template.Metadata.DefaultFunctionName : FunctionName; await _templatesManager.Deploy(FunctionName, template); PerformPostDeployTasks(FunctionName, Language); } } ColoredConsole.WriteLine($"The function \"{FunctionName}\" was created successfully from the \"{TemplateName}\" template."); }
private async Task InternalPublishFunctionApp(GitIgnoreParser ignoreParser) { ColoredConsole.WriteLine("Getting site publishing info..."); var functionApp = await _armManager.GetFunctionAppAsync(FunctionAppName); var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); if (functionApp.IsLinux && !functionApp.IsDynamic && RunFromZipDeploy) { ColoredConsole .WriteLine(ErrorColor("--zip is not supported with dedicated linux apps.")); return; } var workerRuntime = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsWorkerRuntime, StringComparison.OrdinalIgnoreCase)).Value; var workerRuntimeEnum = string.IsNullOrEmpty(workerRuntime) ? WorkerRuntime.None : WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); if (workerRuntimeEnum == WorkerRuntime.python && !functionApp.IsLinux) { throw new CliException("Publishing Python functions is only supported for Linux FunctionApps"); } var zipStream = await ZipHelper.GetAppZipFile(workerRuntimeEnum, functionAppRoot, BuildNativeDeps, ignoreParser); // if consumption Linux, or --zip, run from zip if ((functionApp.IsLinux && functionApp.IsDynamic) || RunFromZipDeploy) { await PublishRunFromZip(functionApp, zipStream); } else { await PublishZipDeploy(functionApp, zipStream); } await SyncTriggers(functionApp); if (PublishLocalSettings) { await PublishAppSettings(functionApp); } }
public async override Task RunAsync() { if (Console.IsOutputRedirected || Console.IsInputRedirected) { if (string.IsNullOrEmpty(TemplateName) || string.IsNullOrEmpty(FunctionName)) { ColoredConsole .Error .WriteLine(ErrorColor("Running with stdin\\stdout redirected. Command must specify --template, and --name explicitly.")) .WriteLine(ErrorColor("See 'func help function' for more details")); return; } } var workerRuntime = GlobalCoreToolsSettings.CurrentWorkerRuntimeOrNone; if (!FileSystemHelpers.FileExists(Path.Combine(Environment.CurrentDirectory, "local.settings.json"))) { // we're assuming "func init" has not been run await _initAction.RunAsync(); workerRuntime = _initAction.ResolvedWorkerRuntime; Language = _initAction.ResolvedLanguage; } var templates = await _templatesManager.Templates; if (workerRuntime != WorkerRuntime.None && !string.IsNullOrWhiteSpace(Language)) { // validate var workerRuntimeSelected = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(Language); if (workerRuntime != workerRuntimeSelected) { throw new CliException("Selected language doesn't match worker set in local.settings.json." + $"Selected worker is: {workerRuntime} and selected language is: {workerRuntimeSelected}"); } } else if (string.IsNullOrWhiteSpace(Language)) { if (workerRuntime == WorkerRuntime.None) { SelectionMenuHelper.DisplaySelectionWizardPrompt("language"); Language = SelectionMenuHelper.DisplaySelectionWizard(_templates.Value.Select(t => t.Metadata.Language).Where(l => !l.Equals("python", StringComparison.OrdinalIgnoreCase)).Distinct()); workerRuntime = WorkerRuntimeLanguageHelper.SetWorkerRuntime(_secretsManager, Language); } else if (workerRuntime != WorkerRuntime.dotnet || Csx) { var languages = WorkerRuntimeLanguageHelper.LanguagesForWorker(workerRuntime); var displayList = _templates.Value .Select(t => t.Metadata.Language) .Where(l => languages.Contains(l, StringComparer.OrdinalIgnoreCase)) .Distinct() .ToArray(); if (displayList.Length == 1) { Language = displayList.First(); } else if (!InferAndUpdateLanguage(workerRuntime)) { SelectionMenuHelper.DisplaySelectionWizardPrompt("language"); Language = SelectionMenuHelper.DisplaySelectionWizard(displayList); } } } else if (!string.IsNullOrWhiteSpace(Language)) { workerRuntime = WorkerRuntimeLanguageHelper.SetWorkerRuntime(_secretsManager, Language); } if (workerRuntime == WorkerRuntime.dotnet && !Csx) { SelectionMenuHelper.DisplaySelectionWizardPrompt("template"); TemplateName = TemplateName ?? SelectionMenuHelper.DisplaySelectionWizard(DotnetHelpers.GetTemplates()); ColoredConsole.Write("Function name: "); FunctionName = FunctionName ?? Console.ReadLine(); ColoredConsole.WriteLine(FunctionName); var namespaceStr = Path.GetFileName(Environment.CurrentDirectory); await DotnetHelpers.DeployDotnetFunction(TemplateName.Replace(" ", string.Empty), Utilities.SanitizeClassName(FunctionName), Utilities.SanitizeNameSpace(namespaceStr), AuthorizationLevel); } else { SelectionMenuHelper.DisplaySelectionWizardPrompt("template"); string templateLanguage; try { templateLanguage = WorkerRuntimeLanguageHelper.NormalizeLanguage(Language); } catch (Exception) { // Ideally this should never happen. templateLanguage = WorkerRuntimeLanguageHelper.GetDefaultTemplateLanguageFromWorker(workerRuntime); } TelemetryHelpers.AddCommandEventToDictionary(TelemetryCommandEvents, "language", templateLanguage); TemplateName = TemplateName ?? SelectionMenuHelper.DisplaySelectionWizard(_templates.Value.Where(t => t.Metadata.Language.Equals(templateLanguage, StringComparison.OrdinalIgnoreCase)).Select(t => t.Metadata.Name).Distinct()); ColoredConsole.WriteLine(TitleColor(TemplateName)); var template = _templates.Value.FirstOrDefault(t => Utilities.EqualsIgnoreCaseAndSpace(t.Metadata.Name, TemplateName) && t.Metadata.Language.Equals(templateLanguage, StringComparison.OrdinalIgnoreCase)); if (template == null) { TelemetryHelpers.AddCommandEventToDictionary(TelemetryCommandEvents, "template", "N/A"); throw new CliException($"Can't find template \"{TemplateName}\" in \"{Language}\""); } else { TelemetryHelpers.AddCommandEventToDictionary(TelemetryCommandEvents, "template", TemplateName); var extensionBundleManager = ExtensionBundleHelper.GetExtensionBundleManager(); if (template.Metadata.Extensions != null && !extensionBundleManager.IsExtensionBundleConfigured() && !CommandChecker.CommandExists("dotnet")) { throw new CliException($"The {template.Metadata.Name} template has extensions. {Constants.Errors.ExtensionsNeedDotnet}"); } if (AuthorizationLevel.HasValue) { ConfigureAuthorizationLevel(template); } ColoredConsole.Write($"Function name: [{template.Metadata.DefaultFunctionName}] "); FunctionName = FunctionName ?? Console.ReadLine(); FunctionName = string.IsNullOrEmpty(FunctionName) ? template.Metadata.DefaultFunctionName : FunctionName; await _templatesManager.Deploy(FunctionName, template); PerformPostDeployTasks(FunctionName, Language); } } ColoredConsole.WriteLine($"The function \"{FunctionName}\" was created successfully from the \"{TemplateName}\" template."); }