Skip to content

Commit

Permalink
fix oci-layout version to 1.0.0 (#71)
Browse files Browse the repository at this point in the history
* fix oci-layout version to 1.0.0

* add oras test
  • Loading branch information
tofay committed Oct 26, 2023
1 parent 4e886e7 commit da7c98d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
profile: minimal
toolchain: stable
override: true
- uses: oras-project/setup-oras@v1
with:
version: 1.1.0
- name: Run cargo test
run: cargo test --features test-docker

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
### Added
### Fixed

## 0.2.11 - 2023-10-26
### Fixed
- Pin oci-layout versions to 1.0.0 rather than using the OCI spec version in `oci_spec` crate.
- rpmoci 0.2.10 produces invalid OCI images that are not compatible with the OCI spec, as they have an oci-layout version of 1.0.1.

## 0.2.10 - 2023-10-25
### Fixed
- Don't attempt to verify signatures from packages from repositories that have `gpgcheck` disabled.
Expand Down
9 changes: 1 addition & 8 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rpmoci"
version = "0.2.10"
version = "0.2.11"
edition = "2021"
description = "Build container images from RPMs"
# rpmoci uses DNF (via pyo3) which is GPLV2+ licensed,
Expand All @@ -21,7 +21,6 @@ openssl = "0.10.55"
pathdiff = "0.2.1"
pyo3 = { version = "0.19.1", features = ["auto-initialize"] }
rpm = { version = "0.12.1", default-features = false }
semver = "1.0.20"
serde = { version = "1.0.185", features = ["derive"] }
serde_json = "1.0.105"
tar = "0.4.38"
Expand Down
33 changes: 17 additions & 16 deletions src/oci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use anyhow::{bail, Context, Result};
use flate2::{write::GzEncoder, Compression};
use oci_spec::image::{Descriptor, DescriptorBuilder, MediaType, OciLayout, OciLayoutBuilder};
use semver::Version;
use serde::Serialize;
use std::{
fs,
Expand All @@ -31,6 +30,10 @@ use walkdir::WalkDir;
use crate::sha256_writer::Sha256Writer;

const OCI_LAYOUT_PATH: &str = "oci-layout";
// OCI layout version: https://github.com/opencontainers/image-spec/blob/main/image-layout.md#oci-layout-file
// Fixed at 1.0.0 until changes to the layout format are made, when changes are made the new version will be
// taken from the OCI spec version that makes the changes.
const OCI_LAYOUT_VERSION: &str = "1.0.0";

/// Initialize an [OCI image directory](https://github.com/opencontainers/image-spec/blob/main/image-layout.md) if required
///
Expand All @@ -50,13 +53,11 @@ pub(crate) fn init_image_directory(layout: impl AsRef<Path>) -> Result<(), anyho

match OciLayout::from_file(layout.as_ref().join(OCI_LAYOUT_PATH)) {
Ok(oci_layout) => {
let version = Version::parse(oci_layout.image_layout_version())
.context("Failed to parse image layout version from oci-layout file")?;
if version.major != u64::from(oci_spec::image::VERSION_MAJOR) {
if oci_layout.image_layout_version() != OCI_LAYOUT_VERSION {
bail!(
"Unsupported image layout version found: {}. rpmoci only supports oci-layout versions that are semver compatible with {}",
version,
oci_spec::image::version()
"Unsupported image layout version found: {}. rpmoci only supports oci-layout version {}",
oci_layout.image_layout_version(),
OCI_LAYOUT_VERSION
)
}
}
Expand Down Expand Up @@ -96,7 +97,7 @@ fn init_dir(layout: impl AsRef<Path>) -> Result<(), anyhow::Error> {

// create oci-layout file
let oci_layout = OciLayoutBuilder::default()
.image_layout_version(oci_spec::image::version())
.image_layout_version(OCI_LAYOUT_VERSION)
.build()?;
let oci_layout_path = layout.as_ref().join(OCI_LAYOUT_PATH);
oci_layout.to_file(&oci_layout_path).context(format!(
Expand Down Expand Up @@ -292,21 +293,21 @@ where
mod tests {
use std::path::PathBuf;

use oci_spec::image::OciLayout;

use super::init_image_directory;

#[test]
fn test_init() {
let test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/init/actual");
let _ = std::fs::remove_dir_all(&test_dir);
init_image_directory(&test_dir).unwrap();
}

#[test]
fn test_init_incompatible_version() {
let test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/init/old");
let e = init_image_directory(test_dir).unwrap_err();
assert!(e
.to_string()
.contains("Unsupported image layout version found"));
assert_eq!(
OciLayout::from_file(test_dir.join("oci-layout"))
.unwrap()
.image_layout_version(),
"1.0.0"
);
}
}
14 changes: 14 additions & 0 deletions tests/it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ fn test_update_from_lockfile() {
assert!(stderr.contains("Updating dnf 4.8.0-1.cm2 -> "));
}

// This test requires oras be installed, to check that the produced images are
// compatible with another OCI tool.
#[test]
fn test_simple_build() {
let root = setup_test("simple_build");
Expand All @@ -145,6 +147,17 @@ fn test_simple_build() {
.output()
.unwrap();

let oras_status = Command::new("sudo")
.arg("oras")
.arg("copy")
.arg("--from-oci-layout")
.arg("--to-oci-layout")
.arg("foo:bar")
.arg("baz:bar")
.current_dir(&root)
.status()
.unwrap();

// Cleanup using sudo
let _ = Command::new("sudo")
.arg("rm")
Expand All @@ -156,6 +169,7 @@ fn test_simple_build() {
let stderr = std::str::from_utf8(&output.stderr).unwrap();
eprintln!("stderr: {}", stderr);
assert!(output.status.success());
assert!(oras_status.success());
}

#[test]
Expand Down

0 comments on commit da7c98d

Please sign in to comment.