Skip to content

Commit 76939a7

Browse files
authored
Merge pull request #45 from cgwalters/config-install
Add a default-enabled `install` feature
2 parents 5ba1f64 + 956d94e commit 76939a7

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
key: "tests"
3131
- name: Build
3232
run: cargo test --no-run
33+
- name: Build lib without default features
34+
run: cd lib && cargo check --no-default-features
3335
- name: Individual checks
3436
run: (cd cli && cargo check) && (cd lib && cargo check)
3537
- name: Lints

lib/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ xshell = { version = "0.2", optional = true }
3434
uuid = { version = "1.2.2", features = ["v4"] }
3535

3636
[features]
37-
default = []
37+
default = ["install"]
38+
# This feature enables `bootc install`. Disable if you always want to use an external installer.
39+
install = []
40+
# Implementation detail of man page generation.
3841
docgen = ["clap_mangen"]
42+
# This feature should only be enabled in CI environments.
3943
internal-testing-api = ["xshell"]

lib/src/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub(crate) enum Opt {
9797
/// Display status
9898
Status(StatusOpts),
9999
/// Install to the target block device
100+
#[cfg(feature = "install")]
100101
Install(crate::install::InstallOpts),
101102
/// Internal integration testing helpers.
102103
#[clap(hide(true), subcommand)]
@@ -333,6 +334,7 @@ where
333334
match opt {
334335
Opt::Upgrade(opts) => upgrade(opts).await,
335336
Opt::Switch(opts) => switch(opts).await,
337+
#[cfg(feature = "install")]
336338
Opt::Install(opts) => crate::install::install(opts).await,
337339
Opt::Status(opts) => super::status::status(opts).await,
338340
#[cfg(feature = "internal-testing-api")]

lib/src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,29 @@
1313
#![deny(clippy::dbg_macro)]
1414
#![deny(clippy::todo)]
1515

16+
pub mod cli;
17+
mod lsm;
18+
mod reexec;
19+
mod status;
20+
mod utils;
21+
22+
#[cfg(feature = "internal-testing-api")]
23+
mod privtests;
24+
25+
#[cfg(feature = "install")]
1626
mod blockdev;
27+
#[cfg(feature = "install")]
1728
mod bootloader;
18-
pub mod cli;
29+
#[cfg(feature = "install")]
1930
mod containerenv;
31+
#[cfg(feature = "install")]
2032
pub(crate) mod ignition;
33+
#[cfg(feature = "install")]
2134
mod install;
22-
mod lsm;
35+
#[cfg(feature = "install")]
2336
mod podman;
24-
#[cfg(feature = "internal-testing-api")]
25-
mod privtests;
26-
mod reexec;
27-
mod status;
37+
#[cfg(feature = "install")]
2838
mod task;
29-
mod utils;
3039

3140
#[cfg(feature = "docgen")]
3241
mod docgen;

lib/src/lsm.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ use std::process::Command;
55
use anyhow::{Context, Result};
66
use camino::{Utf8Path, Utf8PathBuf};
77
use fn_error_context::context;
8+
#[cfg(feature = "install")]
89
use gvariant::{aligned_bytes::TryAsAligned, Marker, Structure};
10+
#[cfg(feature = "install")]
911
use ostree_ext::ostree;
1012

13+
#[cfg(feature = "install")]
1114
use crate::task::Task;
1215

1316
/// The mount path for selinux
17+
#[cfg(feature = "install")]
1418
const SELINUXFS: &str = "/sys/fs/selinux";
1519
/// The SELinux xattr
20+
#[cfg(feature = "install")]
1621
const SELINUX_XATTR: &[u8] = b"security.selinux\0";
1722

1823
#[context("Querying selinux availability")]
@@ -59,6 +64,7 @@ pub(crate) fn selinux_ensure_install() -> Result<()> {
5964
/// Ensure that /sys/fs/selinux is mounted, and ensure we're running
6065
/// as install_t.
6166
#[context("Ensuring selinux mount")]
67+
#[cfg(feature = "install")]
6268
pub(crate) fn container_setup_selinux() -> Result<()> {
6369
let path = Utf8Path::new(SELINUXFS);
6470
if !path.join("enforce").exists() {
@@ -89,14 +95,18 @@ fn selinux_label_for_path(target: &str) -> Result<String> {
8995
#[context("Labeling {as_path}")]
9096
pub(crate) fn lsm_label(target: &Utf8Path, as_path: &Utf8Path, recurse: bool) -> Result<()> {
9197
let label = selinux_label_for_path(as_path.as_str())?;
92-
Task::new("Setting SELinux security context (chcon)", "chcon")
93-
.quiet()
94-
.args(["-h"])
98+
let st = Command::new("chcon")
99+
.arg("-h")
95100
.args(recurse.then_some("-R"))
96101
.args(["-h", label.as_str(), target.as_str()])
97-
.run()
102+
.status()?;
103+
if !st.success() {
104+
anyhow::bail!("Failed to invoke chcon: {st:?}");
105+
}
106+
Ok(())
98107
}
99108

109+
#[cfg(feature = "install")]
100110
pub(crate) fn xattrs_have_selinux(xattrs: &ostree::glib::Variant) -> bool {
101111
let v = xattrs.data_as_bytes();
102112
let v = v.try_as_aligned().unwrap();

lib/src/utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ where
4949
}
5050

5151
/// Run a command in the host mount namespace
52+
#[allow(dead_code)]
5253
pub(crate) fn run_in_host_mountns(cmd: &str) -> Command {
5354
let mut c = Command::new("nsenter");
5455
c.args(["-m", "-t", "1", "--", cmd]);
@@ -57,6 +58,7 @@ pub(crate) fn run_in_host_mountns(cmd: &str) -> Command {
5758

5859
/// Given a possibly tagged image like quay.io/foo/bar:latest and a digest 0ab32..., return
5960
/// the digested form quay.io/foo/bar@sha256:0ab32...
61+
#[allow(dead_code)]
6062
pub(crate) fn digested_pullspec(image: &str, digest: &str) -> String {
6163
let image = image.rsplit_once(':').map(|v| v.0).unwrap_or(image);
6264
format!("{image}@{digest}")

0 commit comments

Comments
 (0)