Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add support for configmaps #100

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
59 changes: 14 additions & 45 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anyhow::{Context, Result};
use camino::Utf8PathBuf;
use clap::Parser;
use fn_error_context::context;
use ostree::{gio, glib};
use ostree::gio;
use ostree_container::store::LayeredImageState;
use ostree_container::store::PrepareResult;
use ostree_container::OstreeImageReference;
Expand All @@ -21,7 +21,6 @@ use std::os::unix::process::CommandExt;
use std::process::Command;

use crate::spec::Host;
use crate::spec::HostSpec;
use crate::spec::ImageReference;

/// Perform an upgrade operation
Expand Down Expand Up @@ -131,6 +130,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 @@ -229,45 +231,6 @@ async fn pull(
Ok(import)
}

/// Stage (queue deployment of) a fetched container image.
#[context("Staging")]
async fn stage(
sysroot: &SysrootLock,
stateroot: &str,
image: Box<LayeredImageState>,
spec: &HostSpec,
) -> Result<()> {
let cancellable = gio::Cancellable::NONE;
let stateroot = Some(stateroot);
let merge_deployment = sysroot.merge_deployment(stateroot);
let origin = glib::KeyFile::new();
let ostree_imgref = spec
.image
.as_ref()
.map(|imgref| OstreeImageReference::from(imgref.clone()));
if let Some(imgref) = ostree_imgref.as_ref() {
origin.set_string(
"origin",
ostree_container::deploy::ORIGIN_CONTAINER,
imgref.to_string().as_str(),
);
}
let _new_deployment = sysroot.stage_tree_with_options(
stateroot,
image.merge_commit.as_str(),
Some(&origin),
merge_deployment.as_ref(),
&Default::default(),
cancellable,
)?;
if let Some(imgref) = ostree_imgref.as_ref() {
println!("Queued for next boot: {imgref}");
}
ostree_container::deploy::remove_undeployed_images(sysroot).context("Pruning images")?;

Ok(())
}

#[context("Querying root privilege")]
pub(crate) fn require_root() -> Result<()> {
let uid = rustix::process::getuid();
Expand All @@ -282,7 +245,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 @@ -295,6 +258,11 @@ async fn prepare_for_write() -> Result<()> {
Ok(())
}

pub(crate) fn target_deployment(sysroot: &SysrootLock) -> Result<ostree::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<()> {
Expand Down Expand Up @@ -351,7 +319,7 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
}

let osname = booted_deployment.osname();
stage(sysroot, &osname, fetched, &host.spec).await?;
crate::deploy::stage(sysroot, &osname, fetched, &host.spec).await?;
}
if let Some(path) = opts.touch_if_changed {
std::fs::write(&path, "").with_context(|| format!("Writing {path}"))?;
Expand Down Expand Up @@ -410,7 +378,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
}

let stateroot = booted_deployment.osname();
stage(sysroot, &stateroot, fetched, &new_spec).await?;
crate::deploy::stage(sysroot, &stateroot, fetched, &new_spec).await?;

Ok(())
}
Expand Down Expand Up @@ -448,7 +416,7 @@ async fn edit(opts: EditOpts) -> Result<()> {
// TODO gc old layers here

let stateroot = booted_deployment.osname();
stage(sysroot, &stateroot, fetched, &new_host.spec).await?;
crate::deploy::stage(sysroot, &stateroot, fetched, &new_host.spec).await?;

Ok(())
}
Expand Down Expand Up @@ -476,6 +444,7 @@ where
Opt::Switch(opts) => switch(opts).await,
Opt::Edit(opts) => edit(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
Loading