-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pack] extension bundle probing and download #4135
Changes from 6 commits
aa468e5
0f582e3
edea3f2
33282fb
801468c
3d535d1
bd3f2d9
fe63b9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using NuGet.Versioning; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Configuration | ||
{ | ||
public class ExtensionBundleOptions | ||
{ | ||
/// <summary> | ||
/// Gets or Sets the Id of the extension bundle | ||
/// </summary> | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or Sets the version range or version of the extension bundle. | ||
/// </summary> | ||
public VersionRange Version { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the Probing path of the Extension Bundle. | ||
/// Probing path are configured by the host depending on the hosting enviroment the default location where the runtime would look for an extension bundle first. | ||
/// To be configured by the host or consuming service | ||
/// </summary> | ||
public ICollection<string> ProbingPaths { get; private set; } = new Collection<string>(); | ||
|
||
/// <summary> | ||
/// Gets or Sets the download path for the extension bundle. | ||
/// This is the path where the runtime would download the extension bundle in case it is not present at the probing path. | ||
/// To be configured by the host or consuming service | ||
/// </summary> | ||
public string DownloadPath { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or Sets a value indicating whether the runtime should force fetch the latest version of extension bundle available on CDN, even when there is a matching extension bundle available locally. | ||
/// To be configured by the host or consuming service | ||
/// </summary> | ||
public bool EnsureLatest { get; set; } | ||
soninaren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Microsoft.Azure.WebJobs.Script.Properties; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Options; | ||
using NuGet.Packaging; | ||
using NuGet.Versioning; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Configuration | ||
{ | ||
public class ExtensionBundleOptionsSetup : IConfigureOptions<ExtensionBundleOptions> | ||
{ | ||
private readonly IConfiguration _configuration; | ||
private readonly IEnvironment _environment; | ||
private readonly IHostingEnvironment _hostingEnvironment; | ||
|
||
public ExtensionBundleOptionsSetup(IConfiguration configuration, IEnvironment environment, IHostingEnvironment hostingEnvironment) | ||
{ | ||
_configuration = configuration; | ||
_environment = environment; | ||
_hostingEnvironment = hostingEnvironment; | ||
} | ||
|
||
public void Configure(ExtensionBundleOptions options) | ||
{ | ||
IConfigurationSection jobHostSection = _configuration.GetSection(ConfigurationSectionNames.JobHost); | ||
var extensionBundleSection = jobHostSection.GetSection(ConfigurationSectionNames.ExtensionBundle); | ||
|
||
if (extensionBundleSection.Exists()) | ||
{ | ||
extensionBundleSection.Bind(options); | ||
ValidateBundleId(options.Id); | ||
ConfigureBundleVersion(extensionBundleSection, options); | ||
|
||
if (_environment.IsAppServiceEnvironment() || _hostingEnvironment.IsDevelopment()) | ||
{ | ||
options.DownloadPath = Path.Combine(_environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHomePath), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is not configurable when running in those environments? (configuration will be ignored?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non AppService environment would have to override this configuration. For example core tools running in windows would set this to be a different location than core tools running in linux. |
||
"data", "Functions", ScriptConstants.ExtensionBundleDirectory, options.Id); | ||
ConfigureProbingPaths(options); | ||
} | ||
} | ||
} | ||
|
||
private void ConfigureBundleVersion(IConfigurationSection configurationSection, ExtensionBundleOptions options) | ||
{ | ||
string bundleVersion = configurationSection.GetValue<string>("version"); | ||
if (string.IsNullOrWhiteSpace(bundleVersion) || !VersionRange.TryParse(bundleVersion.ToString(), allowFloating: true, out VersionRange version)) | ||
{ | ||
string message = string.Format(Resources.ExtensionBundleConfigMissingVersion, ScriptConstants.HostMetadataFileName); | ||
throw new ArgumentException(message); | ||
} | ||
options.Version = version; | ||
} | ||
|
||
private void ValidateBundleId(string id) | ||
{ | ||
if (string.IsNullOrWhiteSpace(id) || !PackageIdValidator.IsValidPackageId(id)) | ||
{ | ||
string message = string.Format(Resources.ExtensionBundleConfigMissingId, ScriptConstants.HostMetadataFileName); | ||
throw new ArgumentException(message); | ||
} | ||
} | ||
|
||
private void ConfigureProbingPaths(ExtensionBundleOptions options) | ||
{ | ||
if (_environment.IsAppServiceWindowsEnvironment() || _hostingEnvironment.IsDevelopment()) | ||
{ | ||
string windowsDefaultPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), | ||
ScriptConstants.DefaultExtensionBundleDirectory, | ||
options.Id); | ||
|
||
options.ProbingPaths.Add(windowsDefaultPath); | ||
} | ||
|
||
if (_environment.IsLinuxAppServiceEnvironment()) | ||
{ | ||
string linuxDefaultPath = Path.Combine(Path.PathSeparator.ToString(), ScriptConstants.DefaultExtensionBundleDirectory, options.Id); | ||
|
||
string deploymentPackageBundlePath = Path.Combine( | ||
_environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHomePath), | ||
"site", "wwwroot", ".azureFunctions", ScriptConstants.ExtensionBundleDirectory, options.Id); | ||
|
||
options.ProbingPaths.Add(linuxDefaultPath); | ||
options.ProbingPaths.Add(deploymentPackageBundlePath); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in person, please add tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There aren't any tests cases for any of the controller yet. We might need to setup something in e2e tests. Have added test cases for changes to extension manager in the extension manager tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scenarios based tests would be a good place for this. Some of the examples we have are the keys controller tests.