Skip to content

Commit

Permalink
Merge pull request #1164 from ckyrouac/reinstall-cloudinit
Browse files Browse the repository at this point in the history
reinstall: Pull podman image early
  • Loading branch information
cgwalters authored Mar 4, 2025
2 parents b26d5ca + 3e1b0bf commit f1ab775
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
18 changes: 12 additions & 6 deletions system-reinstall-bootc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ fn run() -> Result<()> {

let config = config::ReinstallConfig::load().context("loading config")?;

podman::ensure_podman_installed()?;

//pull image early so it can be inspected, e.g. to check for cloud-init
let mut pull_image_command = podman::pull_image_command(&config.bootc_image);
pull_image_command
.run_with_cmd_context()
.context(format!("pulling image {}", &config.bootc_image))?;

println!();

let ssh_key_file = tempfile::NamedTempFile::new()?;
let ssh_key_file_path = ssh_key_file
.path()
Expand All @@ -30,18 +40,14 @@ fn run() -> Result<()> {

prompt::get_ssh_keys(ssh_key_file_path)?;

let mut reinstall_podman_command = podman::command(&config.bootc_image, ssh_key_file_path);
let mut reinstall_podman_command =
podman::reinstall_command(&config.bootc_image, ssh_key_file_path);

println!();

println!("Going to run command {:?}", reinstall_podman_command);

prompt::temporary_developer_protection_prompt()?;

// At this poihnt, the user has already given us permission to reinstall their system, so we
// feel confident with just installing podman without any further user interaction.
podman::ensure_podman_installed()?;

reinstall_podman_command
.run_with_cmd_context()
.context("running reinstall command")?;
Expand Down
14 changes: 10 additions & 4 deletions system-reinstall-bootc/src/podman.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::prompt;

use super::ROOT_KEY_MOUNT_POINT;
use anyhow::{ensure, Context, Result};
use bootc_utils::CommandRunExt;
use std::process::Command;
use which::which;

pub(crate) fn command(image: &str, ssh_key_file: &str) -> Command {
pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
let mut podman_command_and_args = [
// We use podman to run the bootc container. This might change in the future to remove the
// podman dependency.
Expand Down Expand Up @@ -62,6 +64,12 @@ pub(crate) fn command(image: &str, ssh_key_file: &str) -> Command {
command
}

pub(crate) fn pull_image_command(image: &str) -> Command {
let mut command = Command::new("podman");
command.args(["pull", image]);
command
}

/// Path to the podman installation script. Can be influenced by the build
/// SYSTEM_REINSTALL_BOOTC_INSTALL_PODMAN_PATH parameter to override. Defaults
/// to /usr/lib/system-reinstall-bootc/install-podman
Expand All @@ -78,9 +86,7 @@ pub(crate) fn ensure_podman_installed() -> Result<()> {
return Ok(());
}

tracing::warn!(
"Podman was not found on this system. It's required in order to install a bootc image. Attempting to install it automatically."
);
prompt::ask_yes_no("Podman was not found on this system. It's required in order to install a bootc image. Do you want to install it now?", true)?;

ensure!(
which(podman_install_script_path()).is_ok(),
Expand Down

0 comments on commit f1ab775

Please sign in to comment.