@@ -176,19 +176,18 @@ public async Task Push(Image x, string name, string? tag, string baseName, Actio
176
176
tag ??= "latest" ;
177
177
178
178
using HttpClient client = GetClient ( ) ;
179
-
180
- foreach ( var descriptor in x . LayerDescriptors )
181
- {
179
+ var reg = this ;
180
+ await Task . WhenAll ( x . LayerDescriptors . Select ( async descriptor => {
182
181
string digest = descriptor . Digest ;
183
182
logProgressMessage ( $ "Uploading layer { digest } to registry") ;
184
- if ( await BlobAlreadyUploaded ( name , digest , client ) )
183
+ if ( await reg . BlobAlreadyUploaded ( name , digest , client ) )
185
184
{
186
185
logProgressMessage ( $ "Layer { digest } already existed") ;
187
- continue ;
186
+ return ;
188
187
}
189
188
190
189
// Blob wasn't there; can we tell the server to get it from the base image?
191
- HttpResponseMessage pushResponse = await client . PostAsync ( new Uri ( BaseUri , $ "/v2/{ name } /blobs/uploads/?mount={ digest } &from={ baseName } ") , content : null ) ;
190
+ HttpResponseMessage pushResponse = await client . PostAsync ( new Uri ( reg . BaseUri , $ "/v2/{ name } /blobs/uploads/?mount={ digest } &from={ baseName } ") , content : null ) ;
192
191
193
192
if ( pushResponse . StatusCode != HttpStatusCode . Created )
194
193
{
@@ -202,10 +201,10 @@ public async Task Push(Image x, string name, string? tag, string baseName, Actio
202
201
// Ensure the blob is available locally
203
202
await x . originatingRegistry . Value . DownloadBlob ( x . OriginatingName , descriptor ) ;
204
203
// Then push it to the destination registry
205
- await Push ( Layer . FromDescriptor ( descriptor ) , name , logProgressMessage ) ;
204
+ await reg . Push ( Layer . FromDescriptor ( descriptor ) , name , logProgressMessage ) ;
206
205
logProgressMessage ( $ "Finished uploading layer { digest } to registry") ;
207
206
}
208
- }
207
+ } ) ) ;
209
208
210
209
using ( MemoryStream stringStream = new MemoryStream ( Encoding . UTF8 . GetBytes ( x . config . ToJsonString ( ) ) ) )
211
210
{
@@ -220,14 +219,12 @@ public async Task Push(Image x, string name, string? tag, string baseName, Actio
220
219
HttpContent manifestUploadContent = new StringContent ( x . manifest . ToJsonString ( ) ) ;
221
220
manifestUploadContent . Headers . ContentType = new MediaTypeHeaderValue ( DockerManifestV2 ) ;
222
221
var putResponse = await client . PutAsync ( new Uri ( BaseUri , $ "/v2/{ name } /manifests/{ manifestDigest } ") , manifestUploadContent ) ;
223
- string putresponsestr = await putResponse . Content . ReadAsStringAsync ( ) ;
224
222
225
223
if ( ! putResponse . IsSuccessStatusCode )
226
224
{
227
225
string jsonResponse = await putResponse . Content . ReadAsStringAsync ( ) ;
228
226
throw new ContainerHttpException ( "Registry push failed." , putResponse . RequestMessage ? . RequestUri ? . ToString ( ) , jsonResponse ) ;
229
227
}
230
-
231
228
logProgressMessage ( $ "Uploaded manifest to registry") ;
232
229
233
230
logProgressMessage ( $ "Uploading tag { tag } to registry") ;
0 commit comments