Skip to content
Open
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
20 changes: 15 additions & 5 deletions .github/workflows/crates-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name: Publish to crates.io
on:
push:
tags: ['v*'] # Triggers when pushing tags starting with 'v'
tags: ['v*']
workflow_dispatch: {}
jobs:
publish:
runs-on: ubuntu-24.04
Expand All @@ -13,10 +14,19 @@ jobs:
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- run: |
for crate in bootc-internal-utils bootc-internal-blockdev; do
echo "Publishing $crate..."
cargo publish -p "$crate"
echo "Successfully published $crate"
# Publish crates if their current version is not already on crates.io.
# Order matters: dependencies must be published first.
CRATES="bootc-internal-utils bootc-internal-mount bootc-internal-blockdev"

for crate in $CRATES; do
VERSION=$(cargo read-manifest -p "$crate" | jq -r '.version')
if cargo info "$crate@$VERSION" > /dev/null 2>&1; then
echo "$crate@$VERSION is already published, skipping"
else
echo "Publishing $crate@$VERSION..."
cargo publish -p "$crate"
echo "Successfully published $crate@$VERSION"
fi
done
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
5 changes: 5 additions & 0 deletions .github/workflows/scheduled-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ jobs:
cargo set-version --manifest-path crates/lib/Cargo.toml --package bootc-lib --bump ${INPUT_VERSION:-minor}
VERSION=$(cargo read-manifest --manifest-path crates/lib/Cargo.toml | jq -r '.version')

# Set internal crate versions to match the bootc release version
cargo set-version --manifest-path crates/utils/Cargo.toml --package bootc-internal-utils "$VERSION"
cargo set-version --manifest-path crates/mount/Cargo.toml --package bootc-internal-mount "$VERSION"
cargo set-version --manifest-path crates/blockdev/Cargo.toml --package bootc-internal-blockdev "$VERSION"

cargo update --workspace
cargo xtask update-generated
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
Expand Down
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/blockdev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = "0.2.0"
[dependencies]
# Internal crates
bootc-utils = { package = "bootc-internal-utils", path = "../utils", version = "0.1.0" }
bootc-mount = { path = "../mount" }
bootc-mount = { package = "bootc-internal-mount", path = "../mount", version = "0.1.0" }

# Workspace dependencies
anyhow = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include = ["/src", "LICENSE-APACHE", "LICENSE-MIT"]
# Internal crates
bootc-blockdev = { package = "bootc-internal-blockdev", path = "../blockdev", version = "0.2.0" }
bootc-kernel-cmdline = { path = "../kernel_cmdline", version = "0.0.0" }
bootc-mount = { path = "../mount" }
bootc-mount = { package = "bootc-internal-mount", path = "../mount", version = "0.1.0" }
bootc-sysusers = { path = "../sysusers" }
bootc-tmpfiles = { path = "../tmpfiles" }
bootc-utils = { package = "bootc-internal-utils", path = "../utils", version = "0.1.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
//! # Related Crates
//!
//! - [`ostree-ext`](../ostree_ext/index.html) - OCI/ostree bridging
//! - [`bootc-mount`](../bootc_mount/index.html) - Mount utilities
//! - [`bootc-internal-mount`](../bootc_mount/index.html) - Mount utilities
//! - [`bootc-kernel-cmdline`](../bootc_kernel_cmdline/index.html) - Cmdline parsing
//! - [`etc-merge`](../etc_merge/index.html) - `/etc` three-way merge

Expand Down
11 changes: 6 additions & 5 deletions crates/mount/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[package]
description = "Internal mount code"
# Should never be published to crates.io
publish = false
description = "Internal implementation component of bootc; do not use"
edition = "2024"
license = "MIT OR Apache-2.0"
name = "bootc-mount"
name = "bootc-internal-mount"
repository = "https://github.com/bootc-dev/bootc"
version = "0.0.0"
version = "0.1.0"

[dependencies]
# Internal crates
Expand All @@ -28,3 +26,6 @@ indoc = { workspace = true }

[lib]
path = "src/mount.rs"

[lints]
workspace = true
22 changes: 17 additions & 5 deletions crates/mount/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use rustix::{
};
use serde::Deserialize;

/// Temporary mount management with automatic cleanup.
pub mod tempmount;

/// Well known identifier for pid 1
Expand All @@ -33,26 +34,37 @@ pub const PID1: Pid = const {
}
};

