Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit bdadb3b

Browse files
committed
container: Add standard OCI version key by default
And add an API to allow opting-out of the legacy label.
1 parent 01f9b46 commit bdadb3b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/src/container/encapsulate.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ use std::num::NonZeroU32;
2020
use std::path::Path;
2121
use tracing::instrument;
2222

23+
/// The label which may be used in addition to the standard OCI label.
24+
pub const LEGACY_VERSION_LABEL: &str = "version";
25+
2326
/// Type of container image generated
2427
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
2528
pub enum ExportLayout {
@@ -220,7 +223,10 @@ fn build_oci(
220223
.unwrap_or_else(|| crate::chunking::Chunking::new(repo, commit))?;
221224

222225
if let Some(version) = commit_meta.lookup::<String>("version")? {
223-
labels.insert("version".into(), version);
226+
if !opts.no_legacy_version_label {
227+
labels.insert(LEGACY_VERSION_LABEL.into(), version.clone());
228+
}
229+
labels.insert(oci_image::ANNOTATION_VERSION.into(), version);
224230
}
225231
labels.insert(OSTREE_COMMIT_LABEL.into(), commit.into());
226232

@@ -356,6 +362,9 @@ pub struct ExportOpts {
356362
pub max_layers: Option<NonZeroU32>,
357363
/// The container image layout
358364
pub format: ExportLayout,
365+
// TODO semver-break: remove this
366+
/// Use only the standard OCI version label
367+
pub no_legacy_version_label: bool,
359368
}
360369

361370
impl ExportOpts {

lib/tests/it/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ async fn impl_test_container_import_export(chunked: bool) -> Result<()> {
488488
assert!(srcoci_path.exists());
489489

490490
let inspect = skopeo_inspect(&srcoci_imgref.to_string())?;
491+
// Legacy path includes this
491492
assert!(inspect.contains(r#""version": "42.0""#));
493+
// Also include the new standard version
494+
assert!(inspect.contains(r#""org.opencontainers.image.version": "42.0""#));
492495
assert!(inspect.contains(r#""foo": "bar""#));
493496
assert!(inspect.contains(r#""test": "value""#));
494497
assert!(inspect.contains(

0 commit comments

Comments
 (0)