public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Filip Schauer <f.schauer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox 03/26] oci: add `os` parameter to parse_and_extract_image
Date: Thu, 12 Nov 2026 15:10:30 +0100	[thread overview]
Message-ID: <20261112141109.137298-4-f.schauer@proxmox.com> (raw)
In-Reply-To: <20261112141109.137298-1-f.schauer@proxmox.com>

Manifest selection from a multi-platform image index only compared the
architecture. Add an optional `os` argument to `parse_and_extract_image`
and match it together with `arch`.

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
 proxmox-oci/src/lib.rs           | 10 +++++++---
 proxmox-oci/src/oci_tar_image.rs |  9 ++++++---
 proxmox-oci/tests/helper/mod.rs  |  9 +++++++--
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/proxmox-oci/src/lib.rs b/proxmox-oci/src/lib.rs
index 0e732324..f2664857 100644
--- a/proxmox-oci/src/lib.rs
+++ b/proxmox-oci/src/lib.rs
@@ -8,7 +8,7 @@ use std::str::FromStr;
 
 use flate2::read::GzDecoder;
 use oci_spec::OciSpecError;
-pub use oci_spec::image::{Arch, Config};
+pub use oci_spec::image::{Arch, Config, Os};
 use oci_spec::image::{ImageConfiguration, ImageManifest, MediaType};
 use sha2::digest::generic_array::GenericArray;
 use sha2::{Digest, Sha256};
