Skip to content

Commit 021c629

Browse files
committed
remove full dependency tracking and just use exact-matching
1 parent ca47a5c commit 021c629

File tree

2 files changed

+28
-43
lines changed

2 files changed

+28
-43
lines changed

Microsoft.NET.Build.Containers/Registry.cs

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@ public record Registry(Uri BaseUri)
4949
var unknownMediaType => throw new NotImplementedException($"The manifest for {name}:{reference} from registry {BaseUri} was an unknown type: {unknownMediaType}. Please raise an issue at https://github.com/dotnet/sdk-container-builds/issues with this message.")
5050
};
5151

52-
async Task<HttpResponseMessage> GetManifest(string reference) {
53-
var client = GetClient();
54-
var response = await client.GetAsync(new Uri(BaseUri, $"/v2/{name}/manifests/{reference}"));
55-
response.EnsureSuccessStatusCode();
56-
return response;
57-
}
58-
59-
async Task<HttpResponseMessage> GetBlob(string digest) {
60-
var client = GetClient();
61-
var response = await client.GetAsync(new Uri(BaseUri, $"/v2/{name}/blobs/{digest}"));
62-
response.EnsureSuccessStatusCode();
63-
return response;
64-
}
65-
6652
async Task<Image?> TryReadSingleImage(ManifestV2 manifest) {
6753
var config = manifest.config;
6854
string configSha = config.digest;
@@ -76,50 +62,55 @@ async Task<HttpResponseMessage> GetBlob(string digest) {
7662
}
7763

7864
async Task<Image?> TryPickBestImageFromManifestList(ManifestListV2 manifestList, string runtimeIdentifier) {
79-
var runtimeGraph = GetRuntimeGraphForDotNet();
80-
var compatibleRuntimesForUserRid = runtimeGraph.ExpandRuntime(runtimeIdentifier);
81-
var (ridDict, graphForManifestList) = ConstructRuntimeGraphForManifestList(manifestList, runtimeGraph);
82-
var bestManifestRid = PickBestRidFromCompatibleUserRids(graphForManifestList, compatibleRuntimesForUserRid);
65+
var (ridDict, graphForManifestList) = ConstructRuntimeGraphForManifestList(manifestList);
66+
var bestManifestRid = CheckIfRidExistsInGraph(graphForManifestList, runtimeIdentifier);
8367
if (bestManifestRid is null) {
84-
throw new ArgumentException($"The runtimeIdentifier '{runtimeIdentifier}' is not supported. The supported RuntimeIdentifiers for the base image {name}:{reference} are {String.Join(",", compatibleRuntimesForUserRid)}");
68+
throw new ArgumentException($"The runtimeIdentifier '{runtimeIdentifier}' is not supported. The supported RuntimeIdentifiers for the base image {name}:{reference} are {String.Join(",", graphForManifestList.Runtimes.Keys)}");
8569
}
8670
var matchingManifest = ridDict[bestManifestRid];
8771
var manifestResponse = await GetManifest(matchingManifest.digest);
8872
return await TryReadSingleImage(await manifestResponse.Content.ReadFromJsonAsync<ManifestV2>());
8973
}
74+
75+
async Task<HttpResponseMessage> GetManifest(string reference)
76+
{
77+
var client = GetClient();
78+
var response = await client.GetAsync(new Uri(BaseUri, $"/v2/{name}/manifests/{reference}"));
79+
response.EnsureSuccessStatusCode();
80+
return response;
81+
}
82+
83+
async Task<HttpResponseMessage> GetBlob(string digest)
84+
{
85+
var client = GetClient();
86+
var response = await client.GetAsync(new Uri(BaseUri, $"/v2/{name}/blobs/{digest}"));
87+
response.EnsureSuccessStatusCode();
88+
return response;
89+
}
9090
}
9191

92-
private string? PickBestRidFromCompatibleUserRids(RuntimeGraph graphForManifestList, IEnumerable<string> compatibleRuntimesForUserRid)
92+
private string? CheckIfRidExistsInGraph(RuntimeGraph graphForManifestList, string userRid)
9393
{
94-
return compatibleRuntimesForUserRid.First(rid => graphForManifestList.Runtimes.ContainsKey(rid));
94+
graphForManifestList.Runtimes.TryGetValue(userRid, out var runtimeInfo);
95+
return runtimeInfo?.RuntimeIdentifier;
9596
}
9697

