Skip to content

Commit fad5174

Browse files
committed
reinstall: Ensure podman is installed
Fixes #1104 Make the podman dependency of system-reinstall-bootc optional * Change the spec file to recommend podman instead of requiring it (this will make it more palatable to have this package included in distros by default) * Now that podman is only recommended, the system-reinstall-bootc binary must check whether podman is installed and try to install it. This is done by launching the install-podman script that is included with the system-reinstall-bootc RPM. The exact location where system-reinstall-bootc will look for this script is defined in the build environment variable `SYSTEM_REINSTALL_BOOTC_INSTALL_PODMAN_PATH` Signed-off-by: Omer Tuchfeld <[email protected]>
1 parent eddbb2d commit fad5174

File tree

5 files changed

+90
-7
lines changed

5 files changed

+90
-7
lines changed

Cargo.lock

Lines changed: 35 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/packaging/bootc.spec

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ Provides: ostree-cli(ostree-container)
6565
# (-n because we don't want the subpackage name to start with bootc-)
6666
%package -n system-reinstall-bootc
6767
Summary: Utility to reinstall the current system using bootc
68-
Requires: podman
68+
Recommends: podman
6969
# The reinstall subpackage intentionally does not require bootc, as it pulls in many unnecessary dependencies
7070

7171
%description -n system-reinstall-bootc
7272
This package provides a utility to simplify reinstalling the current system to a given bootc image.
7373

74+
%global system_reinstall_bootc_install_podman_path %{_prefix}/lib/system-reinstall-bootc/install-podman
75+
7476
%prep
7577
%autosetup -p1 -a1
7678
# Default -v vendor config doesn't support non-crates.io deps (i.e. git)
@@ -89,6 +91,7 @@ rm vendor-config.toml
8991

9092
# Build the system reinstallation CLI binary
9193
%global cargo_args -p system-reinstall-bootc
94+
export SYSTEM_REINSTALL_BOOTC_INSTALL_PODMAN_PATH=%{system_reinstall_bootc_install_podman_path}
9295
%cargo_build
9396

9497
%cargo_vendor_manifest
@@ -102,6 +105,12 @@ sed -i -e '/https:\/\//d' cargo-vendor.txt
102105
%if %{with ostree_ext}
103106
make install-ostree-hooks DESTDIR=%{?buildroot}
104107
%endif
108+
mkdir -p %{buildroot}/%{dirname:%{system_reinstall_bootc_install_podman_path}}
109+
cat >%{?buildroot}/%{system_reinstall_bootc_install_podman_path} <<EOF
110+
#!/bin/bash
111+
exec dnf install podman
112+
EOF
113+
chmod +x %{?buildroot}/%{system_reinstall_bootc_install_podman_path}
105114

106115
%if %{with check}
107116
%check
@@ -126,6 +135,7 @@ make install-ostree-hooks DESTDIR=%{?buildroot}
126135

127136
%files -n system-reinstall-bootc
128137
%{_bindir}/system-reinstall-bootc
138+
%{system_reinstall_bootc_install_podman_path}
129139

130140
%changelog
131141
%autochangelog

system-reinstall-bootc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ serde_json = { workspace = true }
2626
serde_yaml = "0.9.22"
2727
tracing = { workspace = true }
2828
uzers = "0.12.1"
29+
which = "7.0.2"
2930

3031
[lints]
3132
workspace = true

system-reinstall-bootc/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ fn run() -> Result<()> {
2020

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

23+
podman::ensure_podman_installed()?;
24+
2325
let mut reinstall_podman_command =
2426
podman::command(&config.bootc_image, &prompt::get_root_key()?);
2527

system-reinstall-bootc/src/podman.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use std::process::Command;
2-
31
use super::ROOT_KEY_MOUNT_POINT;
42
use crate::users::UserKeys;
3+
use anyhow::{ensure, Context, Result};
4+
use bootc_utils::CommandRunExt;
5+
use std::process::Command;
6+
use which::which;
57

68
pub(crate) fn command(image: &str, root_key: &Option<UserKeys>) -> Command {
79
let mut podman_command_and_args = [
@@ -58,3 +60,40 @@ pub(crate) fn command(image: &str, root_key: &Option<UserKeys>) -> Command {
5860

5961
command
6062
}
63+
64+
/// Path to the podman installation script. Can be influenced by the build
65+
/// SYSTEM_REINSTALL_BOOTC_INSTALL_PODMAN_PATH parameter to override. Defaults
66+
/// to /usr/lib/system-reinstall-bootc/install-podman
67+
const fn podman_install_path() -> &'static str {
68+
if let Some(path) = option_env!("SYSTEM_REINSTALL_BOOTC_INSTALL_PODMAN_PATH") {
69+
path
70+
} else {
71+
"/usr/lib/system-reinstall-bootc/install-podman"
72+
}
73+
}
74+
75+
pub(crate) fn ensure_podman_installed() -> Result<()> {
76+
if which("podman").is_ok() {
77+
return Ok(());
78+
}
79+
80+
tracing::warn!("Podman was not found on this system. It's required in order to install a bootc image.");
81+
82+
ensure!(
83+
which(podman_install_path()).is_ok(),
84+
"Podman installation script {} not found, cannot automatically install podman. Please install it manually and try again.",
85+
podman_install_path()
86+
);
87+
88+
Command::new(podman_install_path())
89+
.run_with_cmd_context()
90+
.context("installing podman")?;
91+
92+
// Make sure the installation was actually successful
93+
ensure!(
94+
which("podman").is_ok(),
95+
"podman still doesn't seem to be available, despite the installation. Please install it manually and try again."
96+
);
97+
98+
Ok(())
99+
}

0 commit comments

Comments
 (0)