-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Match sdk-container-builds properties.
- Loading branch information
Showing
7 changed files
with
202 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,99 @@ | ||
class FlavorInfo | ||
{ | ||
public string Flavor { get; init; } = null!; | ||
public string RuntimeImage { get; init; } = null!; | ||
public string BaseImage { get; init; } = null!; | ||
public string SdkImage { get; init; } = null!; | ||
} | ||
|
||
class ImageFlavorDatabase | ||
{ | ||
public static FlavorInfo GetFlavorInfo(string flavor, string runtimeVersion, string sdkVersion) | ||
public static FlavorInfo GetFlavorInfo(string baseFlavor, string? sdkFlavor, string runtimeVersion, string sdkVersion) | ||
{ | ||
string fromImage, buildImage; | ||
if (flavor.StartsWith("ubi")) | ||
return new FlavorInfo() | ||
{ | ||
string runtimeVersionNoDot = runtimeVersion.Replace(".", ""); | ||
string sdkVersionNoDot = sdkVersion.Replace(".", ""); | ||
string baseOs = flavor; | ||
if (baseOs == "ubi") | ||
Flavor = baseFlavor, | ||
BaseImage = ResolveImage(baseFlavor, runtimeVersion, isSdk: false, out string resolvedFlavor), | ||
SdkImage = ResolveImage(sdkFlavor ?? resolvedFlavor, sdkVersion, isSdk: true, out _) | ||
}; | ||
} | ||
|
||
private static bool IsRepositoryName(string flavor) => flavor.Contains("/"); | ||
private static bool IsShortName(string flavor) => !IsRepositoryName(flavor); | ||
|
||
private static string ResolveImage(string flavor, string version, bool isSdk, out string resolvedFlavor) | ||
{ | ||
if (IsRepositoryName(flavor)) | ||
{ | ||
if (flavor.Contains("redhat.com")) | ||
{ | ||
baseOs = "ubi8"; // TODO: switch based on dotnetVersion | ||
// Fall through to short name. | ||
flavor = "ubi"; | ||
} | ||
fromImage = $"registry.access.redhat.com/{baseOs}/dotnet-{runtimeVersionNoDot}-runtime"; | ||
buildImage = $"registry.access.redhat.com/{baseOs}/dotnet-{sdkVersionNoDot}"; | ||
} | ||
else | ||
{ | ||
string imageTag = runtimeVersion; | ||
string sdkImageTag = sdkVersion; | ||
if (!string.IsNullOrEmpty(flavor)) | ||
else | ||
{ | ||
imageTag += $"-{flavor}"; | ||
sdkImageTag += $"-{flavor}"; | ||
int colonPos = flavor.IndexOf(':'); | ||
|
||
const string ChiseledSuffix = "-chiseled"; | ||
if (sdkImageTag.EndsWith(ChiseledSuffix)) | ||
if (colonPos == -1) // example: flavor = mcr.microsoft.com/dotnet/runtime | ||
{ | ||
// There are no chiseled SDK images. | ||
sdkImageTag = sdkImageTag.Substring(0, sdkImageTag.Length - ChiseledSuffix.Length); | ||
resolvedFlavor = ""; | ||
return $"{flavor}:{version}"; | ||
} | ||
else // example: flavor = mcr.microsoft.com/dotnet/runtime:6.0-alpine | ||
{ | ||
string registryName = flavor.Substring(0, colonPos); | ||
string tag = flavor.Substring(colonPos + 1); | ||
|
||
// strip version from the tag. | ||
while (tag.Length > 0 && (char.IsDigit(tag[0]) || tag[0] == '.')) | ||
{ | ||
tag = tag.Substring(1); | ||
} | ||
|
||
resolvedFlavor = tag.StartsWith('-') ? tag.Substring(1) : tag; | ||
|
||
return $"{registryName}:{version}{tag}"; | ||
} | ||
} | ||
bool isPreview = flavor == "jammy-chiseled" && runtimeVersion == "6.0"; | ||
string fromRegistry = isPreview ? "mcr.microsoft.com/dotnet/nightly/aspnet" : "mcr.microsoft.com/dotnet/aspnet"; | ||
fromImage = $"{fromRegistry}:{imageTag}"; | ||
buildImage = $"mcr.microsoft.com/dotnet/sdk:{sdkImageTag}"; | ||
} | ||
|
||
return new FlavorInfo() | ||
// flavor is a short name | ||
resolvedFlavor = flavor; | ||
|
||
if (flavor.StartsWith("ubi")) // Red Hat image. | ||
{ | ||
Flavor = flavor, | ||
RuntimeImage = fromImage, | ||
SdkImage = buildImage | ||
}; | ||
string versionNoDot = version.Replace(".", ""); | ||
|
||
return isSdk ? $"registry.access.redhat.com/{DotNetVersionToRedHatBaseImage(version)}/dotnet-{versionNoDot}" | ||
: $"registry.access.redhat.com/{DotNetVersionToRedHatBaseImage(version)}/dotnet-{versionNoDot}-runtime"; | ||
|
||
static string DotNetVersionToRedHatBaseImage(string version) => version switch | ||
{ | ||
_ => "ubi8" | ||
}; | ||
} | ||
else // Microsoft image. | ||
{ | ||
const string ChiseledSuffix = "-chiseled"; | ||
if (flavor.EndsWith(ChiseledSuffix) && isSdk) // There are no chiseled SDK images. | ||
{ | ||
flavor = flavor.Substring(0, flavor.Length - ChiseledSuffix.Length); | ||
} | ||
|
||
string registryName = isSdk ? "mcr.microsoft.com/dotnet/sdk" : "mcr.microsoft.com/dotnet/aspnet"; | ||
|
||
// jammy-chiseled is preview for .NET 6.0. | ||
if (flavor == "jammy-chiseled" && version == "6.0") | ||
{ | ||
registryName = "mcr.microsoft.com/dotnet/nightly/aspnet"; | ||
} | ||
|
||
string tag = version; | ||
if (flavor.Length > 0) | ||
{ | ||
tag += $"-{flavor}"; | ||
} | ||
|
||
return $"{registryName}:{tag}"; | ||
} | ||
} | ||
} |
Oops, something went wrong.