Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Oct 1, 2023
1 parent bb163bc commit aecaa61
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
45 changes: 24 additions & 21 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,43 +283,46 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
}
let imgref = imgref.ok_or_else(|| anyhow::anyhow!("No image source specified"))?;
// Find the currently queued digest, if any before we pull
let queued_digest = status
.staged
.as_ref()
.and_then(|e| e.image.as_ref())
.map(|img| img.image_digest.as_str());
let staged = status.staged.as_ref();
let staged_image = staged.as_ref().and_then(|s| s.image.as_ref());
let mut changed = false;
if opts.check {
let imgref = imgref.clone().into();
let mut imp = new_importer(repo, &imgref).await?;
match imp.prepare().await? {
PrepareResult::AlreadyPresent(_) => {
println!("No changes in: {}", imgref);
return Ok(());
}
PrepareResult::Ready(r) => {
println!("Update available for: {}", imgref);
println!(" Digest: {}", r.manifest_digest);
if let Some(previous) = r.previous_state.as_ref() {
let diff = ostree_container::ManifestDiff::new(&previous.manifest, &r.manifest);
diff.print();
if let Some(version) = r.version() {
println!(" Version: {version}");
}
// Note fallthrough to -- touch-if-changed
println!(" Digest: {}", r.manifest_digest);
changed = true;
}
}
} else {
let fetched = pull(&sysroot.repo(), imgref, opts.quiet).await?;
if let Some(queued_digest) = queued_digest {
if fetched.merge_commit.as_str() == queued_digest {
println!("Already queued: {queued_digest}");
return Ok(());
}
let staged_digest = staged_image.as_ref().map(|s| s.image_digest.as_str());
let fetched_digest = fetched.manifest_digest.as_str();
tracing::debug!("staged: {staged_digest:?}");
tracing::debug!("fetched: {fetched_digest}");
let staged_unchanged = staged_digest
.map(|d| d == fetched_digest)
.unwrap_or_default();
if staged_unchanged {
println!("Staged update present, not changed.");
} else {
let osname = booted_deployment.osname();
crate::deploy::stage(sysroot, &osname, fetched, &host.spec).await?;
changed = true;
}

let osname = booted_deployment.osname();
crate::deploy::stage(sysroot, &osname, fetched, &host.spec).await?;
}
if let Some(path) = opts.touch_if_changed {
std::fs::write(&path, "").with_context(|| format!("Writing {path}"))?;
if changed {
if let Some(path) = opts.touch_if_changed {
std::fs::write(&path, "").with_context(|| format!("Writing {path}"))?;
}
}

Ok(())
Expand Down
12 changes: 10 additions & 2 deletions lib/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async fn deploy(
sysroot: &SysrootLock,
merge_deployment: Option<&Deployment>,
stateroot: &str,
image: Box<LayeredImageState>,
image: &LayeredImageState,
origin: &glib::KeyFile,
) -> Result<()> {
let stateroot = Some(stateroot);
Expand Down Expand Up @@ -115,13 +115,21 @@ pub(crate) async fn stage(
sysroot,
merge_deployment.as_ref(),
stateroot,
image,
&image,
&origin,
)
.await?;
crate::deploy::cleanup(sysroot).await?;
if let Some(imgref) = ostree_imgref.as_ref() {
println!("Queued for next boot: {imgref}");
if let Some(version) = image
.configuration
.as_ref()
.and_then(ostree_container::version_for_config)
{
println!(" Version: {version}");
}
println!(" Digest: {}", image.manifest_digest);
}
ostree_container::deploy::remove_undeployed_images(sysroot).context("Pruning images")?;

Expand Down

0 comments on commit aecaa61

Please sign in to comment.