Skip to content

Commit

Permalink
Merge pull request #275 from cgwalters/deploy-write-ref
Browse files Browse the repository at this point in the history
container: Add `--write-commitid-to` for `image deploy`
  • Loading branch information
cgwalters authored Apr 4, 2022
2 parents 21f8920 + f91a180 commit 85f7161
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 19 additions & 3 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
//! also exported as a library too, so that projects
//! such as `rpm-ostree` can directly reuse it.

use anyhow::Result;
use anyhow::{Context, Result};
use camino::Utf8PathBuf;
use futures_util::FutureExt;
use ostree::{cap_std, gio, glib};
use std::borrow::Borrow;
Expand Down Expand Up @@ -247,6 +248,10 @@ enum ContainerImageOpts {
#[structopt(long)]
/// Add a kernel argument
karg: Option<Vec<String>>,

/// Write the deployed checksum to this file
#[structopt(long)]
write_commitid_to: Option<Utf8PathBuf>,
},
}

Expand Down Expand Up @@ -632,6 +637,7 @@ where
target_imgref,
karg,
proxyopts,
write_commitid_to,
} => {
let sysroot = &ostree::Sysroot::new(Some(&gio::File::for_path(&sysroot)));
sysroot.load(gio::NONE_CANCELLABLE)?;
Expand All @@ -645,8 +651,18 @@ where
target_imgref: target_imgref.as_ref(),
proxy_cfg: Some(proxyopts.into()),
};
crate::container::deploy::deploy(sysroot, &stateroot, &imgref, Some(options))
.await
let state = crate::container::deploy::deploy(
sysroot,
&stateroot,
&imgref,
Some(options),
)
.await?;
if let Some(p) = write_commitid_to {
std::fs::write(&p, state.merge_commit.as_bytes())
.with_context(|| format!("Failed to write commitid to {}", p))?;
}
Ok(())
}
},
},
Expand Down
6 changes: 4 additions & 2 deletions lib/src/container/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Perform initial setup for a container image based system root

use super::store::LayeredImageState;
use super::OstreeImageReference;
use crate::container::store::PrepareResult;
use anyhow::Result;
Expand Down Expand Up @@ -37,7 +38,7 @@ pub async fn deploy(
stateroot: &str,
imgref: &OstreeImageReference,
options: Option<DeployOpts<'_>>,
) -> Result<()> {
) -> Result<Box<LayeredImageState>> {
let cancellable = ostree::gio::NONE_CANCELLABLE;
let options = options.unwrap_or_default();
let repo = &sysroot.repo().unwrap();
Expand Down Expand Up @@ -66,5 +67,6 @@ pub async fn deploy(
let flags = ostree::SysrootSimpleWriteDeploymentFlags::NONE;
sysroot.simple_write_deployment(Some(stateroot), deployment, None, flags, cancellable)?;
sysroot.cleanup(cancellable)?;
Ok(())

Ok(state)
}

0 comments on commit 85f7161

Please sign in to comment.