@@ -109,6 +109,8 @@ pub enum ProxmoxOciError {
 ///
 /// * `oci_tar_path` - Path to the OCI image tar archive
 /// * `rootfs_path` - Destination path where the rootfs will be extracted to
+/// * `os` - Optional operating system used to pick the first matching manifest from a multi-arch
+///   image index. If `None`, the first manifest will be used.
 /// * `arch` - Optional CPU architecture used to pick the first matching manifest from a multi-arch
 ///   image index. If `None`, the first manifest will be used.
 ///
@@ -119,9 +121,10 @@ pub enum ProxmoxOciError {
 pub fn parse_and_extract_image<P: AsRef<Path>>(
     oci_tar_path: P,
     rootfs_path: P,
+    os: Option<&Os>,
     arch: Option<&Arch>,
 ) -> Result<Option<Config>, ProxmoxOciError> {
-    let (oci_tar_image, image_manifest, image_config) = parse_image(oci_tar_path, arch)?;
+    let (oci_tar_image, image_manifest, image_config) = parse_image(oci_tar_path, os, arch)?;
 
     extract_image_rootfs(oci_tar_image, &image_manifest, &image_config, rootfs_path)?;
 
@@ -144,13 +147,14 @@ pub enum ParseError {
 
 fn parse_image<P: AsRef<Path>>(
     oci_tar_path: P,
+    os: Option<&Os>,
     arch: Option<&Arch>,
 ) -> Result<(OciTarImage<File>, ImageManifest, ImageConfiguration), ParseError> {
     let oci_tar_file = File::open(oci_tar_path)?;
     let mut oci_tar_image = OciTarImage::new(oci_tar_file)?;
 
     let image_manifest = oci_tar_image
-        .image_manifest(arch)
+        .image_manifest(os, arch)
         .ok_or(ParseError::NoMatchingManifest)??;
 
     let image_config_descriptor = image_manifest.config();
diff --git a/proxmox-oci/src/oci_tar_image.rs b/proxmox-oci/src/oci_tar_image.rs
index ebe3edb4..f51556e9 100644
--- a/proxmox-oci/src/oci_tar_image.rs
+++ b/proxmox-oci/src/oci_tar_image.rs
@@ -4,7 +4,7 @@ use std::ops::Range;
 use std::path::{Path, PathBuf};
 
 use oci_spec::OciSpecError;
-use oci_spec::image::{Arch, Digest, ImageIndex, ImageManifest, MediaType};
+use oci_spec::image::{Arch, Digest, ImageIndex, ImageManifest, MediaType, Os};
 use tar::Archive;
 
 use proxmox_io::RangeReader;
@@ -73,12 +73,15 @@ impl<R: Read + Seek> OciTarImage<R> {
 
     pub fn image_manifest(
         &mut self,
+        os: Option<&Os>,
         architecture: Option<&Arch>,
     ) -> Option<oci_spec::Result<ImageManifest>> {
         let digest = match self.image_index.manifests().iter().find(|d| {
             d.media_type() == &MediaType::ImageManifest
-                && architecture
-                    .is_none_or(|a| d.platform().as_ref().is_none_or(|p| p.architecture() == a))
+                && d.platform().as_ref().is_none_or(|p| {
+                    architecture.is_none_or(|a| p.architecture() == a)
+                        && os.is_none_or(|os| p.os() == os)
+                })
         }) {
             Some(descriptor) => descriptor.digest(),
             None => return None,
diff --git a/proxmox-oci/tests/helper/mod.rs b/proxmox-oci/tests/helper/mod.rs
index c07bbf9c..46491a89 100644
--- a/proxmox-oci/tests/helper/mod.rs
+++ b/proxmox-oci/tests/helper/mod.rs
@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
 
 use anyhow::Result;
 
-use proxmox_oci::{Arch, Config, ProxmoxOciError, parse_and_extract_image};
+use proxmox_oci::{Arch, Config, Os, ProxmoxOciError, parse_and_extract_image};
 use proxmox_sys::fs::make_tmp_dir;
 
 mod oci_tar_image_builder;
@@ -71,7 +71,12 @@ impl TestImage {
     }
 
     pub fn extract(&self) -> Result<Option<Config>, ProxmoxOciError> {
-        parse_and_extract_image(&self.path, &self.extract_dir, Some(&Arch::Amd64))
+        parse_and_extract_image(
+            &self.path,
+            &self.extract_dir,
+            Some(&Os::Linux),
+            Some(&Arch::Amd64),
+        )
     }
 }
 
-- 
2.47.3





  parent reply	other threads:[~2026-11-12 14:12 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 14:10 [PATCH container/manager/proxmox{,-perl-rs}/storage 00/26] oci: add native registry client and prepare for OverlayFS Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox-perl-rs 01/26] pve-rs: oci: update doc comment of parse_and_extract_image Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 02/26] oci: rename error when no manifest can be selected Filip Schauer
2026-11-12 14:10 ` Filip Schauer [this message]
2026-11-12 14:10 ` [PATCH proxmox-perl-rs 04/26] pve-rs: oci: add `os` parameter to parse_and_extract_image Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 05/26] oci: add a digest helper module Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 06/26] oci: reduce redundant layer decompression during extraction Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 07/26] oci: factor out parsing and extraction into modules Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 08/26] oci: explicitly set mtime of directories when extracting layer Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 09/26] oci: add a registry client Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 10/26] oci: add a public list_repository_tags function Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox-perl-rs 11/26] pve-rs: oci: expose list_repository_tags Filip Schauer
2026-11-12 14:10 ` [PATCH manager 12/26] use proxmox-oci instead of skopeo for listing tags from OCI registries Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 13/26] oci: rename parse_and_extract_image to be tar-specific Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox-perl-rs 14/26] pve-rs: " Filip Schauer
2026-11-12 14:10 ` [PATCH container 15/26] oci create: " Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 16/26] oci: rename ProxmoxOciError to ParseAndExtractTarError Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 17/26] oci: add a public pull_image_as_tar function Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox-perl-rs 18/26] pve-rs: oci: expose pull_image_as_tar Filip Schauer
2026-11-12 14:10 ` [PATCH storage 19/26] use proxmox-oci instead of skopeo for pulling from OCI registries Filip Schauer
2026-11-12 14:10 ` [PATCH storage 20/26] api: oci image pull: fix temp file cleanup on task stop Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 21/26] oci: add a public pull_image_to_oci_storage function Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox-perl-rs 22/26] pve-rs: oci: expose pull_image_to_oci_storage Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 23/26] fix #7058: oci: add compatibility for Docker Image Manifest V2 Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 24/26] oci: include media type in ParseError::WrongMediaType Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox 25/26] oci: add public functions for removing OCI images Filip Schauer
2026-11-12 14:10 ` [PATCH proxmox-perl-rs 26/26] pve-rs: oci: expose " Filip Schauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261112141109.137298-4-f.schauer@proxmox.com \
    --to=f.schauer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal