Skip to content

Commit

Permalink
Fix oci-spec update outputs pretty manifests
Browse files Browse the repository at this point in the history
With oci-spec 0.6.6 [#166](youki-dev/oci-spec-rs#166)
the `to_string()` method started to return the
blanket impl of `ToString` due to the `Display` Trait being added.

I'm not entirely sure why I got the display trait instead of the
`to_string()` implemented on `ImageManifest`, in the rust playground I'm
unable to reproduce it. Instead I now call serde_json directly so I
don't have to rely on whatever oci-spec implements as the serialization.
  • Loading branch information
AllexVeldman committed Sep 13, 2024
1 parent 92508d5 commit 4716329
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ codegen-units = 1
[dependencies]
bytes = "1.7.1"
exitcode = "1.1.2"
oci-spec = { version = "0.6.4", default-features = false, features = ["image", "distribution"] }
oci-spec = { version = "0.6.8", default-features = false, features = ["image", "distribution"] }
url = "2.3.1"
regex = "1.10.6"
tracing = "0.1.40"
Expand Down
2 changes: 2 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,15 @@ mod tests {
server
.mock("PUT", "/v2/mockserver/foobar/manifests/sha256:7ffd96d9eab411893eeacfa906e30956290a07b0141d7c1dd54c9fd5c7c48cf5")
.match_header("Content-Type", "application/vnd.oci.image.manifest.v1+json")
.match_body(r#"{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","artifactType":"application/pyoci.package.v1","config":{"mediaType":"application/vnd.oci.empty.v1+json","digest":"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a","size":2},"layers":[{"mediaType":"application/pyoci.package.v1","digest":"sha256:b7513fb69106a855b69153582dec476677b3c79f4a13cfee6fb7a356cfa754c0","size":22}]}"#)
.with_status(201) // CREATED
.create_async()
.await,
// PUT request to create Index
server
.mock("PUT", "/v2/mockserver/foobar/manifests/1.0.0")
.match_header("Content-Type", "application/vnd.oci.image.index.v1+json")
.match_body(r#"{"schemaVersion":2,"mediaType":"application/vnd.oci.image.index.v1+json","artifactType":"application/pyoci.package.v1","manifests":[{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:7ffd96d9eab411893eeacfa906e30956290a07b0141d7c1dd54c9fd5c7c48cf5","size":422,"platform":{"architecture":".tar.gz","os":"any"}}]}"#)
.with_status(201) // CREATED
.create_async()
.await,
Expand Down
4 changes: 2 additions & 2 deletions src/pyoci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,11 @@ impl PyOci {
Manifest::Index(index) => {
let version = version.context("`version` required for pushing an ImageIndex")?;
let url = build_url!(&self, "v2/{}/manifests/{}", name, version);
let data = index.to_string();
let data = serde_json::to_string(&index)?;
(url, data, "application/vnd.oci.image.index.v1+json")
}
Manifest::Manifest(manifest) => {
let data = manifest.to_string();
let data = serde_json::to_string(&manifest)?;
let sha = <Sha256 as Digest>::digest(&data);
let digest = format!("sha256:{}", hex_encode(&sha));
let url = build_url!(&self, "/v2/{}/manifests/{}", name, &digest);
Expand Down

0 comments on commit 4716329

Please sign in to comment.