Skip to content

Commit f92e4ad

Browse files
author
Jason Zhai
committed
Merge branch 'release/8.0.3xx' of https://github.com/dotnet/sdk into darc-release/8.0.3xx-5038e008-afe0-464c-a686-df43c720eed9
2 parents 69225d6 + 511c121 commit f92e4ad

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/Containers/Microsoft.NET.Build.Containers/Tasks/ComputeDotnetBaseImageAndTag.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public sealed class ComputeDotnetBaseImageAndTag : Microsoft.Build.Utilities.Tas
8080

8181
private bool IsMuslRid => TargetRuntimeIdentifier.StartsWith("linux-musl", StringComparison.Ordinal);
8282
private bool IsBundledRuntime => IsSelfContained;
83-
private bool NeedsNightlyImages => IsAotPublished;
83+
84+
// as of March 2024, the -extra images are on stable MCR, but the -aot images are still on nightly. This means AOT, invariant apps need the /nightly/ base.
85+
private bool NeedsNightlyImages => IsAotPublished && UsesInvariantGlobalization;
8486
private bool AllowsExperimentalTagInference => String.IsNullOrEmpty(ContainerFamily);
8587

8688
public ComputeDotnetBaseImageAndTag()

src/Containers/packaging/build/Microsoft.NET.Build.Containers.targets

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
Returns="$(ContainerBaseImage)">
3636
<PropertyGroup>
3737
<!-- The Container RID should default to the RID used for the entire build (to ensure things run on the platform they are built for), but the user knows best and so should be able to set it explicitly.
38-
For builds that have a RID, we default to that RID. Otherwise, we default to the Linux RID matching the architecture of the currently-executing SDK. -->
38+
For builds that have a RID, we default to that RID. Otherwise, we default to the Linux RID matching the architecture of the currently-executing SDK. -->
3939
<ContainerRuntimeIdentifier Condition="'$(ContainerRuntimeIdentifier)' == '' and '$(IsRidAgnostic)' != 'true'">$(RuntimeIdentifier)</ContainerRuntimeIdentifier>
4040
<ContainerRuntimeIdentifier Condition="'$(ContainerRuntimeIdentifier)' == ''">linux-$(NETCoreSdkPortableRuntimeIdentifier.Split('-')[1])</ContainerRuntimeIdentifier>
4141
<_ContainerIsUsingMicrosoftDefaultImages Condition="'$(ContainerBaseImage)' == ''">true</_ContainerIsUsingMicrosoftDefaultImages>
4242
<_ContainerIsUsingMicrosoftDefaultImages Condition="'$(ContainerBaseImage)' != ''">false</_ContainerIsUsingMicrosoftDefaultImages>
4343
</PropertyGroup>
44-
44+
4545
<ComputeDotnetBaseImageAndTag
4646
Condition="$(_ContainerIsUsingMicrosoftDefaultImages)"
4747
SdkVersion="$(NetCoreSdkVersion)"
@@ -170,8 +170,13 @@
170170

171171
<!-- These sourcelink-derived properties are only allowed to flow to generated artifacts if `PublishRepositoryUrl` is set as a user signal for opt-in.
172172
In addition, the 'nice' property names are currently set by NuGet Pack targets and so we have to use the private/generic names here. -->
173+
<PropertyGroup Label="Source control label assignment" Condition="'$(ContainerGenerateLabels)' == 'true' and '$(PublishRepositoryUrl)' == 'true'">
174+
<!-- Sourcelink gives us the .git suffix, but scanning tools aren't looking for that so we trim it off here. -->
175+
<_TrimmedRepositoryUrl Condition="'$(RepositoryType)' == 'git' and '$(PrivateRepositoryUrl)' != '' and $(PrivateRepositoryUrl.EndsWith('.git'))">$(PrivateRepositoryUrl.Substring(0, $(PrivateRepositoryUrl.LastIndexOf('.git'))))</_TrimmedRepositoryUrl>
176+
<_TrimmedRepositoryUrl Condition="'$(_TrimmedRepositoryUrl)' == '' and '$(PrivateRepositoryUrl)' != ''">$(PrivateRepositoryUrl)</_TrimmedRepositoryUrl>
177+
</PropertyGroup>
173178
<ItemGroup Label="Source control label assignment" Condition="'$(ContainerGenerateLabels)' == 'true' and '$(PublishRepositoryUrl)' == 'true'">
174-
<ContainerLabel Condition="'$(ContainerGenerateLabelsImageSource)' == 'true' and '$(PrivateRepositoryUrl)' != ''" Include="org.opencontainers.image.source" Value="$(PrivateRepositoryUrl)" />
179+
<ContainerLabel Condition="'$(ContainerGenerateLabelsImageSource)' == 'true' and '$(_TrimmedRepositoryUrl)' != ''" Include="org.opencontainers.image.source" Value="$(_TrimmedRepositoryUrl)" />
175180
<ContainerLabel Condition="'$(ContainerGenerateLabelsImageRevision)' == 'true' and '$(SourceRevisionId)' != ''" Include="org.opencontainers.image.revision" Value="$(SourceRevisionId)" />
176181
</ItemGroup>
177182
</Target>

