Skip to content

Commit fde6bdd

Browse files
committed
deploy: Pass around subset of ostree-container image state
Prep for a podman backend. Signed-off-by: Colin Walters <[email protected]>
1 parent 6956054 commit fde6bdd

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

lib/src/cli.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,11 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
315315
crate::deploy::stage(sysroot, &osname, &fetched, &spec).await?;
316316
changed = true;
317317
if let Some(prev) = booted_image.as_ref() {
318-
let diff = ostree_container::ManifestDiff::new(&prev.manifest, &fetched.manifest);
319-
diff.print();
318+
if let Some(fetched_manifest) = fetched.get_manifest(repo)? {
319+
let diff =
320+
ostree_container::ManifestDiff::new(&prev.manifest, &fetched_manifest);
321+
diff.print();
322+
}
320323
}
321324
}
322325
}

lib/src/deploy.rs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use anyhow::{Context, Result};
66

77
use fn_error_context::context;
88
use ostree::{gio, glib};
9-
use ostree_container::store::LayeredImageState;
109
use ostree_container::OstreeImageReference;
1110
use ostree_ext::container as ostree_container;
1211
use ostree_ext::container::store::PrepareResult;
@@ -28,6 +27,13 @@ pub(crate) struct RequiredHostSpec<'a> {
2827
pub(crate) image: &'a ImageReference,
2928
}
3029

30+
/// State of a locally fetched image
31+
pub(crate) struct ImageState {
32+
pub(crate) manifest_digest: String,
33+
pub(crate) version: Option<String>,
34+
pub(crate) ostree_commit: String,
35+
}
36+
3137
impl<'a> RequiredHostSpec<'a> {
3238
/// Given a (borrowed) host specification, "unwrap" its internal
3339
/// options, giving a spec that is required to have a base container image.
@@ -40,6 +46,29 @@ impl<'a> RequiredHostSpec<'a> {
4046
}
4147
}
4248

49+
impl From<ostree_container::store::LayeredImageState> for ImageState {
50+
fn from(value: ostree_container::store::LayeredImageState) -> Self {
51+
let version = value.version().map(|v| v.to_owned());
52+
let ostree_commit = value.get_commit().to_owned();
53+
Self {
54+
manifest_digest: value.manifest_digest,
55+
version,
56+
ostree_commit,
57+
}
58+
}
59+
}
60+
61+
impl ImageState {
62+
/// Fetch the manifest corresponding to this image. May not be available in all backends.
63+
pub(crate) fn get_manifest(
64+
&self,
65+
repo: &ostree::Repo,
66+
) -> Result<Option<ostree_ext::oci_spec::image::ImageManifest>> {
67+
ostree_container::store::query_image_commit(repo, &self.ostree_commit)
68+
.map(|v| Some(v.manifest))
69+
}
70+
}
71+
4372
/// Wrapper for pulling a container image, wiring up status output.
4473
pub(crate) async fn new_importer(
4574
repo: &ostree::Repo,
@@ -57,14 +86,14 @@ pub(crate) async fn pull(
5786
sysroot: &SysrootLock,
5887
imgref: &ImageReference,
5988
quiet: bool,
60-
) -> Result<Box<LayeredImageState>> {
89+
) -> Result<Box<ImageState>> {
6190
let repo = &sysroot.repo();
6291
let imgref = &OstreeImageReference::from(imgref.clone());
6392
let mut imp = new_importer(repo, imgref).await?;
6493
let prep = match imp.prepare().await? {
6594
PrepareResult::AlreadyPresent(c) => {
6695
println!("No changes in {} => {}", imgref, c.manifest_digest);
67-
return Ok(c);
96+
return Ok(Box::new((*c).into()));
6897
}
6998
PrepareResult::Ready(p) => p,
7099
};
@@ -89,7 +118,7 @@ pub(crate) async fn pull(
89118
{
90119
eprintln!("{msg}")
91120
}
92-
Ok(import)
121+
Ok(Box::new((*import).into()))
93122
}
94123

95124
pub(crate) async fn cleanup(sysroot: &SysrootLock) -> Result<()> {
@@ -143,16 +172,15 @@ async fn deploy(
143172
sysroot: &SysrootLock,
144173
merge_deployment: Option<&Deployment>,
145174
stateroot: &str,
146-
image: &LayeredImageState,
175+
image: &ImageState,
147176
origin: &glib::KeyFile,
148177
) -> Result<()> {
149178
let stateroot = Some(stateroot);
150179
// Copy to move into thread
151-
let base_commit = image.get_commit().to_owned();
152180
let cancellable = gio::Cancellable::NONE;
153181
let _new_deployment = sysroot.stage_tree_with_options(
154182
stateroot,
155-
&base_commit,
183+
image.ostree_commit.as_str(),
156184
Some(origin),
157185
merge_deployment,
158186
&Default::default(),
@@ -166,7 +194,7 @@ async fn deploy(
166194
pub(crate) async fn stage(
167195
sysroot: &SysrootLock,
168196
stateroot: &str,
169-
image: &LayeredImageState,
197+
image: &ImageState,
170198
spec: &RequiredHostSpec<'_>,
171199
) -> Result<()> {
172200
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
@@ -187,11 +215,7 @@ pub(crate) async fn stage(
187215
.await?;
188216
crate::deploy::cleanup(sysroot).await?;
189217
println!("Queued for next boot: {imgref}");
190-
if let Some(version) = image
191-
.configuration
192-
.as_ref()
193-
.and_then(ostree_container::version_for_config)
194-
{
218+
if let Some(version) = image.version.as_deref() {
195219
println!(" Version: {version}");
196220
}
197221
println!(" Digest: {}", image.manifest_digest);

0 commit comments

Comments
 (0)