Skip to content

Commit

Permalink
cli: Add a --check flag for update.
Browse files Browse the repository at this point in the history
This simply pull the manifest of the image to see if any update and
available. It could be named `--dry-run` but I wanted to be consistent
with `rpm-ostree`
Fixes containers#3

Signed-off-by: jbtrystram <jbtrystram@redhat.com>
  • Loading branch information
jbtrystram committed Jul 5, 2023
1 parent 730c07e commit a022d80
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Required dependencies

In order to build `bootc` you will need the following dependencies.

Fedora:
```
sudo dnf install ostree-libs ostree-devel
```

# Pre flight checks

Makes sure you commented your code additions, then run
```
cargo fmt
cargo clippy
```
Make sure to apply any relevant suggestions.

42 changes: 34 additions & 8 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ pub(crate) struct UpgradeOpts {

#[clap(long)]
pub(crate) touch_if_changed: Option<Utf8PathBuf>,

/// Check if an update is available without applying it
#[clap(long)]
pub(crate) check: bool,
}

/// Perform an upgrade operation
/// Perform an switch operation
#[derive(Debug, Parser)]
pub(crate) struct SwitchOpts {
/// Don't display progress
Expand All @@ -57,7 +61,7 @@ pub(crate) struct SwitchOpts {
pub(crate) target: String,
}

/// Perform an upgrade operation
/// Perform a status operation
#[derive(Debug, Parser)]
pub(crate) struct StatusOpts {
/// Output in JSON format.
Expand Down Expand Up @@ -281,14 +285,36 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
let commit = booted_deployment.csum();
let state = ostree_container::store::query_image_commit(repo, &commit)?;
let digest = state.manifest_digest.as_str();
let fetched = pull(repo, &imgref, opts.quiet).await?;

if fetched.merge_commit.as_str() == commit.as_str() {
println!("Already queued: {digest}");
return Ok(());
}
if opts.check {
// pull the image manifest without the layers
let config = Default::default();
let mut imp = ostree_container::store::ImageImporter::new(repo, &imgref, config).await?;
match imp.prepare().await? {
PrepareResult::AlreadyPresent(c) => {
println!(
"No changes available for {}. Latest digest: {}",
imgref, c.manifest_digest
);
return Ok(());
}
PrepareResult::Ready(p) => {
println!(
"New manifest available for {}. Digest {}",
imgref, p.manifest_digest
);
}
}
} else {
let fetched = pull(repo, &imgref, opts.quiet).await?;

if fetched.merge_commit.as_str() == commit.as_str() {
println!("Already queued: {digest}");
return Ok(());
}

stage(sysroot, &osname, &imgref, fetched, &origin).await?;
stage(sysroot, &osname, &imgref, fetched, &origin).await?;
}

if let Some(path) = opts.touch_if_changed {
std::fs::write(&path, "").with_context(|| format!("Writing {path}"))?;
Expand Down

0 comments on commit a022d80

Please sign in to comment.