Skip to content

Commit

Permalink
Add support for configmaps
Browse files Browse the repository at this point in the history
This is part of containers#22
  • Loading branch information
cgwalters committed Jul 6, 2023
1 parent e851fbb commit 1424a7a
Show file tree
Hide file tree
Showing 8 changed files with 941 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tempfile = "3.3.0"
toml = "0.7.2"
xshell = { version = "0.2", optional = true }
uuid = { version = "1.2.2", features = ["v4"] }
reqwest = { version = "0.11.14", features = ["json"] }

[features]
default = ["install"]
Expand Down
51 changes: 49 additions & 2 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ostree_ext::container as ostree_container;
use ostree_ext::container::SignatureSource;
use ostree_ext::keyfileext::KeyFileExt;
use ostree_ext::ostree;
use ostree_ext::ostree::Deployment;
use ostree_ext::sysroot::SysrootLock;
use std::ffi::OsString;
use std::os::unix::process::CommandExt;
Expand Down Expand Up @@ -116,6 +117,9 @@ pub(crate) enum Opt {
/// Add a transient writable overlayfs on `/usr` that will be discarded on reboot.
#[clap(alias = "usroverlay")]
UsrOverlay,
/// Manipulate configuration
#[clap(subcommand)]
Config(crate::config::ConfigOpts),
/// Install to the target block device
#[cfg(feature = "install")]
Install(crate::install::InstallOpts),
Expand Down Expand Up @@ -216,12 +220,13 @@ async fn pull(

/// Stage (queue deployment of) a fetched container image.
#[context("Staging")]
async fn stage(
pub(crate) async fn stage(
sysroot: &SysrootLock,
stateroot: &str,
image: Box<LayeredImageState>,
spec: &HostSpec,
) -> Result<()> {
<<<<<<< HEAD
let cancellable = gio::Cancellable::NONE;
let stateroot = Some(stateroot);
let merge_deployment = sysroot.merge_deployment(stateroot);
Expand All @@ -248,6 +253,12 @@ async fn stage(
if let Some(imgref) = ostree_imgref.as_ref() {
println!("Queued for next boot: {imgref}");
}
=======
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
crate::deploy::deploy(sysroot, merge_deployment.as_ref(), stateroot, image, origin).await?;
crate::deploy::cleanup(sysroot).await?;
println!("Queued for next boot: {imgref}");
>>>>>>> 6b0a900 (Add support for configmaps)
Ok(())
}

Expand All @@ -265,7 +276,7 @@ pub(crate) fn require_root() -> Result<()> {

/// A few process changes that need to be made for writing.
#[context("Preparing for write")]
async fn prepare_for_write() -> Result<()> {
pub(crate) async fn prepare_for_write() -> Result<()> {
if ostree_ext::container_utils::is_ostree_container()? {
anyhow::bail!(
"Detected container (ostree base); this command requires a booted host system."
Expand All @@ -278,22 +289,43 @@ async fn prepare_for_write() -> Result<()> {
Ok(())
}

pub(crate) fn target_deployment(sysroot: &SysrootLock) -> Result<Deployment> {
let booted_deployment = sysroot.require_booted_deployment()?;
Ok(sysroot.staged_deployment().unwrap_or(booted_deployment))
}

/// Implementation of the `bootc upgrade` CLI command.
#[context("Upgrading")]
async fn upgrade(opts: UpgradeOpts) -> Result<()> {
prepare_for_write().await?;
let sysroot = &get_locked_sysroot().await?;
<<<<<<< HEAD
let booted_deployment = &sysroot.require_booted_deployment()?;
let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?;
// SAFETY: There must be a status if we have a booted deployment
let status = host.status.unwrap();
let imgref = host.spec.image.as_ref();
// If there's no specified image, let's be nice and check if the booted system is using rpm-ostree
if imgref.is_none() && status.booted.map_or(false, |b| b.incompatible) {
=======
let repo = &sysroot.repo();
let merge_deployment = &target_deployment(sysroot)?;
let status = crate::status::DeploymentStatus::from_deployment(merge_deployment, true)?;
let osname = merge_deployment.osname();
let origin = merge_deployment
.origin()
.ok_or_else(|| anyhow::anyhow!("Deployment is missing an origin"))?;
let imgref = status
.image
.ok_or_else(|| anyhow::anyhow!("Booted deployment is not container image based"))?;
let imgref: OstreeImageReference = imgref.into();
if !status.supported {
>>>>>>> 6b0a900 (Add support for configmaps)
return Err(anyhow::anyhow!(
"Booted deployment contains local rpm-ostree modifications; cannot upgrade via bootc"
));
}
<<<<<<< HEAD
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
Expand Down Expand Up @@ -332,6 +364,12 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
return Ok(());
}
}
=======
let commit = merge_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?;
>>>>>>> 6b0a900 (Add support for configmaps)

let osname = booted_deployment.osname();
stage(sysroot, &osname, fetched, &host.spec).await?;
Expand All @@ -348,8 +386,16 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
async fn switch(opts: SwitchOpts) -> Result<()> {
prepare_for_write().await?;
let cancellable = gio::Cancellable::NONE;
<<<<<<< HEAD

let sysroot = &get_locked_sysroot().await?;
=======
let sysroot = &get_locked_sysroot().await?;
let merge_deployment = &target_deployment(sysroot)?;
let (origin, booted_image) = crate::utils::get_image_origin(merge_deployment)?;
let booted_refspec = origin.optional_string("origin", "refspec")?;
let osname = merge_deployment.osname();
>>>>>>> 6b0a900 (Add support for configmaps)
let repo = &sysroot.repo();
let booted_deployment = &sysroot.require_booted_deployment()?;
let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?;
Expand Down Expand Up @@ -427,6 +473,7 @@ where
Opt::Upgrade(opts) => upgrade(opts).await,
Opt::Switch(opts) => switch(opts).await,
Opt::UsrOverlay => usroverlay().await,
Opt::Config(opts) => crate::config::run(opts).await,
#[cfg(feature = "install")]
Opt::Install(opts) => crate::install::install(opts).await,
#[cfg(feature = "install")]
Expand Down
Loading

0 comments on commit 1424a7a

Please sign in to comment.