From 17e9e00d4d823c7af994b0ee77eefefa811bc759 Mon Sep 17 00:00:00 2001 From: MichalPavlik Date: Tue, 11 Jun 2024 15:33:33 +0200 Subject: [PATCH 1/7] Added new set of credential env variables to be used separately for pull and push operations. Old set of variables is used for fallback. --- .../AuthHandshakeMessageHandler.cs | 47 +++++++++++++++++-- .../ContainerBuilder.cs | 3 +- .../ContainerHelpers.cs | 7 ++- .../DestinationImageReference.cs | 5 +- .../Registry/DefaultRegistryAPI.cs | 8 ++-- .../Registry/Registry.cs | 47 +++++++++++++++++-- .../Tasks/CreateNewImage.cs | 3 +- .../CreateNewImageTests.cs | 2 +- .../DockerRegistryTests.cs | 6 +-- .../EndToEndTests.cs | 8 ++-- .../RegistryTests.cs | 2 +- .../AuthHandshakeMessageHandlerTests.cs | 31 ++++++++++++ .../RegistryTests.cs | 4 +- 13 files changed, 147 insertions(+), 26 deletions(-) create mode 100644 src/Tests/Microsoft.NET.Build.Containers.UnitTests/AuthHandshakeMessageHandlerTests.cs diff --git a/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs b/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs index 94488fa74339..a036f0641833 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs @@ -36,12 +36,14 @@ private sealed record AuthInfo(string Realm, string? Service, string? Scope); private readonly string _registryName; private readonly ILogger _logger; + private readonly RegistryMode _registryMode; private static ConcurrentDictionary _authenticationHeaders = new(); - public AuthHandshakeMessageHandler(string registryName, HttpMessageHandler innerHandler, ILogger logger) : base(innerHandler) + public AuthHandshakeMessageHandler(string registryName, HttpMessageHandler innerHandler, ILogger logger, RegistryMode mode) : base(innerHandler) { _registryName = registryName; _logger = logger; + _registryMode = mode; } /// @@ -136,8 +138,7 @@ public DateTimeOffset ResolvedExpiration { private async Task<(AuthenticationHeaderValue, DateTimeOffset)?> GetAuthenticationAsync(string registry, string scheme, AuthInfo? bearerAuthInfo, CancellationToken cancellationToken) { // Allow overrides for auth via environment variables - string? credU = Environment.GetEnvironmentVariable(ContainerHelpers.HostObjectUser); - string? credP = Environment.GetEnvironmentVariable(ContainerHelpers.HostObjectPass); + (string? credU, string? credP) = GetDockerCredentialsFromEnvironment(_registryMode); // fetch creds for the host DockerCredentials? privateRepoCreds; @@ -175,6 +176,46 @@ public DateTimeOffset ResolvedExpiration { } } + /// + /// Gets docker credentials from the environment variables based on registry mode. + /// + internal static (string? credU, string? credP) GetDockerCredentialsFromEnvironment(RegistryMode mode) + { + if (mode == RegistryMode.Push) + { + string? credU = Environment.GetEnvironmentVariable(ContainerHelpers.PushHostObjectUser); + string? credP = Environment.GetEnvironmentVariable(ContainerHelpers.PushHostObjectPass); + if (string.IsNullOrEmpty(credU) || string.IsNullOrEmpty(credP)) + { + // Fallback to the old environment variables + return (Environment.GetEnvironmentVariable(ContainerHelpers.HostObjectUser), + Environment.GetEnvironmentVariable(ContainerHelpers.HostObjectPass)); + } + return (credU, credP); + } + else if (mode == RegistryMode.Pull) + { + return (Environment.GetEnvironmentVariable(ContainerHelpers.PullHostObjectUser), + Environment.GetEnvironmentVariable(ContainerHelpers.PullHostObjectPass)); + } + else if (mode == RegistryMode.PullFromOutput) + { + string? credU = Environment.GetEnvironmentVariable(ContainerHelpers.PullHostObjectUser); + string? credP = Environment.GetEnvironmentVariable(ContainerHelpers.PullHostObjectPass); + if (string.IsNullOrEmpty(credU) || string.IsNullOrEmpty(credP)) + { + // Fallback to the old environment variables + return (Environment.GetEnvironmentVariable(ContainerHelpers.HostObjectUser), + Environment.GetEnvironmentVariable(ContainerHelpers.HostObjectPass)); + } + return (credU, credP); + } + else + { + throw new InvalidEnumArgumentException(nameof(mode), (int)mode, typeof(RegistryMode)); + } + } + /// /// Implements the Docker OAuth2 Authentication flow as documented at . /// ContainerizeAsync( logger.LogTrace("Trace logging: enabled."); bool isLocalPull = string.IsNullOrEmpty(baseRegistry); - Registry? sourceRegistry = isLocalPull ? null : new Registry(baseRegistry, logger); + RegistryMode sourceRegistryMode = baseRegistry.Equals(outputRegistry, StringComparison.InvariantCultureIgnoreCase) ? RegistryMode.PullFromOutput : RegistryMode.Pull; + Registry? sourceRegistry = isLocalPull ? null : new Registry(baseRegistry, logger, sourceRegistryMode); SourceImageReference sourceImageReference = new(sourceRegistry, baseImageName, baseImageTag); DestinationImageReference destinationImageReference = DestinationImageReference.CreateFromSettings( diff --git a/src/Containers/Microsoft.NET.Build.Containers/ContainerHelpers.cs b/src/Containers/Microsoft.NET.Build.Containers/ContainerHelpers.cs index 5706c6171b5c..244ebd6cc9e4 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/ContainerHelpers.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/ContainerHelpers.cs @@ -16,9 +16,14 @@ namespace Microsoft.NET.Build.Containers; public static class ContainerHelpers { internal const string HostObjectUser = "SDK_CONTAINER_REGISTRY_UNAME"; - internal const string HostObjectPass = "SDK_CONTAINER_REGISTRY_PWORD"; + internal const string PushHostObjectUser = "SDK_CONTAINER_PUSH_REGISTRY_UNAME"; + internal const string PushHostObjectPass = "SDK_CONTAINER_PUSH_REGISTRY_PWORD"; + + internal const string PullHostObjectUser = "SDK_CONTAINER_PULL_REGISTRY_UNAME"; + internal const string PullHostObjectPass = "SDK_CONTAINER_PULL_REGISTRY_PWORD"; + internal const string DockerRegistryAlias = "docker.io"; /// diff --git a/src/Containers/Microsoft.NET.Build.Containers/DestinationImageReference.cs b/src/Containers/Microsoft.NET.Build.Containers/DestinationImageReference.cs index 46eb30ebc338..b885d791166b 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/DestinationImageReference.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/DestinationImageReference.cs @@ -75,7 +75,10 @@ public static DestinationImageReference CreateFromSettings( } else if (!string.IsNullOrEmpty(outputRegistry)) { - destinationImageReference = new DestinationImageReference(new Registry(outputRegistry, loggerFactory.CreateLogger()), repository, imageTags); + destinationImageReference = new DestinationImageReference( + new Registry(outputRegistry, loggerFactory.CreateLogger(), RegistryMode.Push), + repository, + imageTags); } else { diff --git a/src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultRegistryAPI.cs b/src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultRegistryAPI.cs index e83a4da029b3..e3bf32f39bd9 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultRegistryAPI.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultRegistryAPI.cs @@ -14,12 +14,12 @@ internal class DefaultRegistryAPI : IRegistryAPI private readonly HttpClient _client; private readonly ILogger _logger; - internal DefaultRegistryAPI(string registryName, Uri baseUri, ILogger logger) + internal DefaultRegistryAPI(string registryName, Uri baseUri, ILogger logger, RegistryMode mode) { bool isAmazonECRRegistry = baseUri.IsAmazonECRRegistry(); _baseUri = baseUri; _logger = logger; - _client = CreateClient(registryName, baseUri, logger, isAmazonECRRegistry); + _client = CreateClient(registryName, baseUri, logger, isAmazonECRRegistry, mode); Manifest = new DefaultManifestOperations(_baseUri, registryName, _client, _logger); Blob = new DefaultBlobOperations(_baseUri, registryName, _client, _logger); } @@ -28,7 +28,7 @@ internal DefaultRegistryAPI(string registryName, Uri baseUri, ILogger logger) public IManifestOperations Manifest { get; } - private static HttpClient CreateClient(string registryName, Uri baseUri, ILogger logger, bool isAmazonECRRegistry = false) + private static HttpClient CreateClient(string registryName, Uri baseUri, ILogger logger, bool isAmazonECRRegistry, RegistryMode mode) { var innerHandler = new SocketsHttpHandler(); @@ -42,7 +42,7 @@ private static HttpClient CreateClient(string registryName, Uri baseUri, ILogger }; } - HttpMessageHandler clientHandler = new AuthHandshakeMessageHandler(registryName, innerHandler, logger); + HttpMessageHandler clientHandler = new AuthHandshakeMessageHandler(registryName, innerHandler, logger, mode); if (isAmazonECRRegistry) { diff --git a/src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs b/src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs index d65dd905d9c5..b3df405b7457 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs @@ -10,6 +10,13 @@ namespace Microsoft.NET.Build.Containers; +internal enum RegistryMode +{ + Push, + Pull, + PullFromOutput +} + internal sealed class Registry { private const string DockerHubRegistry1 = "registry-1.docker.io"; @@ -27,11 +34,23 @@ internal sealed class Registry /// public string RegistryName { get; } - internal Registry(string registryName, ILogger logger, IRegistryAPI? registryAPI = null, RegistrySettings? settings = null) : - this(ContainerHelpers.TryExpandRegistryToUri(registryName), logger, registryAPI, settings) + internal Registry(string registryName, ILogger logger, RegistryMode mode, RegistrySettings? settings = null) : this( + ContainerHelpers.TryExpandRegistryToUri(registryName), logger, new RegistryApiFactory(mode), settings) + { } + + internal Registry(string registryName, ILogger logger, IRegistryAPI registryAPI, RegistrySettings? settings = null) : this( + ContainerHelpers.TryExpandRegistryToUri(registryName), logger, new RegistryApiFactory(registryAPI), settings) { } - internal Registry(Uri baseUri, ILogger logger, IRegistryAPI? registryAPI = null, RegistrySettings? settings = null) + internal Registry(Uri baseUri, ILogger logger, IRegistryAPI registryAPI, RegistrySettings? settings = null) : + this(baseUri, logger, new RegistryApiFactory(registryAPI), settings) + { } + + internal Registry(Uri baseUri, ILogger logger, RegistryMode mode, RegistrySettings? settings = null) : + this(baseUri, logger, new RegistryApiFactory(mode), settings) + { } + + private Registry(Uri baseUri, ILogger logger, RegistryApiFactory factory, RegistrySettings? settings = null) { RegistryName = DeriveRegistryName(baseUri); @@ -44,7 +63,7 @@ internal Registry(Uri baseUri, ILogger logger, IRegistryAPI? registryAPI = null, _logger = logger; _settings = settings ?? new RegistrySettings(); - _registryAPI = registryAPI ?? new DefaultRegistryAPI(RegistryName, BaseUri, logger); + _registryAPI = factory.Create(RegistryName, BaseUri, logger); } private static string DeriveRegistryName(Uri baseUri) @@ -442,4 +461,24 @@ private async Task PushAsync(BuiltImage builtImage, SourceImageReference source, _logger.LogInformation(Strings.Registry_ManifestUploaded, RegistryName); } } + + private readonly ref struct RegistryApiFactory + { + private readonly IRegistryAPI? _registryApi; + private readonly RegistryMode? _mode; + public RegistryApiFactory(IRegistryAPI registryApi) + { + _registryApi = registryApi; + } + + public RegistryApiFactory(RegistryMode mode) + { + _mode = mode; + } + + public IRegistryAPI Create(string registryName, Uri baseUri, ILogger logger) + { + return _registryApi ?? new DefaultRegistryAPI(registryName, baseUri, logger, _mode!.Value); + } + } } diff --git a/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs b/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs index 669edba9590e..367d1552c2f6 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs @@ -48,7 +48,8 @@ internal async Task ExecuteAsync(CancellationToken cancellationToken) return !Log.HasLoggedErrors; } - Registry? sourceRegistry = IsLocalPull ? null : new Registry(BaseRegistry, logger); + RegistryMode sourceRegistryMode = BaseRegistry.Equals(OutputRegistry, StringComparison.InvariantCultureIgnoreCase) ? RegistryMode.PullFromOutput : RegistryMode.Pull; + Registry? sourceRegistry = IsLocalPull ? null : new Registry(BaseRegistry, logger, sourceRegistryMode); SourceImageReference sourceImageReference = new(sourceRegistry, BaseImageName, BaseImageTag); DestinationImageReference destinationImageReference = DestinationImageReference.CreateFromSettings( diff --git a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/CreateNewImageTests.cs b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/CreateNewImageTests.cs index 0d3ee20642d5..d79db49d7020 100644 --- a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/CreateNewImageTests.cs +++ b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/CreateNewImageTests.cs @@ -225,7 +225,7 @@ public async System.Threading.Tasks.Task CreateNewImage_RootlessBaseImage() var logger = loggerFactory.CreateLogger(nameof(CreateNewImage_RootlessBaseImage)); // Build a rootless base runtime image. - Registry registry = new Registry(DockerRegistryManager.LocalRegistry, logger); + Registry registry = new(DockerRegistryManager.LocalRegistry, logger, RegistryMode.Push); ImageBuilder imageBuilder = await registry.GetImageManifestAsync( DockerRegistryManager.RuntimeBaseImage, diff --git a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/DockerRegistryTests.cs b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/DockerRegistryTests.cs index 4d4f5df614ef..c1e9a19d5a4f 100644 --- a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/DockerRegistryTests.cs +++ b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/DockerRegistryTests.cs @@ -22,7 +22,7 @@ public async Task GetFromRegistry() { var loggerFactory = new TestLoggerFactory(_testOutput); var logger = loggerFactory.CreateLogger(nameof(GetFromRegistry)); - Registry registry = new Registry(DockerRegistryManager.LocalRegistry, logger); + Registry registry = new(DockerRegistryManager.LocalRegistry, logger, RegistryMode.Push); var ridgraphfile = ToolsetUtils.GetRuntimeGraphFilePath(); // Don't need rid graph for local registry image pulls - since we're only pushing single image manifests (not manifest lists) @@ -73,9 +73,9 @@ public async Task WriteToPrivateBasicRegistry() // login to that registry ContainerCli.LoginCommand(_testOutput, "--username", "testuser", "--password", "testpassword", registryName).Execute().Should().Pass(); // push an image to that registry using username/password - Registry localAuthed = new Registry(new Uri($"https://{registryName}"), logger, settings: new() { ParallelUploadEnabled = false, ForceChunkedUpload = true }); + Registry localAuthed = new(new Uri($"https://{registryName}"), logger, RegistryMode.Push, settings: new() { ParallelUploadEnabled = false, ForceChunkedUpload = true }); var ridgraphfile = ToolsetUtils.GetRuntimeGraphFilePath(); - Registry mcr = new Registry(DockerRegistryManager.BaseImageSource, logger); + Registry mcr = new(DockerRegistryManager.BaseImageSource, logger, RegistryMode.Pull); var sourceImage = new SourceImageReference(mcr, DockerRegistryManager.RuntimeBaseImage, DockerRegistryManager.Net6ImageTag); var destinationImage = new DestinationImageReference(localAuthed, DockerRegistryManager.RuntimeBaseImage,new[] { DockerRegistryManager.Net6ImageTag }); diff --git a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs index c012fbd153f3..8aad9aae4eda 100644 --- a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs +++ b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs @@ -46,7 +46,7 @@ public async Task ApiEndToEndWithRegistryPushAndPull() // Build the image - Registry registry = new Registry(DockerRegistryManager.LocalRegistry, logger); + Registry registry = new(DockerRegistryManager.LocalRegistry, logger, RegistryMode.Push); ImageBuilder imageBuilder = await registry.GetImageManifestAsync( DockerRegistryManager.RuntimeBaseImage, @@ -93,7 +93,7 @@ public async Task ApiEndToEndWithLocalLoad() // Build the image - Registry registry = new Registry(DockerRegistryManager.LocalRegistry, logger); + Registry registry = new(DockerRegistryManager.LocalRegistry, logger, RegistryMode.Push); ImageBuilder imageBuilder = await registry.GetImageManifestAsync( DockerRegistryManager.RuntimeBaseImage, @@ -134,7 +134,7 @@ public async Task ApiEndToEndWithArchiveWritingAndLoad() // Build the image - Registry registry = new Registry(DockerRegistryManager.LocalRegistry, logger); + Registry registry = new(DockerRegistryManager.LocalRegistry, logger, RegistryMode.Push); ImageBuilder imageBuilder = await registry.GetImageManifestAsync( DockerRegistryManager.RuntimeBaseImage, @@ -479,7 +479,7 @@ public async Task CanPackageForAllSupportedContainerRIDs(string dockerPlatform, string publishDirectory = BuildLocalApp(tfm: ToolsetInfo.CurrentTargetFramework, rid: rid); // Build the image - Registry registry = new(DockerRegistryManager.BaseImageSource, logger); + Registry registry = new(DockerRegistryManager.BaseImageSource, logger, RegistryMode.Pull); var isWin = rid.StartsWith("win"); ImageBuilder? imageBuilder = await registry.GetImageManifestAsync( DockerRegistryManager.RuntimeBaseImage, diff --git a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/RegistryTests.cs b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/RegistryTests.cs index 92bede0342c3..8b848ba6e524 100644 --- a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/RegistryTests.cs +++ b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/RegistryTests.cs @@ -39,7 +39,7 @@ public async Task CanReadManifestFromRegistry(string fullyQualifiedContainerName containerTag ??= "latest"; ILogger logger = _loggerFactory.CreateLogger(nameof(CanReadManifestFromRegistry)); - Registry registry = new Registry(containerRegistry, logger); + Registry registry = new(registryName, logger, RegistryMode.Pull); var ridgraphfile = ToolsetUtils.GetRuntimeGraphFilePath(); diff --git a/src/Tests/Microsoft.NET.Build.Containers.UnitTests/AuthHandshakeMessageHandlerTests.cs b/src/Tests/Microsoft.NET.Build.Containers.UnitTests/AuthHandshakeMessageHandlerTests.cs new file mode 100644 index 000000000000..04ec702cd184 --- /dev/null +++ b/src/Tests/Microsoft.NET.Build.Containers.UnitTests/AuthHandshakeMessageHandlerTests.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +namespace Microsoft.NET.Build.Containers.UnitTests +{ + public class AuthHandshakeMessageHandlerTests + { + [Theory] + [InlineData("SDK_CONTAINER_REGISTRY_UNAME", "SDK_CONTAINER_REGISTRY_PWORD", (int)RegistryMode.Push)] + [InlineData("SDK_CONTAINER_PUSH_REGISTRY_UNAME", "SDK_CONTAINER_PUSH_REGISTRY_PWORD", (int)RegistryMode.Push)] + [InlineData("SDK_CONTAINER_PULL_REGISTRY_UNAME", "SDK_CONTAINER_PULL_REGISTRY_PWORD", (int)RegistryMode.Pull)] + [InlineData("SDK_CONTAINER_PULL_REGISTRY_UNAME", "SDK_CONTAINER_PULL_REGISTRY_PWORD", (int)RegistryMode.PullFromOutput)] + [InlineData("SDK_CONTAINER_REGISTRY_UNAME", "SDK_CONTAINER_REGISTRY_PWORD", (int)RegistryMode.PullFromOutput)] + public void GetDockerCredentialsFromEnvironment_ReturnsCorrectValues(string unameVarName, string pwordVarName, int mode) + { + string? originalUnameValue = Environment.GetEnvironmentVariable(unameVarName); + string? originalPwordValue = Environment.GetEnvironmentVariable(pwordVarName); + + Environment.SetEnvironmentVariable(unameVarName, "uname"); + Environment.SetEnvironmentVariable(pwordVarName, "pword"); + + (string? credU, string? credP) = AuthHandshakeMessageHandler.GetDockerCredentialsFromEnvironment((RegistryMode)mode); + + Assert.Equal("uname", credU); + Assert.Equal("pword", credP); + + // restore env variable values + Environment.SetEnvironmentVariable(unameVarName, originalUnameValue); + Environment.SetEnvironmentVariable(pwordVarName, originalPwordValue); + } + } +} diff --git a/src/Tests/Microsoft.NET.Build.Containers.UnitTests/RegistryTests.cs b/src/Tests/Microsoft.NET.Build.Containers.UnitTests/RegistryTests.cs index 3c3fba3d2cd6..87f81f3b85e5 100644 --- a/src/Tests/Microsoft.NET.Build.Containers.UnitTests/RegistryTests.cs +++ b/src/Tests/Microsoft.NET.Build.Containers.UnitTests/RegistryTests.cs @@ -30,7 +30,7 @@ public void Dispose() public void CheckIfGoogleArtifactRegistry(string registryName, bool isECR) { ILogger logger = _loggerFactory.CreateLogger(nameof(CheckIfGoogleArtifactRegistry)); - Registry registry = new Registry(registryName, logger); + Registry registry = new(registryName, logger, RegistryMode.Push); Assert.Equal(isECR, registry.IsGoogleArtifactRegistry); } @@ -38,7 +38,7 @@ public void CheckIfGoogleArtifactRegistry(string registryName, bool isECR) public void DockerIoAlias() { ILogger logger = _loggerFactory.CreateLogger(nameof(DockerIoAlias)); - Registry registry = new Registry("docker.io", logger); + Registry registry = new("docker.io", logger, RegistryMode.Push); Assert.True(registry.IsDockerHub); Assert.Equal("docker.io", registry.RegistryName); Assert.Equal("registry-1.docker.io", registry.BaseUri.Host); From 5c1acb706c0670c09762f0de29fe527a90fd4e41 Mon Sep 17 00:00:00 2001 From: MichalPavlik Date: Tue, 11 Jun 2024 16:15:47 +0200 Subject: [PATCH 2/7] Resolving conflict --- .../Registry/DefaultRegistryAPI.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultRegistryAPI.cs b/src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultRegistryAPI.cs index e3bf32f39bd9..015ea7d535de 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultRegistryAPI.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultRegistryAPI.cs @@ -14,6 +14,14 @@ internal class DefaultRegistryAPI : IRegistryAPI private readonly HttpClient _client; private readonly ILogger _logger; + // Empirical value - Unoptimized .NET application layers can be ~200MB + // * .NET Runtime (~80MB) + // * ASP.NET Runtime (~25MB) + // * application and dependencies - variable, but _probably_ not more than the BCL? + // Given a 200MB target and a 1Mb/s upload speed, we'd expect an upload speed of 27m:57s. + // Making this a round 30 for convenience. + private static TimeSpan LongRequestTimeout = TimeSpan.FromMinutes(30); + internal DefaultRegistryAPI(string registryName, Uri baseUri, ILogger logger, RegistryMode mode) { bool isAmazonECRRegistry = baseUri.IsAmazonECRRegistry(); @@ -30,7 +38,12 @@ internal DefaultRegistryAPI(string registryName, Uri baseUri, ILogger logger, Re private static HttpClient CreateClient(string registryName, Uri baseUri, ILogger logger, bool isAmazonECRRegistry, RegistryMode mode) { - var innerHandler = new SocketsHttpHandler(); + var innerHandler = new SocketsHttpHandler() + { + UseCookies = false, + // the rest of the HTTP stack has an very long timeout (see below) but we should still have a reasonable timeout for the initial connection + ConnectTimeout = TimeSpan.FromSeconds(30) + }; // Ignore certificate for https localhost repository. if (baseUri.Host == "localhost" && baseUri.Scheme == "https") @@ -49,7 +62,10 @@ private static HttpClient CreateClient(string registryName, Uri baseUri, ILogger clientHandler = new AmazonECRMessageHandler(clientHandler); } - HttpClient client = new(clientHandler); + HttpClient client = new(clientHandler) + { + Timeout = LongRequestTimeout + }; client.DefaultRequestHeaders.Add("User-Agent", $".NET Container Library v{Constants.Version}"); From de2497352cd3c71f9720ce0bc3b996d198f5aff8 Mon Sep 17 00:00:00 2001 From: MichalPavlik Date: Tue, 11 Jun 2024 17:21:57 +0200 Subject: [PATCH 3/7] Added missing using --- .../AuthHandshakeMessageHandler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs b/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs index a036f0641833..56ce998e79dd 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Concurrent; +using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Net; From 80e3001293fd53ebe14d9579bc8730248483ca0e Mon Sep 17 00:00:00 2001 From: MichalPavlik Date: Wed, 12 Jun 2024 13:44:30 +0200 Subject: [PATCH 4/7] Fixed compilation error --- .../RegistryTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/RegistryTests.cs b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/RegistryTests.cs index 8b848ba6e524..8e25c9b13724 100644 --- a/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/RegistryTests.cs +++ b/src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/RegistryTests.cs @@ -39,7 +39,7 @@ public async Task CanReadManifestFromRegistry(string fullyQualifiedContainerName containerTag ??= "latest"; ILogger logger = _loggerFactory.CreateLogger(nameof(CanReadManifestFromRegistry)); - Registry registry = new(registryName, logger, RegistryMode.Pull); + Registry registry = new(containerRegistry, logger, RegistryMode.Pull); var ridgraphfile = ToolsetUtils.GetRuntimeGraphFilePath(); From 124f99ebb239fccc53037aabf7f96d30035b2521 Mon Sep 17 00:00:00 2001 From: DotNet-Bot Date: Tue, 16 Jul 2024 22:58:33 +0000 Subject: [PATCH 5/7] Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-runtime build 20240716.12 Microsoft.NET.HostModel , Microsoft.NET.ILLink.Tasks , Microsoft.NETCore.App.Host.win-x64 , Microsoft.NETCore.App.Ref , Microsoft.NETCore.App.Runtime.win-x64 , Microsoft.NETCore.DotNetHostResolver , Microsoft.NETCore.Platforms , VS.Redist.Common.NetCore.SharedFramework.x64.8.0 , VS.Redist.Common.NetCore.TargetingPack.x64.8.0 From Version 8.0.7-servicing.24313.11 -> To Version 8.0.8-servicing.24366.12 Dependency coherency updates Microsoft.NET.Workload.Emscripten.Current.Manifest-8.0.100 From Version 8.0.7 -> To Version 8.0.8 (parent: Microsoft.NETCore.App.Runtime.win-x64 --- NuGet.config | 8 +++----- eng/Version.Details.xml | 40 ++++++++++++++++++++-------------------- eng/Versions.props | 14 +++++++------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/NuGet.config b/NuGet.config index d8dc69e028a6..3e4e690d5199 100644 --- a/NuGet.config +++ b/NuGet.config @@ -3,11 +3,7 @@ - - - - - + @@ -30,6 +26,7 @@ + @@ -74,6 +71,7 @@ + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 77a840e8574b..0770d9e167bf 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -14,46 +14,46 @@ 5cab53780897ef7a8e212e10732af54c0a7e597f - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - 2aade6beb02ea367fd97c4070a4198802fe61c03 + 08338fcaa5c9b9a8190abb99222fed12aaba956c - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - 2aade6beb02ea367fd97c4070a4198802fe61c03 + 08338fcaa5c9b9a8190abb99222fed12aaba956c - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - 2aade6beb02ea367fd97c4070a4198802fe61c03 + 08338fcaa5c9b9a8190abb99222fed12aaba956c - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - 2aade6beb02ea367fd97c4070a4198802fe61c03 + 08338fcaa5c9b9a8190abb99222fed12aaba956c - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - 2aade6beb02ea367fd97c4070a4198802fe61c03 + 08338fcaa5c9b9a8190abb99222fed12aaba956c - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - 2aade6beb02ea367fd97c4070a4198802fe61c03 + 08338fcaa5c9b9a8190abb99222fed12aaba956c - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - 2aade6beb02ea367fd97c4070a4198802fe61c03 + 08338fcaa5c9b9a8190abb99222fed12aaba956c https://dev.azure.com/dnceng/internal/_git/dotnet-runtime 2aade6beb02ea367fd97c4070a4198802fe61c03 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - 2aade6beb02ea367fd97c4070a4198802fe61c03 + 08338fcaa5c9b9a8190abb99222fed12aaba956c - + https://github.com/dotnet/emsdk - a64772f521c578bc9925578b1384d3a08a02d31d + e92f92efe5854b6fe013787830b59166cb9b4ed9 https://github.com/dotnet/msbuild @@ -200,9 +200,9 @@ https://github.com/microsoft/vstest aa59400b11e1aeee2e8af48928dbd48748a8bef9 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - 2aade6beb02ea367fd97c4070a4198802fe61c03 + 08338fcaa5c9b9a8190abb99222fed12aaba956c https://dev.azure.com/dnceng/internal/_git/dotnet-runtime diff --git a/eng/Versions.props b/eng/Versions.props index a1b99a522747..7af4264bd80a 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -48,18 +48,18 @@ - 8.0.7 - 8.0.7-servicing.24313.11 - 8.0.7 + 8.0.8 + 8.0.8-servicing.24366.12 + 8.0.8 $(MicrosoftNETCoreAppRuntimewinx64PackageVersion) 8.0.1 - 8.0.7 - 8.0.7-servicing.24313.11 + 8.0.8 + 8.0.8-servicing.24366.12 8.0.0 8.0.0 8.0.1 8.0.0 - 8.0.7 + 8.0.8 8.0.0 8.0.0 8.0.7 @@ -222,7 +222,7 @@ - 8.0.7 + 8.0.8 $(MicrosoftNETWorkloadEmscriptenCurrentManifest80100PackageVersion) 8.0.100$([System.Text.RegularExpressions.Regex]::Match($(EmscriptenWorkloadManifestVersion), `-rtm|-[A-z]*\.*\d*`)) From 29d146c103146600ac4a3aed4ff538f121a5ce3c Mon Sep 17 00:00:00 2001 From: DotNet-Bot Date: Wed, 17 Jul 2024 07:06:00 +0000 Subject: [PATCH 6/7] Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-windowsdesktop build 20240716.8 Microsoft.WindowsDesktop.App.Ref , Microsoft.WindowsDesktop.App.Runtime.win-x64 , VS.Redist.Common.WindowsDesktop.SharedFramework.x64.8.0 , VS.Redist.Common.WindowsDesktop.TargetingPack.x64.8.0 From Version 8.0.7 -> To Version 8.0.8 Dependency coherency updates Microsoft.NET.Sdk.WindowsDesktop From Version 8.0.7-servicing.24313.7 -> To Version 8.0.8-servicing.24366.7 (parent: Microsoft.WindowsDesktop.App.Ref --- NuGet.config | 12 ++---------- eng/Version.Details.xml | 20 ++++++++++---------- eng/Versions.props | 2 +- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/NuGet.config b/NuGet.config index 3e4e690d5199..7bf3302e13e1 100644 --- a/NuGet.config +++ b/NuGet.config @@ -32,11 +32,7 @@ - - - - - + @@ -79,11 +75,7 @@ - - - - - + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 0770d9e167bf..758fe08914d0 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -220,25 +220,25 @@ https://dev.azure.com/dnceng/internal/_git/dotnet-runtime 5535e31a712343a63f5d7d796cd874e563e5ac14 - + https://dev.azure.com/dnceng/internal/_git/dotnet-windowsdesktop - 28ae95bc8703be1ebc194391b03b6477cf59bed2 + 1526afd4eae1d862d586402ef8e005151a919d52 - + https://dev.azure.com/dnceng/internal/_git/dotnet-windowsdesktop - 28ae95bc8703be1ebc194391b03b6477cf59bed2 + 1526afd4eae1d862d586402ef8e005151a919d52 - + https://dev.azure.com/dnceng/internal/_git/dotnet-windowsdesktop - 28ae95bc8703be1ebc194391b03b6477cf59bed2 + 1526afd4eae1d862d586402ef8e005151a919d52 - + https://dev.azure.com/dnceng/internal/_git/dotnet-windowsdesktop - 28ae95bc8703be1ebc194391b03b6477cf59bed2 + 1526afd4eae1d862d586402ef8e005151a919d52 - + https://dev.azure.com/dnceng/internal/_git/dotnet-wpf - 43bb8cc831c2658e1117415019264bfe6f644f94 + 883fc207bb50622d4458ff09ae6a62548783826a https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore diff --git a/eng/Versions.props b/eng/Versions.props index 7af4264bd80a..8aba51d64e38 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -178,7 +178,7 @@ - 8.0.7-servicing.24313.7 + 8.0.8-servicing.24366.7 From 2a6a4da77325ef8ea56ce5b3eb1a4ee8fa4f842d Mon Sep 17 00:00:00 2001 From: DotNet-Bot Date: Sat, 20 Jul 2024 00:32:31 +0000 Subject: [PATCH 7/7] Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore build 20240719.8 dotnet-dev-certs , dotnet-user-jwts , dotnet-user-secrets , Microsoft.AspNetCore.Analyzers , Microsoft.AspNetCore.App.Ref , Microsoft.AspNetCore.App.Ref.Internal , Microsoft.AspNetCore.App.Runtime.win-x64 , Microsoft.AspNetCore.Authorization , Microsoft.AspNetCore.Components.SdkAnalyzers , Microsoft.AspNetCore.Components.Web , Microsoft.AspNetCore.DeveloperCertificates.XPlat , Microsoft.AspNetCore.Mvc.Analyzers , Microsoft.AspNetCore.Mvc.Api.Analyzers , Microsoft.AspNetCore.TestHost , Microsoft.Extensions.FileProviders.Embedded , Microsoft.Extensions.ObjectPool , Microsoft.JSInterop , VS.Redist.Common.AspNetCore.SharedFramework.x64.8.0 From Version 8.0.7-servicing.24314.2 -> To Version 8.0.8-servicing.24369.8 --- NuGet.config | 12 ++----- eng/Version.Details.xml | 72 ++++++++++++++++++++--------------------- eng/Versions.props | 16 ++++----- 3 files changed, 46 insertions(+), 54 deletions(-) diff --git a/NuGet.config b/NuGet.config index 7bf3302e13e1..631ac8ba8501 100644 --- a/NuGet.config +++ b/NuGet.config @@ -9,11 +9,7 @@ - - - - - + @@ -57,11 +53,7 @@ - - - - - + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 758fe08914d0..e2495fb3e9dd 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -111,13 +111,13 @@ https://github.com/dotnet/roslyn 2975b0a592ac27549e1b9d0e786243f9cb569316 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 https://dev.azure.com/devdiv/DevDiv/_git/NuGet-NuGet.Client-Trusted @@ -240,50 +240,50 @@ https://dev.azure.com/dnceng/internal/_git/dotnet-wpf 883fc207bb50622d4458ff09ae6a62548783826a - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 https://github.com/dotnet/razor @@ -298,21 +298,21 @@ https://github.com/dotnet/razor d135dd8d2ec1c2fbdee220e8656b308694e17a4b - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 https://github.com/dotnet/xdt @@ -429,9 +429,9 @@ https://dev.azure.com/dnceng/internal/_git/dotnet-runtime 5535e31a712343a63f5d7d796cd874e563e5ac14 - + https://dev.azure.com/dnceng/internal/_git/dotnet-aspnetcore - 2f1db20456007c9515068a35a65afdf99af70bc6 + 954f61dd38b33caa2b736c73530bd5a294174437 https://dev.azure.com/dnceng/internal/_git/dotnet-runtime diff --git a/eng/Versions.props b/eng/Versions.props index 8aba51d64e38..84b7dbd0378f 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -62,7 +62,7 @@ 8.0.8 8.0.0 8.0.0 - 8.0.7 + 8.0.8 8.0.0 8.0.0 8.0.0 @@ -162,13 +162,13 @@ - 8.0.7 - 8.0.7-servicing.24314.2 - 8.0.7-servicing.24314.2 - 8.0.7-servicing.24314.2 - 8.0.7-servicing.24314.2 - 8.0.7-servicing.24314.2 - 8.0.7 + 8.0.8 + 8.0.8-servicing.24369.8 + 8.0.8-servicing.24369.8 + 8.0.8-servicing.24369.8 + 8.0.8-servicing.24369.8 + 8.0.8-servicing.24369.8 + 8.0.8