97-
private (IReadOnlyDictionary<string, PlatformSpecificManifest>, RuntimeGraph) ConstructRuntimeGraphForManifestList(ManifestListV2 manifestList, RuntimeGraph dotnetRuntimeGraph)
98+
private (IReadOnlyDictionary<string, PlatformSpecificManifest>, RuntimeGraph) ConstructRuntimeGraphForManifestList(ManifestListV2 manifestList)
9899
{
99100
var ridDict = new Dictionary<string, PlatformSpecificManifest>();
100101
var runtimeDescriptionSet = new HashSet<RuntimeDescription>();
101102
foreach (var manifest in manifestList.manifests) {
102103
if (CreateRidForPlatform(manifest.platform) is { } rid)
103104
{
104-
if (ridDict.TryAdd(rid, manifest))
105-
{
106-
AddRidAndDescendentsToSet(runtimeDescriptionSet, rid, dotnetRuntimeGraph);
107-
}
105+
ridDict.TryAdd(rid, manifest);
106+
runtimeDescriptionSet.Add(new RuntimeDescription(rid));
108107
}
109108
}
110109

111-
// todo: inheritance relationships for these RIDs?
112110
var graph = new RuntimeGraph(runtimeDescriptionSet);
113111
return (ridDict, graph);
114112
}
115113

116-
private void AddRidAndDescendentsToSet(HashSet<RuntimeDescription> runtimeDescriptionSet, string rid, RuntimeGraph dotnetRuntimeGraph)
117-
{
118-
var R = dotnetRuntimeGraph.Runtimes[rid];
119-
runtimeDescriptionSet.Add(R);
120-
foreach (var r in R.InheritedRuntimes) AddRidAndDescendentsToSet(runtimeDescriptionSet, r, dotnetRuntimeGraph);
121-
}
122-
123114
private string? CreateRidForPlatform(PlatformInformation platform)
124115
{
125116
var osPart = platform.os switch
@@ -129,6 +120,7 @@ private void AddRidAndDescendentsToSet(HashSet<RuntimeDescription> runtimeDescri
129120
_ => null
130121
};
131122
// TODO: this part needs a lot of work, the RID graph isn't super precise here and version numbers (especially on windows) are _whack_
123+
// TODO: we _may_ need OS-specific version parsing. Need to do more research on what the field looks like across more manifest lists.
132124
var versionPart = platform.version?.Split('.') switch
133125
{
134126
[var major, .. ] => major,
@@ -139,20 +131,14 @@ private void AddRidAndDescendentsToSet(HashSet<RuntimeDescription> runtimeDescri
139131
"amd64" => "x64",
140132
"x386" => "x86",
141133
"arm" => $"arm{(platform.variant != "v7" ? platform.variant : "")}",
142-
"arm64" => "arm64"
134+
"arm64" => "arm64",
135+
_ => null
143136
};
144137

145-
146138
if (osPart is null || platformPart is null) return null;
147139
return $"{osPart}{versionPart ?? ""}-{platformPart}";
148140
}
149141

150-
private RuntimeGraph GetRuntimeGraphForDotNet()
151-
{
152-
var runtimePath = Path.Combine("C:", "Program Files","dotnet", "sdk", "7.0.100", "RuntimeIdentifierGraph.json"); // how to get this at runtime?
153-
return JsonRuntimeFormat.ReadRuntimeGraph(runtimePath);
154-
}
155-
156142
/// <summary>
157143
/// Ensure a blob associated with <paramref name="name"/> from the registry is available locally.
158144
/// </summary>

Test.Microsoft.NET.Build.Containers.Filesystem/EndToEnd.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ public async Task EndToEnd_NoAPI()
281281
[DataRow("linux-arm64", false, "/app")] // packaging framework-dependent because emulating arm64 on x64 Docker host doesn't work
282282
[DataRow("win-x64", true, "C:\\app")]
283283
[DataRow("linux-x64", true, "/app")]
284-
[DataRow("debian.11-x64", true, "/app")] // user-reported RID. proves dependency relationships
285284
[TestMethod]
286285
public async Task CanPackageForAllSupportedContainerRIDs(string rid, bool isRIDSpecific, string workingDir) {
287286
if (rid == "win-x64") {

0 commit comments

Comments
 (0)