private async Task PreRunConditions(WorkerRuntime workerRuntime) { if (workerRuntime == WorkerRuntime.python) { PythonHelpers.VerifyVirtualEnvironment(); } else if (workerRuntime == WorkerRuntime.dotnet && !NoBuild) { if (DotnetHelpers.CanDotnetBuild()) { var outputPath = Path.Combine("bin", "output"); await DotnetHelpers.BuildDotnetProject(outputPath, string.Empty); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } else if (StaticSettings.IsDebug) { ColoredConsole.WriteLine("Could not find a valid .csproj file. Skipping the build."); } } if (!NetworkHelpers.IsPortAvailable(Port)) { throw new CliException($"Port {Port} is unavailable. Close the process using that port, or specify another port using --port [-p]."); } }
private async Task <TriggersPayload> GetTriggersLocalFiles() { var functionsPath = Environment.CurrentDirectory; if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.dotnet) { if (DotnetHelpers.CanDotnetBuild()) { var outputPath = Path.Combine("bin", "output"); await DotnetHelpers.BuildDotnetProject(outputPath, string.Empty, showOutput : false); functionsPath = Path.Combine(Environment.CurrentDirectory, outputPath); } } var functionJsonFiles = FileSystemHelpers .GetDirectories(functionsPath) .Select(d => Path.Combine(d, "function.json")) .Where(FileSystemHelpers.FileExists) .Select(f => (filePath: f, content: FileSystemHelpers.ReadAllTextFromFile(f))); var functionsJsons = functionJsonFiles .Select(t => (filePath: t.filePath, jObject: JsonConvert.DeserializeObject <JObject>(t.content))) .Where(b => b.jObject["bindings"] != null) .ToDictionary(k => Path.GetFileName(Path.GetDirectoryName(k.filePath)), v => v.jObject); var hostJson = JsonConvert.DeserializeObject <JObject>(FileSystemHelpers.ReadAllTextFromFile("host.json")); return(new TriggersPayload { HostJson = hostJson, FunctionsJson = functionsJsons }); }
private async Task PreRunConditions() { if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.python) { var pythonVersion = await PythonHelpers.GetEnvironmentPythonVersion(); PythonHelpers.AssertPythonVersion(pythonVersion, errorIfNotSupported: true, errorIfNoVersion: true); PythonHelpers.SetWorkerPath(pythonVersion?.ExecutablePath, overwrite: false); PythonHelpers.SetWorkerRuntimeVersionPython(pythonVersion); } else if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.dotnet && !NoBuild) { if (DotnetHelpers.CanDotnetBuild()) { var outputPath = Path.Combine("bin", "output"); await DotnetHelpers.BuildDotnetProject(outputPath, string.Empty); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } else if (StaticSettings.IsDebug) { ColoredConsole.WriteLine("Could not find a valid .csproj file. Skipping the build."); } } else if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.powershell && !CommandChecker.CommandExists("dotnet")) { throw new CliException("Dotnet is required for PowerShell Functions. Please install dotnet (.NET Core SDK) for your system from https://www.microsoft.com/net/download"); } if (!NetworkHelpers.IsPortAvailable(Port)) { throw new CliException($"Port {Port} is unavailable. Close the process using that port, or specify another port using --port [-p]."); } }
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); } } }
private async Task PreRunConditions(WorkerRuntime workerRuntime) { if (workerRuntime == WorkerRuntime.python) { PythonHelpers.VerifyVirtualEnvironment(); } else if (workerRuntime == WorkerRuntime.dotnet && Build) { const string outputPath = "bin/output"; await DotnetHelpers.BuildDotnetProject(outputPath); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } }
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() { 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); } } }
private async Task PreRunConditions(WorkerRuntime workerRuntime) { if (workerRuntime == WorkerRuntime.python) { PythonHelpers.VerifyVirtualEnvironment(); } else if (workerRuntime == WorkerRuntime.dotnet && Build) { const string outputPath = "bin/output"; await DotnetHelpers.BuildDotnetProject(outputPath, string.Empty); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } if (!NetworkHelpers.IsPortAvailable(Port)) { throw new CliException($"Port {Port} is unavailable. Close the process using that port, or specify another port using --port [-p]."); } }
private async Task PreRunConditions() { if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.python) { await PythonHelpers.ValidatePythonVersion(setWorkerExecutable : true, errorIfNoExactMatch : true, errorOutIfOld : true); // We need to update the PYTHONPATH to add worker's dependencies var pythonPath = Environment.GetEnvironmentVariable("PYTHONPATH") ?? string.Empty; var pythonWorkerDeps = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "workers", "python", "deps"); if (!pythonPath.Contains(pythonWorkerDeps)) { Environment.SetEnvironmentVariable("PYTHONPATH", $"{pythonPath}{Path.PathSeparator}{pythonWorkerDeps}", EnvironmentVariableTarget.Process); } if (StaticSettings.IsDebug) { ColoredConsole.WriteLine($"PYTHONPATH for the process is: {Environment.GetEnvironmentVariable("PYTHONPATH")}"); } } else if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.dotnet && !NoBuild) { if (DotnetHelpers.CanDotnetBuild()) { var outputPath = Path.Combine("bin", "output"); await DotnetHelpers.BuildDotnetProject(outputPath, string.Empty); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } else if (StaticSettings.IsDebug) { ColoredConsole.WriteLine("Could not find a valid .csproj file. Skipping the build."); } } else if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.powershell && !CommandChecker.CommandExists("dotnet")) { throw new CliException("Dotnet is required for PowerShell Functions. Please install dotnet (.NET Core SDK) for your system from https://www.microsoft.com/net/download"); } if (!NetworkHelpers.IsPortAvailable(Port)) { throw new CliException($"Port {Port} is unavailable. Close the process using that port, or specify another port using --port [-p]."); } }
private async Task PreRunConditions(WorkerRuntime workerRuntime) { if (workerRuntime == WorkerRuntime.python) { await PythonHelpers.VerifyPythonVersions(setWorkerExecutable : true); // We need to update the PYTHONPATH to add worker's dependencies var pythonPath = Environment.GetEnvironmentVariable("PYTHONPATH") ?? string.Empty; var pythonWorkerDeps = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "workers", "python", "deps"); if (!pythonPath.Contains(pythonWorkerDeps)) { Environment.SetEnvironmentVariable("PYTHONPATH", $"{pythonWorkerDeps}{Path.PathSeparator}{pythonPath}", EnvironmentVariableTarget.Process); } if (StaticSettings.IsDebug) { ColoredConsole.WriteLine($"PYTHONPATH for the process is: {Environment.GetEnvironmentVariable("PYTHONPATH")}"); } } else if (workerRuntime == WorkerRuntime.dotnet && !NoBuild) { if (DotnetHelpers.CanDotnetBuild()) { var outputPath = Path.Combine("bin", "output"); await DotnetHelpers.BuildDotnetProject(outputPath, string.Empty); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } else if (StaticSettings.IsDebug) { ColoredConsole.WriteLine("Could not find a valid .csproj file. Skipping the build."); } } if (!NetworkHelpers.IsPortAvailable(Port)) { throw new CliException($"Port {Port} is unavailable. Close the process using that port, or specify another port using --port [-p]."); } }
public override async Task RunAsync() { // Get function app var functionApp = await AzureHelper.GetFunctionApp(FunctionAppName, AccessToken, ManagementURL, Slot, Subscription); if (!functionApp.IsLinux && (PublishBuildOption == BuildOption.Container || PublishBuildOption == BuildOption.Remote)) { throw new CliException($"--build {PublishBuildOption} is not supported for Windows Function Apps."); } // Get the GitIgnoreParser from the functionApp root var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); var ignoreParser = PublishHelper.GetIgnoreParser(functionAppRoot); // Get the WorkerRuntime var workerRuntime = GlobalCoreToolsSettings.CurrentWorkerRuntime; // 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); // Update build option PublishBuildOption = PublishHelper.ResolveBuildOption(PublishBuildOption, workerRuntime, functionApp, BuildNativeDeps, NoBuild); if (workerRuntime == WorkerRuntime.dotnet && !Csx && !NoBuild && PublishBuildOption != BuildOption.Remote) { 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); } } }