Merged PR 797274: Allow loading hosted pool configuration file from env variables

This commit is contained in:
Julian Bayardo 2024-07-29 17:32:25 +00:00
Родитель b633c1e25b
Коммит 4bc86f2548
3 изменённых файлов: 22 добавлений и 6 удалений

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

@ -41,9 +41,7 @@ namespace BuildXL.Cache.BuildCacheResource.Helper
throw new ArgumentNullException(nameof(content), "The containing JSON is null");
}
var hostedPoolBuildCacheConfiguration = new HostedPoolBuildCacheConfiguration { AssociatedBuildCaches = buildCaches! };
return hostedPoolBuildCacheConfiguration;
return new HostedPoolBuildCacheConfiguration { AssociatedBuildCaches = buildCaches! };
}
/// <summary>
@ -53,7 +51,7 @@ namespace BuildXL.Cache.BuildCacheResource.Helper
public static bool TrySelectBuildCache(this HostedPoolBuildCacheConfiguration hostedPoolBuildCacheConfiguration, string? hostedPoolActiveBuildCacheName, out BuildCacheConfiguration? buildCacheConfiguration)
{
// If an active cache is not provided, the first one in the collection of associated caches is the default
if (hostedPoolBuildCacheConfiguration is null)
if (string.IsNullOrEmpty(hostedPoolActiveBuildCacheName))
{
buildCacheConfiguration = hostedPoolBuildCacheConfiguration!.AssociatedBuildCaches.First();
return true;

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

@ -177,6 +177,18 @@ namespace BuildXL.Cache.MemoizationStoreAdapter
[DefaultValue(false)]
public bool IsReadOnly { get; set; }
/// <summary>
/// Authenticate by using a file that contains a <see cref="HostedPoolBuildCacheConfigurationFile"/>
/// </summary>
/// <remarks>
/// The preferred authentication method is to use a managed identity (<see cref="StorageAccountEndpoint"/>
/// and <see cref="ManagedIdentityId"/>). However, this is unsupported for sharded scenarios and isn't
/// available outside of Azure. Use <see cref="ConnectionStringFileEnvironmentVariableName"/> if that's
/// your use-case.
/// </remarks>
[DefaultValue("BlobCacheFactoryHostedPoolConfigurationFile")]
public string HostedPoolBuildCacheConfigurationFileEnvironmentVariableName { get; set; }
/// <summary>
/// When not null, we are running on the context of 1ESHP and a set of cache resources are associated to the pool. The value of this string points
/// to the JSON file describing this topology.

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

@ -43,9 +43,15 @@ namespace BuildXL.Cache.MemoizationStoreAdapter
var context = new OperationContext(tracingContext);
// Case where an ADO build cache resource is configured
if (configuration.HostedPoolBuildCacheConfigurationFile != null)
var hostedPoolConfigurationFilePath = configuration.HostedPoolBuildCacheConfigurationFile;
if (string.IsNullOrEmpty(hostedPoolConfigurationFilePath) && !string.IsNullOrEmpty(configuration.HostedPoolBuildCacheConfigurationFileEnvironmentVariableName))
{
var hostedPoolBuildCacheConfiguration = BuildCacheResourceHelper.LoadFromJSONAsync(configuration.HostedPoolBuildCacheConfigurationFile).GetAwaiter().GetResult();
hostedPoolConfigurationFilePath = Environment.GetEnvironmentVariable(configuration.HostedPoolBuildCacheConfigurationFileEnvironmentVariableName);
}
if (!string.IsNullOrEmpty(hostedPoolConfigurationFilePath))
{
var hostedPoolBuildCacheConfiguration = BuildCacheResourceHelper.LoadFromJSONAsync(hostedPoolConfigurationFilePath).GetAwaiter().GetResult();
if (!hostedPoolBuildCacheConfiguration.TrySelectBuildCache(configuration.HostedPoolActiveBuildCacheName, out var selectedBuildCacheConfiguration))
{