This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add a new container/store module
The initial scope of this project was just "encapsulating" ostree commits in containers. However, when doing that a very, very natural question arises: Why not support *deriving* from that base image container, and have the tooling natively support importing it? This initial prototype code implements that. Here, we still use the `tar::import` path for the base image - we expect it to have a pre-generated ostree commit. This new `container::store` module processes layered images and generates (client side) ostree commits from the tar layers. There's a whole lot of new infrastructure we need around mapping ostree refs to blobs and images, etc.
- Loading branch information
Showing
7 changed files
with
692 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//! Perform initial setup for a container image based system root | ||
use super::OstreeImageReference; | ||
use crate::container::store::PrepareResult; | ||
use anyhow::Result; | ||
use ostree::glib; | ||
|
||
/// The key in the OSTree origin which holds a serialized [`super::OstreeImageReference`]. | ||
pub const ORIGIN_CONTAINER: &str = "container"; | ||
|
||
async fn pull_idempotent(repo: &ostree::Repo, imgref: &OstreeImageReference) -> Result<String> { | ||
let mut imp = super::store::LayeredImageImporter::new(repo, imgref).await?; | ||
match imp.prepare().await? { | ||
PrepareResult::AlreadyPresent(r) => Ok(r), | ||
PrepareResult::Ready(prep) => Ok(imp.import(prep).await?.commit), | ||
} | ||
} | ||
|
||
/// Options configuring deployment. | ||
#[derive(Debug, Default)] | ||
pub struct DeployOpts<'a> { | ||
/// Kernel arguments to use. | ||
pub kargs: Option<&'a [&'a str]>, | ||
} | ||
|
||
/// Write a container image to an OSTree deployment. | ||
/// | ||
/// This API is currently intended for only an initial deployment. | ||
pub async fn deploy<'opts>( | ||
sysroot: &ostree::Sysroot, | ||
stateroot: &str, | ||
imgref: &OstreeImageReference, | ||
options: Option<DeployOpts<'opts>>, | ||
) -> Result<()> { | ||
let cancellable = ostree::gio::NONE_CANCELLABLE; | ||
let options = options.unwrap_or_default(); | ||
let repo = &sysroot.repo().unwrap(); | ||
let commit = &pull_idempotent(repo, imgref).await?; | ||
let origin = glib::KeyFile::new(); | ||
origin.set_string("ostree", ORIGIN_CONTAINER, &imgref.to_string()); | ||
let deployment = &sysroot.deploy_tree( | ||
Some(stateroot), | ||
commit, | ||
Some(&origin), | ||
None, | ||
options.kargs.unwrap_or_default(), | ||
cancellable, | ||
)?; | ||
let flags = ostree::SysrootSimpleWriteDeploymentFlags::NONE; | ||
sysroot.simple_write_deployment(Some(stateroot), deployment, None, flags, cancellable)?; | ||
sysroot.cleanup(cancellable)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.