Skip to content

Commit 8d97cd8

Browse files
committed
FDD jammy apps with globalization that opt into chiseled need -extra
1 parent bd03e2f commit 8d97cd8

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public override bool Execute()
107107

108108
private bool ComputeRepositoryAndTag([NotNullWhen(true)] out string? repository, [NotNullWhen(true)] out string? tag)
109109
{
110-
if (ComputeVersionPart() is (string baseVersionPart, bool versionAllowsUsingAOTAndExtrasImages))
110+
if (ComputeVersionPart() is (string baseVersionPart, SemanticVersion parsedVersion, bool versionAllowsUsingAOTAndExtrasImages))
111111
{
112112
Log.LogMessage("Computed base version tag of {0} from TFM {1} and SDK {2}", baseVersionPart, TargetFrameworkVersion, SdkVersion);
113113
if (baseVersionPart is null)
@@ -133,6 +133,22 @@ private bool ComputeRepositoryAndTag([NotNullWhen(true)] out string? repository,
133133
// for the inferred image tags, 'family' aka 'flavor' comes after the 'version' portion (including any preview/rc segments).
134134
// so it's safe to just append here
135135
tag += $"-{ContainerFamily}";
136+
Log.LogMessage("Using user-provided ContainerFamily");
137+
138+
// we can do one final check here: if the containerfamily is the 'default' for the RID
139+
// in question, and the app is globalized, we can help and add -extra so the app will actually run
140+
141+
if (
142+
(!IsMuslRid && ContainerFamily == "jammy-chiseled") // default for linux RID
143+
&& !UsesInvariantGlobalization
144+
&& versionAllowsUsingAOTAndExtrasImages
145+
// the extras only became available on the stable tags of the FirstVersionWithNewTaggingScheme
146+
&& (!parsedVersion.IsPrerelease && parsedVersion.Major == FirstVersionWithNewTaggingScheme))
147+
{
148+
Log.LogMessage("Using extra variant because the application needs globalization");
149+
tag += "-extra";
150+
}
151+
136152
return true;
137153
}
138154
else
@@ -180,18 +196,18 @@ private bool ComputeRepositoryAndTag([NotNullWhen(true)] out string? repository,
180196
}
181197
}
182198

183-
private (string, bool)? ComputeVersionPart()
199+
private (string, SemanticVersion, bool)? ComputeVersionPart()
184200
{
185201
if (SemanticVersion.TryParse(TargetFrameworkVersion, out var tfm) && tfm.Major < FirstVersionWithNewTaggingScheme)
186202
{
187203
// < 8 TFMs don't support the -aot and -extras images
188-
return ($"{tfm.Major}.{tfm.Minor}", false);
204+
return ($"{tfm.Major}.{tfm.Minor}", tfm, false);
189205
}
190206
else if (SemanticVersion.TryParse(SdkVersion, out var version))
191207
{
192208
if (ComputeVersionInternal(version, tfm) is string majMinor)
193209
{
194-
return (majMinor, true);
210+
return (majMinor, version, true);
195211
}
196212
else
197213
{

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public void WindowsUsersGetLinuxContainers(string sdkPortableRid, string expecte
260260
[InlineData("8.0.100-preview.2", "v8.0", "jammy", "8.0.0-preview.2-jammy")]
261261
[InlineData("8.0.100-preview.2", "v8.0", "jammy-chiseled", "8.0.0-preview.2-jammy-chiseled")]
262262
[InlineData("8.0.100-rc.2", "v8.0", "jammy-chiseled", "8.0.0-rc.2-jammy-chiseled")]
263-
[InlineData("8.0.100", "v8.0", "jammy-chiseled", "8.0-jammy-chiseled")]
263+
[InlineData("8.0.100", "v8.0", "jammy-chiseled", "8.0-jammy-chiseled-extra")]
264264
[Theory]
265265
public void CanTakeContainerBaseFamilyIntoAccount(string sdkVersion, string tfmMajMin, string containerFamily, string expectedTag)
266266
{
@@ -383,6 +383,47 @@ public void AOTAppsLessThan8DoNotGetAOTImages(string rid, string expectedImage)
383383
computedBaseImageTag.Should().BeEquivalentTo(expectedImage);
384384
}
385385

386+
[Fact]
387+
public void FDDConsoleAppWithCulturesAndOptingIntoChiseledGetsExtras()
388+
{
389+
var expectedImage = "mcr.microsoft.com/dotnet/runtime:8.0-jammy-chiseled-extra";
390+
var (project, logger, d) = ProjectInitializer.InitProject(new()
391+
{
392+
["NetCoreSdkVersion"] = "8.0.100",
393+
["TargetFrameworkVersion"] = "v8.0",
394+
[KnownStrings.Properties.ContainerRuntimeIdentifier] = "linux-x64",
395+
[KnownStrings.Properties.ContainerFamily] = "jammy-chiseled",
396+
[KnownStrings.Properties.InvariantGlobalization] = false.ToString(),
397+
}, projectName: $"{nameof(FDDConsoleAppWithCulturesAndOptingIntoChiseledGetsExtras)}");
398+
using var _ = d;
399+
var instance = project.CreateProjectInstance(global::Microsoft.Build.Execution.ProjectInstanceSettings.None);
400+
instance.Build(new[] { ComputeContainerBaseImage }, null, null, out var outputs).Should().BeTrue(String.Join(Environment.NewLine, logger.Errors));
401+
var computedBaseImageTag = instance.GetProperty(ContainerBaseImage)?.EvaluatedValue;
402+
computedBaseImageTag.Should().BeEquivalentTo(expectedImage);
403+
}
404+
405+
[Fact]
406+
public void FDDAspNetAppWithCulturesAndOptingIntoChiseledGetsExtras()
407+
{
408+
var expectedImage = "mcr.microsoft.com/dotnet/aspnet:8.0-jammy-chiseled-extra";
409+
var (project, logger, d) = ProjectInitializer.InitProject(new()
410+
{
411+
["NetCoreSdkVersion"] = "8.0.100",
412+
["TargetFrameworkVersion"] = "v8.0",
413+
[KnownStrings.Properties.ContainerRuntimeIdentifier] = "linux-x64",
414+
[KnownStrings.Properties.ContainerFamily] = "jammy-chiseled",
415+
[KnownStrings.Properties.InvariantGlobalization] = false.ToString(),
416+
}, bonusItems: new()
417+
{
418+
[KnownStrings.Items.FrameworkReference] = KnownFrameworkReferences.WebApp
419+
}, projectName: $"{nameof(FDDAspNetAppWithCulturesAndOptingIntoChiseledGetsExtras)}");
420+
using var _ = d;
421+
var instance = project.CreateProjectInstance(global::Microsoft.Build.Execution.ProjectInstanceSettings.None);
422+
instance.Build(new[] { ComputeContainerBaseImage }, null, null, out var outputs).Should().BeTrue(String.Join(Environment.NewLine, logger.Errors));
423+
var computedBaseImageTag = instance.GetProperty(ContainerBaseImage)?.EvaluatedValue;
424+
computedBaseImageTag.Should().BeEquivalentTo(expectedImage);
425+
}
426+
386427
[InlineData("linux-musl-x64", "mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine")]
387428
[InlineData("linux-x64", "mcr.microsoft.com/dotnet/runtime-deps:7.0")]
388429
[Theory]

0 commit comments

Comments
 (0)