From 1103bab89c1cf8356981a11258e0be387f414e10 Mon Sep 17 00:00:00 2001 From: Pragna Gopa Date: Mon, 2 Mar 2020 13:02:57 -0800 Subject: [PATCH] [pack][Hotfix][V2]Remove duplicate worker directories from siteextension (#5723) --- build.ps1 | 8 ++++++++ .../Configuration/RpcWorkerConfigFactory.cs | 15 ++++++++++++++- .../Workers/Rpc/RpcWorkerConfigFactoryTests.cs | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index df21b12e3c..763aa36e5a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -226,7 +226,14 @@ function CreateZips([string] $runtimeSuffix) { Rename-Item "$privateSiteExtensionPath" "$siteExtensionPath\$extensionVersion" Copy-Item .\src\WebJobs.Script.WebHost\extension.xml "$siteExtensionPath" ZipContent $siteExtensionPath "$buildOutput\Functions.$extensionVersion$runtimeSuffix.zip" +} +function deleteDuplicateWorkers() { + Write-Host "Deleting workers directory: $privateSiteExtensionPath\32bit\workers" + Remove-Item -Recurse -Force "$privateSiteExtensionPath\32bit\workers" -ErrorAction SilentlyContinue + Write-Host "Moving workers directory:$privateSiteExtensionPath\64bit\workers to" $privateSiteExtensionPath + + Move-Item -Path "$privateSiteExtensionPath\64bit\workers" -Destination "$privateSiteExtensionPath\workers" } function cleanExtension([string] $bitness) { @@ -245,6 +252,7 @@ function cleanExtension([string] $bitness) { $keepRuntimes = @('win', 'win-x86', 'win10-x86', 'win-x64', 'win10-x64') Get-ChildItem "$privateSiteExtensionPath\$bitness\workers\powershell\runtimes" -Exclude $keepRuntimes -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue + deleteDuplicateWorkers } dotnet --version diff --git a/src/WebJobs.Script/Workers/Rpc/Configuration/RpcWorkerConfigFactory.cs b/src/WebJobs.Script/Workers/Rpc/Configuration/RpcWorkerConfigFactory.cs index 6d173b35f2..47bf733d84 100644 --- a/src/WebJobs.Script/Workers/Rpc/Configuration/RpcWorkerConfigFactory.cs +++ b/src/WebJobs.Script/Workers/Rpc/Configuration/RpcWorkerConfigFactory.cs @@ -32,7 +32,8 @@ public RpcWorkerConfigFactory(IConfiguration config, ILogger logger, ISystemRunt _systemRuntimeInformation = systemRuntimeInfo ?? throw new ArgumentNullException(nameof(systemRuntimeInfo)); _environment = environment ?? throw new ArgumentNullException(nameof(environment)); _metricsLogger = metricsLogger; - WorkersDirPath = Path.Combine(Path.GetDirectoryName(new Uri(typeof(RpcWorkerConfigFactory).Assembly.CodeBase).LocalPath), RpcWorkerConstants.DefaultWorkersDirectoryName); + string assemblyLocalPath = Path.GetDirectoryName(new Uri(typeof(RpcWorkerConfigFactory).Assembly.CodeBase).LocalPath); + WorkersDirPath = GetDefaultWorkersDirectory(Directory.Exists); var workersDirectorySection = _config.GetSection($"{RpcWorkerConstants.LanguageWorkersSectionName}:{WorkerConstants.WorkersDirectorySectionName}"); if (!string.IsNullOrEmpty(workersDirectorySection.Value)) { @@ -76,6 +77,18 @@ public IList GetConfigs() } } + internal static string GetDefaultWorkersDirectory(Func directoryExists) + { + string assemblyLocalPath = Path.GetDirectoryName(new Uri(typeof(RpcWorkerConfigFactory).Assembly.CodeBase).LocalPath); + string workersDirPath = Path.Combine(assemblyLocalPath, RpcWorkerConstants.DefaultWorkersDirectoryName); + if (!directoryExists(workersDirPath)) + { + // Site Extension. Default to parent directory + workersDirPath = Path.Combine(Directory.GetParent(assemblyLocalPath).FullName, RpcWorkerConstants.DefaultWorkersDirectoryName); + } + return workersDirPath; + } + internal void BuildWorkerProviderDictionary() { AddProviders(); diff --git a/test/WebJobs.Script.Tests/Workers/Rpc/RpcWorkerConfigFactoryTests.cs b/test/WebJobs.Script.Tests/Workers/Rpc/RpcWorkerConfigFactoryTests.cs index 61f034dc7f..93b2e4fcb1 100644 --- a/test/WebJobs.Script.Tests/Workers/Rpc/RpcWorkerConfigFactoryTests.cs +++ b/test/WebJobs.Script.Tests/Workers/Rpc/RpcWorkerConfigFactoryTests.cs @@ -39,6 +39,24 @@ public void DefaultLanguageWorkersDir() Assert.Equal(expectedWorkersDir, configFactory.WorkersDirPath); } + [Fact] + public void GetDefaultWorkersDirectory_Returns_Expected() + { + string assemblyLocalPath = Path.GetDirectoryName(new Uri(typeof(RpcWorkerConfigFactory).Assembly.CodeBase).LocalPath); + string defaultWorkersDirPath = Path.Combine(assemblyLocalPath, RpcWorkerConstants.DefaultWorkersDirectoryName); + Func testDirectoryExists = path => + { + return false; + }; + var expectedWorkersDirIsCurrentDir = Path.Combine(assemblyLocalPath, RpcWorkerConstants.DefaultWorkersDirectoryName); + var expectedWorkersDirIsParentDir = Path.Combine(Directory.GetParent(assemblyLocalPath).FullName, RpcWorkerConstants.DefaultWorkersDirectoryName); + var config = new ConfigurationBuilder().Build(); + var testLogger = new TestLogger("test"); + + Assert.Equal(expectedWorkersDirIsCurrentDir, RpcWorkerConfigFactory.GetDefaultWorkersDirectory(Directory.Exists)); + Assert.Equal(expectedWorkersDirIsParentDir, RpcWorkerConfigFactory.GetDefaultWorkersDirectory(testDirectoryExists)); + } + [Fact] public void LanguageWorker_WorkersDir_Set() {