/// Deserialized information about a mounted filesystem from `findmnt`.
#[derive(Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
#[allow(dead_code)]
pub struct Filesystem {
// Note if you add an entry to this list, you need to change the --output invocation below too
/// The source device or path.
pub source: String,
/// The mount target path.
pub target: String,
/// Major:minor device numbers.
#[serde(rename = "maj:min")]
pub maj_min: String,
/// The filesystem type (e.g. ext4, xfs).
pub fstype: String,
/// Mount options.
pub options: String,
/// The filesystem UUID, if available.
pub uuid: Option<String>,
/// Child filesystems, if any.
pub children: Option<Vec<Filesystem>>,
}

/// Deserialized output of `findmnt --json`.
#[derive(Deserialize, Debug, Default)]
pub struct Findmnt {
/// The list of mounted filesystems.
pub filesystems: Vec<Filesystem>,
}

/// Run `findmnt` with JSON output and parse the result.
pub fn run_findmnt(args: &[&str], cwd: Option<&Dir>, path: Option<&str>) -> Result<Findmnt> {
let mut cmd = Command::new("findmnt");
if let Some(cwd) = cwd {
Expand Down Expand Up @@ -99,8 +111,8 @@ pub fn inspect_filesystem_by_uuid(uuid: &str) -> Result<Filesystem> {
findmnt_filesystem(&["--source"], None, &(format!("UUID={uuid}")))
}

// Check if a specified device contains an already mounted filesystem
// in the root mount namespace
/// Check if a specified device contains an already mounted filesystem
/// in the root mount namespace.
pub fn is_mounted_in_pid1_mountns(path: &str) -> Result<bool> {
let o = run_findmnt(&["-N"], None, Some("1"))?;

Expand All @@ -109,7 +121,7 @@ pub fn is_mounted_in_pid1_mountns(path: &str) -> Result<bool> {
Ok(mounted)
}

// Recursively check a given filesystem to see if it contains an already mounted source
/// Recursively check a given filesystem to see if it contains an already mounted source.
pub fn is_source_mounted(path: &str, mounted_fs: &Filesystem) -> bool {
if mounted_fs.source.contains(path) {
return true;
Expand Down Expand Up @@ -281,8 +293,8 @@ pub fn bind_mount_from_pidns(
Ok(())
}

// If the target path is not already mirrored from the host (e.g. via -v /dev:/dev)
// then recursively mount it.
/// If the target path is not already mirrored from the host (e.g. via `-v /dev:/dev`)
/// then recursively mount it.
pub fn ensure_mirrored_host_mount(path: impl AsRef<Utf8Path>) -> Result<()> {
let path = path.as_ref();
// If we didn't have this in our filesystem already (e.g. for /var/lib/containers)
Expand Down
4 changes: 4 additions & 0 deletions crates/mount/src/tempmount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ use cap_std_ext::cap_std::{ambient_authority, fs::Dir};
use fn_error_context::context;
use rustix::mount::{MountFlags, MoveMountFlags, UnmountFlags, move_mount, unmount};

/// RAII wrapper for a temporary mount that is automatically unmounted on drop.
#[derive(Debug)]
pub struct TempMount {
/// The backing temporary directory.
pub dir: tempfile::TempDir,
/// An open handle to the mounted directory.
pub fd: Dir,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/system-reinstall-bootc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ platforms = ["*-unknown-linux-gnu"]

[dependencies]
# Internal crates
bootc-mount = { path = "../mount" }
bootc-mount = { package = "bootc-internal-mount", path = "../mount", version = "0.1.0" }
bootc-utils = { package = "bootc-internal-utils", path = "../utils", version = "0.1.0" }

# Workspace dependencies
Expand Down