Skip to content

Commit

Permalink
Merge pull request ostreedev#362 from cgwalters/deploy-unlinked
Browse files Browse the repository at this point in the history
deploy: Add a `--no-imgref` option
  • Loading branch information
cgwalters authored Sep 12, 2022
2 parents 53f05b1 + bec7c0a commit f99c7fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ where
kargs: kargs.as_deref(),
target_imgref: target_imgref.as_ref(),
proxy_cfg: Some(proxyopts.into()),
..Default::default()
};
let state = crate::container::deploy::deploy(
sysroot,
Expand Down
9 changes: 9 additions & 0 deletions lib/src/container/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ pub struct DeployOpts<'a> {

/// Configuration for fetching containers.
pub proxy_cfg: Option<super::store::ImageProxyConfig>,

/// If true, then no image reference will be written; but there will be refs
/// for the fetched layers. This ensures that if the machine is later updated
/// to a different container image, the fetch process will reuse shared layers, but
/// it will not be necessary to remove the previous image.
pub no_imgref: bool,
}

/// Write a container image to an OSTree deployment.
Expand All @@ -48,6 +54,9 @@ pub async fn deploy(
if let Some(target) = options.target_imgref {
imp.set_target(target);
}
if options.no_imgref {
imp.set_no_imgref();
}
let state = match imp.prepare().await? {
PrepareResult::AlreadyPresent(r) => r,
PrepareResult::Ready(prep) => imp.import(prep).await?,
Expand Down
13 changes: 12 additions & 1 deletion lib/src/container/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub struct ImageImporter {
pub(crate) proxy: ImageProxy,
imgref: OstreeImageReference,
target_imgref: Option<OstreeImageReference>,
no_imgref: bool, // If true, do not write final image ref
pub(crate) proxy_img: OpenedImage,

layer_progress: Option<Sender<ImportProgress>>,
Expand Down Expand Up @@ -405,6 +406,7 @@ impl ImageImporter {
proxy,
proxy_img,
target_imgref: None,
no_imgref: false,
imgref: imgref.clone(),
layer_progress: None,
layer_byte_progress: None,
Expand All @@ -416,6 +418,13 @@ impl ImageImporter {
self.target_imgref = Some(target.clone())
}

/// Do not write the final image ref, but do write refs for shared layers.
/// This is useful in scenarios where you want to "pre-pull" an image,
/// but in such a way that it does not need to be manually removed later.
pub fn set_no_imgref(&mut self) {
self.no_imgref = true;
}

/// Determine if there is a new manifest, and if so return its digest.
pub async fn prepare(&mut self) -> Result<PrepareResult> {
self.prepare_internal(false).await
Expand Down Expand Up @@ -787,7 +796,9 @@ impl ImageImporter {
let merged_commit = repo
.write_commit(None, None, None, Some(&metadata), &merged_root, cancellable)
.context("Writing commit")?;
repo.transaction_set_ref(None, &ostree_ref, Some(merged_commit.as_str()));
if !self.no_imgref {
repo.transaction_set_ref(None, &ostree_ref, Some(merged_commit.as_str()));
}
txn.commit(cancellable)?;
// Here we re-query state just to run through the same code path,
// though it'd be cheaper to synthesize it from the data we already have.
Expand Down

0 comments on commit f99c7fe

Please sign in to comment.