Skip to content

Commit b3975f6

Browse files
authored
log config, manifest, and tag upload digests (#213)
1 parent d21b16b commit b3975f6

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Microsoft.NET.Build.Containers/Registry.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,15 @@ private readonly async Task UploadBlob(string name, string digest, Stream conten
117117
Debug.Assert(pushResponse.Headers.Location is not null);
118118

119119
UriBuilder x;
120-
if (pushResponse.Headers.Location.IsAbsoluteUri)
120+
if (pushResponse.Headers.Location is {IsAbsoluteUri: true })
121121
{
122122
x = new UriBuilder(pushResponse.Headers.Location);
123123
}
124124
else
125125
{
126-
x = new UriBuilder(BaseUri + pushResponse.Headers.Location.OriginalString);
126+
// if we don't trim the BaseUri and relative Uri of slashes, you can get invalid urls.
127+
// Uri constructor does this on our behalf.
128+
x = new UriBuilder(new Uri(BaseUri, pushResponse.Headers.Location.OriginalString));
127129
}
128130

129131
x.Query += $"&digest={Uri.EscapeDataString(digest)}";
@@ -199,23 +201,25 @@ public async Task Push(Image x, string name, string? tag, string baseName, Actio
199201

200202
// Ensure the blob is available locally
201203
await x.originatingRegistry.Value.DownloadBlob(x.OriginatingName, descriptor);
202-
logProgressMessage($"Finished uploading layer {digest} to registry");
203204
// Then push it to the destination registry
204205
await Push(Layer.FromDescriptor(descriptor), name, logProgressMessage);
206+
logProgressMessage($"Finished uploading layer {digest} to registry");
205207
}
206208
}
207209

208-
logProgressMessage($"Uploading config to registry");
209210
using (MemoryStream stringStream = new MemoryStream(Encoding.UTF8.GetBytes(x.config.ToJsonString())))
210211
{
211-
await UploadBlob(name, x.GetDigest(x.config), stringStream);
212+
var configDigest = x.GetDigest(x.config);
213+
logProgressMessage($"Uploading config to registry at blob {configDigest}");
214+
await UploadBlob(name, configDigest, stringStream);
212215
logProgressMessage($"Uploaded config to registry");
213216
}
214217

215-
logProgressMessage($"Uploading manifest to registry");
218+
var manifestDigest = x.GetDigest(x.manifest);
219+
logProgressMessage($"Uploading manifest to registry at blob {manifestDigest}");
216220
HttpContent manifestUploadContent = new StringContent(x.manifest.ToJsonString());
217221
manifestUploadContent.Headers.ContentType = new MediaTypeHeaderValue(DockerManifestV2);
218-
var putResponse = await client.PutAsync(new Uri(BaseUri, $"/v2/{name}/manifests/{x.GetDigest(x.manifest)}"), manifestUploadContent);
222+
var putResponse = await client.PutAsync(new Uri(BaseUri, $"/v2/{name}/manifests/{manifestDigest}"), manifestUploadContent);
219223
string putresponsestr = await putResponse.Content.ReadAsStringAsync();
220224

221225
if (!putResponse.IsSuccessStatusCode)
@@ -226,7 +230,7 @@ public async Task Push(Image x, string name, string? tag, string baseName, Actio
226230

227231
logProgressMessage($"Uploaded manifest to registry");
228232

229-
logProgressMessage($"Uploading tag to registry");
233+
logProgressMessage($"Uploading tag {tag} to registry");
230234
var putResponse2 = await client.PutAsync(new Uri(BaseUri, $"/v2/{name}/manifests/{tag}"), manifestUploadContent);
231235

232236
if (!putResponse2.IsSuccessStatusCode)

0 commit comments

Comments
 (0)