@@ -49,20 +49,6 @@ public record Registry(Uri BaseUri)
49
49
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.")
50
50
} ;
51
51
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
-
66
52
async Task < Image ? > TryReadSingleImage ( ManifestV2 manifest ) {
67
53
var config = manifest . config ;
68
54
string configSha = config . digest ;
@@ -76,50 +62,55 @@ async Task<HttpResponseMessage> GetBlob(string digest) {
76
62
}
77
63
78
64
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 ) ;
83
67
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 ) } ") ;
85
69
}
86
70
var matchingManifest = ridDict [ bestManifestRid ] ;
87
71
var manifestResponse = await GetManifest ( matchingManifest . digest ) ;
88
72
return await TryReadSingleImage ( await manifestResponse . Content . ReadFromJsonAsync < ManifestV2 > ( ) ) ;
89
73
}
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
+ }
90
90
}
91
91
92
- private string ? PickBestRidFromCompatibleUserRids ( RuntimeGraph graphForManifestList , IEnumerable < string > compatibleRuntimesForUserRid )
92
+ private string ? CheckIfRidExistsInGraph ( RuntimeGraph graphForManifestList , string userRid )
93
93
{
94
- return compatibleRuntimesForUserRid . First ( rid => graphForManifestList . Runtimes . ContainsKey ( rid ) ) ;
94
+ graphForManifestList . Runtimes . TryGetValue ( userRid , out var runtimeInfo ) ;
95
+ return runtimeInfo ? . RuntimeIdentifier ;
95
96
}
96
97
97
- private ( IReadOnlyDictionary < string , PlatformSpecificManifest > , RuntimeGraph ) ConstructRuntimeGraphForManifestList ( ManifestListV2 manifestList , RuntimeGraph dotnetRuntimeGraph )
98
+ private ( IReadOnlyDictionary < string , PlatformSpecificManifest > , RuntimeGraph ) ConstructRuntimeGraphForManifestList ( ManifestListV2 manifestList )
98
99
{
99
100
var ridDict = new Dictionary < string , PlatformSpecificManifest > ( ) ;
100
101
var runtimeDescriptionSet = new HashSet < RuntimeDescription > ( ) ;
101
102
foreach ( var manifest in manifestList . manifests ) {
102
103
if ( CreateRidForPlatform ( manifest . platform ) is { } rid )
103
104
{
104
- if ( ridDict . TryAdd ( rid , manifest ) )
105
- {
106
- AddRidAndDescendentsToSet ( runtimeDescriptionSet , rid , dotnetRuntimeGraph ) ;
107
- }
105
+ ridDict . TryAdd ( rid , manifest ) ;
106
+ runtimeDescriptionSet . Add ( new RuntimeDescription ( rid ) ) ;
108
107
}
109
108
}
110
109
111
- // todo: inheritance relationships for these RIDs?
112
110
var graph = new RuntimeGraph ( runtimeDescriptionSet ) ;
113
111
return ( ridDict , graph ) ;
114
112
}
115
113
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
-
123
114
private string ? CreateRidForPlatform ( PlatformInformation platform )
124
115
{
125
116
var osPart = platform . os switch
@@ -129,6 +120,7 @@ private void AddRidAndDescendentsToSet(HashSet<RuntimeDescription> runtimeDescri
129
120
_ => null
130
121
} ;
131
122
// 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.
132
124
var versionPart = platform . version ? . Split ( '.' ) switch
133
125
{
134
126
[ var major , .. ] => major ,
@@ -139,20 +131,14 @@ private void AddRidAndDescendentsToSet(HashSet<RuntimeDescription> runtimeDescri
139
131
"amd64" => "x64" ,
140
132
"x386" => "x86" ,
141
133
"arm" => $ "arm{ ( platform . variant != "v7" ? platform . variant : "" ) } ",
142
- "arm64" => "arm64"
134
+ "arm64" => "arm64" ,
135
+ _ => null
143
136
} ;
144
137
145
-
146
138
if ( osPart is null || platformPart is null ) return null ;
147
139
return $ "{ osPart } { versionPart ?? "" } -{ platformPart } ";
148
140
}
149
141
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
-
156
142
/// <summary>
157
143
/// Ensure a blob associated with <paramref name="name"/> from the registry is available locally.
158
144
/// </summary>
0 commit comments