Skip to content

Commit 714952e

Browse files
authored
ContainerRegistry: Pass through the manifest's mediaType, if set (#23)
### Motivation If the manifest blob's `mediaType` is set, the distribution spec requires that the HTTP `Content-Type` used to upload the manifest should match it. ### Modifications In `putManifest`, use the blob's `mediaType` if it is set; otherwise default to `manifest.v1`. ### Result If a manifest uses a different media type, it will be passed through to the registry. This might happen when copying a base image, which could have been created using the older manifest type. ### Test Plan Automated tests continue to pass. Also tested manually with different registries.
1 parent 5d497a6 commit 714952e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/ContainerRegistry/Manifests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
public extension RegistryClient {
1616
func putManifest(repository: String, reference: String, manifest: ImageManifest) async throws -> String {
17+
// See https://github.com/opencontainers/distribution-spec/blob/main/spec.md#pushing-manifests
1718
precondition(repository.count > 0, "repository must not be an empty string")
1819
precondition(reference.count > 0, "reference must not be an empty string")
1920

2021
let httpResponse = try await executeRequestThrowing(
2122
// All blob uploads have Content-Type: application/octet-stream on the wire, even if mediatype is different
2223
.put(
2324
registryURLForPath("/v2/\(repository)/manifests/\(reference)"),
24-
contentType: "application/vnd.oci.image.manifest.v1+json"
25+
contentType: manifest.mediaType ?? "application/vnd.oci.image.manifest.v1+json"
2526
),
2627
uploading: manifest,
2728
expectingStatus: .created,
@@ -35,6 +36,7 @@ public extension RegistryClient {
3536
}
3637

3738
func getManifest(repository: String, reference: String) async throws -> ImageManifest {
39+
// See https://github.com/opencontainers/distribution-spec/blob/main/spec.md#pulling-manifests
3840
precondition(repository.count > 0, "repository must not be an empty string")
3941
precondition(reference.count > 0, "reference must not be an empty string")
4042

0 commit comments

Comments
 (0)