src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/TargetsTests.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,31 @@ public void ShouldNotIncludeSourceControlLabelsUnlessUserOptsIn(bool includeSour
150150
};
151151
}
152152

153+
[InlineData("https://git.cosmere.com/shard/whimsy.git", "https://git.cosmere.com/shard/whimsy")]
154+
[InlineData("https://repos.git.cosmere.com/shard/whimsy.git", "https://repos.git.cosmere.com/shard/whimsy")]
155+
[Theory]
156+
public void ShouldTrimTrailingGitSuffixFromRepoUrls(string repoUrl, string expectedLabel)
157+
{
158+
var commitHash = "abcdef";
159+
160+
static string NormalizeString(string s) => s.Replace(':', '_').Replace('/', '_');
161+
162+
var (project, logger, d) = ProjectInitializer.InitProject(new()
163+
{
164+
["PublishRepositoryUrl"] = true.ToString(),
165+
["PrivateRepositoryUrl"] = repoUrl,
166+
["SourceRevisionId"] = commitHash,
167+
["RepositoryType"] = "git"
168+
}, projectName: $"{nameof(ShouldNotIncludeSourceControlLabelsUnlessUserOptsIn)}_{NormalizeString(repoUrl)}_{NormalizeString(expectedLabel)}");
169+
using var _ = d;
170+
var instance = project.CreateProjectInstance(global::Microsoft.Build.Execution.ProjectInstanceSettings.None);
171+
instance.Build(new[] { ComputeContainerConfig }, new[] { logger }, null, out var outputs).Should().BeTrue("Build should have succeeded but failed due to {0}", String.Join("\n", logger.AllMessages));
172+
var labels = instance.GetItems(ContainerLabel);
173+
174+
labels.Should().NotBeEmpty("Should have evaluated some labels by default")
175+
.And.ContainSingle(label => LabelMatch("org.opencontainers.image.source", expectedLabel, label), String.Join(",", logger.AllMessages));
176+
}
177+
153178
[InlineData("7.0.100", "v7.0", "7.0")]
154179
[InlineData("7.0.100-preview.7", "v7.0", "7.0")]
155180
[InlineData("7.0.100-rc.1", "v7.0", "7.0")]
@@ -295,8 +320,8 @@ public void AOTAppsGetAOTImages(string rid, string expectedImage)
295320
computedBaseImageTag.Should().BeEquivalentTo(expectedImage);
296321
}
297322

298-
[InlineData("linux-musl-x64", "mcr.microsoft.com/dotnet/nightly/runtime-deps:8.0-alpine-extra")]
299-
[InlineData("linux-x64", "mcr.microsoft.com/dotnet/nightly/runtime-deps:8.0-jammy-chiseled-extra")]
323+
[InlineData("linux-musl-x64", "mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine-extra")]
324+
[InlineData("linux-x64", "mcr.microsoft.com/dotnet/runtime-deps:8.0-jammy-chiseled-extra")]
300325
[Theory]
301326
public void AOTAppsWithCulturesGetExtraImages(string rid, string expectedImage)
302327
{

0 commit comments

Comments
 (0)