Skip to content

Commit 6a1ba9f

Browse files
authored
Merge pull request #1105 from omertuc/ep
reinstall: Ensure podman is installed
2 parents 3c34723 + d707b57 commit 6a1ba9f

File tree

7 files changed

+98
-8
lines changed

7 files changed

+98
-8
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 -y 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ fn run() -> Result<()> {
3838

3939
prompt::temporary_developer_protection_prompt()?;
4040

41+
// At this poihnt, the user has already given us permission to reinstall their system, so we
42+
// feel confident with just installing podman without any further user interaction.
43+
podman::ensure_podman_installed()?;
44+
4145
reinstall_podman_command
4246
.run_with_cmd_context()
4347
.context("running reinstall command")?;

system-reinstall-bootc/src/podman.rs

Lines changed: 43 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,42 @@ 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_script_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!(
81+
"Podman was not found on this system. It's required in order to install a bootc image."
82+
);
83+
84+
ensure!(
85+
which(podman_install_script_path()).is_ok(),
86+
"Podman installation script {} not found, cannot automatically install podman. Please install it manually and try again.",
87+
podman_install_script_path()
88+
);
89+
90+
Command::new(podman_install_script_path())
91+
.run_with_cmd_context()
92+
.context("installing podman")?;
93+
94+
// Make sure the installation was actually successful
95+
ensure!(
96+
which("podman").is_ok(),
97+
"podman still doesn't seem to be available, despite the installation. Please install it manually and try again."
98+
);
99+
100+
Ok(())
101+
}

utils/src/command.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ impl CommandRunExt for Command {
139139
}
140140

141141
fn run_with_cmd_context(&mut self) -> Result<()> {
142-
self.run()
142+
self.status()?
143+
.success()
144+
.then_some(())
143145
// The [`Debug`] output of command contains a properly shell-escaped commandline
144146
// representation that the user can copy paste into their shell
145147
.context("Failed to run command: {self:#?}")

utils/src/tracing_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ pub fn initialize_tracing() {
1414
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
1515
.event_format(format)
1616
.with_writer(std::io::stderr)
17+
.with_max_level(tracing::Level::WARN)
1718
.init();
1819
}

0 commit comments

Comments
 (0)