From fae644c0d9230ee2e7a888c6e045ba84b3710d7a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 2 Feb 2024 15:01:27 -0500 Subject: [PATCH] Add suggestion for `LABEL containers.bootc 1` As we aim to slowly move away from ostree, let's add a bootc label that we expect to be used. For now, this is just a warning. I will change rpm-ostree to add this by default if we take this. But this one is also an important step for if we ever add the flow of simply deriving from an existing application base image. Signed-off-by: Colin Walters --- docs/bootc-images.md | 10 ++++++++++ lib/src/cli.rs | 1 + lib/src/deploy.rs | 22 ++++++++++++++++++++++ lib/src/lib.rs | 1 + lib/src/metadata.rs | 4 ++++ 5 files changed, 38 insertions(+) create mode 100644 lib/src/metadata.rs diff --git a/docs/bootc-images.md b/docs/bootc-images.md index 8a3355634..afa1470c3 100644 --- a/docs/bootc-images.md +++ b/docs/bootc-images.md @@ -50,6 +50,16 @@ The requirement for both methods is that your initial treefile/manifest However, the ostree usage is an implementation detail and the requirement on this will be lifted in the future. +## Standard metadata for bootc compatible images + +It is strongly recommended to do: + +```dockerfile +LABEL containers.bootc 1 +``` + +This will signal that this image is intended to be usable with `bootc`. + # Deriving from existing base images It's important to emphasize that from one diff --git a/lib/src/cli.rs b/lib/src/cli.rs index da4441bab..77154fcb7 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -341,6 +341,7 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> { println!("No changes in: {}", imgref); } PrepareResult::Ready(r) => { + crate::deploy::check_bootc_label(&r.config); println!("Update available for: {}", imgref); if let Some(version) = r.version() { println!(" Version: {version}"); diff --git a/lib/src/deploy.rs b/lib/src/deploy.rs index 6b4373983..df53779e0 100644 --- a/lib/src/deploy.rs +++ b/lib/src/deploy.rs @@ -19,6 +19,7 @@ use ostree_ext::sysroot::SysrootLock; use crate::spec::HostSpec; use crate::spec::ImageReference; +use crate::status::labels_of_config; // TODO use https://github.com/ostreedev/ostree-rs-ext/pull/493/commits/afc1837ff383681b947de30c0cefc70080a4f87a const BASE_IMAGE_PREFIX: &str = "ostree/container/baseimage/bootc"; @@ -84,6 +85,26 @@ pub(crate) async fn new_importer( Ok(imp) } +pub(crate) fn check_bootc_label(config: &ostree_ext::oci_spec::image::ImageConfiguration) { + if let Some(label) = + labels_of_config(config).and_then(|labels| labels.get(crate::metadata::BOOTC_COMPAT_LABEL)) + { + match label.as_str() { + crate::metadata::COMPAT_LABEL_V1 => {} + o => eprintln!( + "notice: Unknown {} value {}", + crate::metadata::BOOTC_COMPAT_LABEL, + o + ), + } + } else { + eprintln!( + "notice: Image is missing label: {}", + crate::metadata::BOOTC_COMPAT_LABEL + ) + } +} + /// Wrapper for pulling a container image, wiring up status output. #[context("Pulling")] pub(crate) async fn pull( @@ -101,6 +122,7 @@ pub(crate) async fn pull( } PrepareResult::Ready(p) => p, }; + check_bootc_label(&prep.config); if let Some(warning) = prep.deprecated_warning() { ostree_ext::cli::print_deprecated_warning(warning).await; } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index fafdd991e..9bb1ac3d2 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -20,6 +20,7 @@ pub mod cli; pub(crate) mod deploy; mod lsm; +pub(crate) mod metadata; mod reboot; mod reexec; mod status; diff --git a/lib/src/metadata.rs b/lib/src/metadata.rs new file mode 100644 index 000000000..4db5758bf --- /dev/null +++ b/lib/src/metadata.rs @@ -0,0 +1,4 @@ +/// This label is expected to be present on compatible base images. +pub(crate) const BOOTC_COMPAT_LABEL: &str = "containers.bootc"; +/// The current single well-known value for the label. +pub(crate) const COMPAT_LABEL_V1: &str = "1";