From ad7af3fab57aa21eeb81f8478863404121d55842 Mon Sep 17 00:00:00 2001 From: John Eckersberg Date: Tue, 24 Sep 2024 13:48:53 -0400 Subject: [PATCH] Bump ostree-ext to 0.15.1 and use proper digests where possible Signed-off-by: John Eckersberg --- Cargo.lock | 4 ++-- lib/src/cli.rs | 7 ++++--- lib/src/deploy.rs | 9 ++++++--- lib/src/spec.rs | 8 ++++++++ lib/src/store/ostree_container.rs | 6 +++--- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 05b6882c..de70cd46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1363,9 +1363,9 @@ dependencies = [ [[package]] name = "ostree-ext" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8778f3ba7b521c1eb9228dd3b92c5461a5594a003e62fef15367199e4cd46482" +checksum = "bbcc45e75367e27db8892062a3b367f058b86135b02158a9fc2d1038506758f9" dependencies = [ "anyhow", "camino", diff --git a/lib/src/cli.rs b/lib/src/cli.rs index a2c4986b..8a8203a3 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -609,16 +609,17 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> { } } else { let fetched = crate::deploy::pull(repo, imgref, None, opts.quiet).await?; - let staged_digest = staged_image.as_ref().map(|s| s.image_digest.as_str()); - let fetched_digest = fetched.manifest_digest.as_str(); + let staged_digest = staged_image.map(|s| s.digest().expect("valid digest in status")); + let fetched_digest = &fetched.manifest_digest; tracing::debug!("staged: {staged_digest:?}"); tracing::debug!("fetched: {fetched_digest}"); let staged_unchanged = staged_digest + .as_ref() .map(|d| d == fetched_digest) .unwrap_or_default(); let booted_unchanged = booted_image .as_ref() - .map(|img| img.manifest_digest.as_str() == fetched_digest) + .map(|img| &img.manifest_digest == fetched_digest) .unwrap_or_default(); if staged_unchanged { println!("Staged update present, not changed."); diff --git a/lib/src/deploy.rs b/lib/src/deploy.rs index 6bcfda9c..17f1208b 100644 --- a/lib/src/deploy.rs +++ b/lib/src/deploy.rs @@ -15,7 +15,7 @@ use ostree::{gio, glib}; use ostree_container::OstreeImageReference; use ostree_ext::container as ostree_container; use ostree_ext::container::store::{ImportProgress, PrepareResult}; -use ostree_ext::oci_spec::image::Descriptor; +use ostree_ext::oci_spec::image::{Descriptor, Digest}; use ostree_ext::ostree::Deployment; use ostree_ext::ostree::{self, Sysroot}; use ostree_ext::sysroot::SysrootLock; @@ -38,7 +38,7 @@ pub(crate) struct RequiredHostSpec<'a> { /// State of a locally fetched image pub(crate) struct ImageState { - pub(crate) manifest_digest: String, + pub(crate) manifest_digest: Digest, pub(crate) version: Option, pub(crate) ostree_commit: String, } @@ -481,7 +481,10 @@ pub(crate) async fn rollback(sysroot: &Storage) -> Result<()> { &msg, [ ("MESSAGE_ID", ROLLBACK_JOURNAL_ID), - ("BOOTC_MANIFEST_DIGEST", &rollback_image.manifest_digest), + ( + "BOOTC_MANIFEST_DIGEST", + &rollback_image.manifest_digest.to_string(), + ), ] .into_iter(), )?; diff --git a/lib/src/spec.rs b/lib/src/spec.rs index 5a5dd0b1..ab2ca907 100644 --- a/lib/src/spec.rs +++ b/lib/src/spec.rs @@ -3,6 +3,7 @@ use std::fmt::Display; use ostree_ext::container::OstreeImageReference; +use ostree_ext::oci_spec::image::Digest; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -219,6 +220,13 @@ impl Display for ImageReference { } } +impl ImageStatus { + pub(crate) fn digest(&self) -> anyhow::Result { + use std::str::FromStr; + Ok(Digest::from_str(&self.image_digest)?) + } +} + #[cfg(test)] mod tests { use std::str::FromStr; diff --git a/lib/src/store/ostree_container.rs b/lib/src/store/ostree_container.rs index ca18000f..bd62fb00 100644 --- a/lib/src/store/ostree_container.rs +++ b/lib/src/store/ostree_container.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Result}; use ostree_ext::container as ostree_container; use ostree_ext::oci_spec; -use ostree_ext::oci_spec::image::ImageConfiguration; +use ostree_ext::oci_spec::image::{Digest, ImageConfiguration}; use ostree_ext::ostree; use ostree_ext::sysroot::SysrootLock; @@ -42,7 +42,7 @@ impl super::ContainerImageStoreImpl for OstreeContainerStore { /// Convert between a subset of ostree-ext metadata and the exposed spec API. fn create_imagestatus( image: ImageReference, - manifest_digest: &str, + manifest_digest: &Digest, config: &ImageConfiguration, ) -> ImageStatus { let labels = labels_of_config(config); @@ -58,7 +58,7 @@ fn create_imagestatus( image, version, timestamp, - image_digest: manifest_digest.to_owned(), + image_digest: manifest_digest.to_string(), } }