Skip to content

Commit

Permalink
fix oci-spec breaking changes
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Dec 17, 2024
1 parent 9e05f21 commit a09ad04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
8 changes: 6 additions & 2 deletions crates/containerd-shim-wasm/src/container/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl RuntimeContext for WasiContext<'_> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use oci_spec::image::Descriptor;
use oci_spec::image::{Descriptor, Digest};
use oci_spec::runtime::{ProcessBuilder, RootBuilder, SpecBuilder};

use super::*;
Expand Down Expand Up @@ -370,7 +370,11 @@ mod tests {
spec: &spec,
wasm_layers: &[WasmLayer {
layer: vec![],
config: Descriptor::new(oci_spec::image::MediaType::Other("".to_string()), 10, ""),
config: Descriptor::new(
oci_spec::image::MediaType::Other("".to_string()),
10,
Digest::try_from(format!("sha256:{:064?}", 0))?,
),
}],
platform: &Platform::default(),
};
Expand Down
10 changes: 5 additions & 5 deletions crates/containerd-shim-wasm/src/sandbox/containerd/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use containerd_client::tonic::transport::Channel;
use containerd_client::tonic::Streaming;
use containerd_client::{tonic, with_namespace};
use futures::TryStreamExt;
use oci_spec::image::{Arch, ImageManifest, MediaType, Platform};
use oci_spec::image::{Arch, Digest, ImageManifest, MediaType, Platform};
use sha256::digest;
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
Expand Down Expand Up @@ -259,7 +259,7 @@ impl Client {
}

#[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))]
async fn get_info(&self, content_digest: &str) -> Result<Info> {
async fn get_info(&self, content_digest: &Digest) -> Result<Info> {
let req = InfoRequest {
digest: content_digest.to_string(),
};
Expand Down Expand Up @@ -359,9 +359,9 @@ impl Client {
async fn get_image_manifest_and_digest(
&self,
image_name: &str,
) -> Result<(ImageManifest, String)> {
) -> Result<(ImageManifest, Digest)> {
let image = self.get_image(image_name).await?;
let image_digest = self.extract_image_content_sha(&image)?;
let image_digest = self.extract_image_content_sha(&image)?.try_into()?;
let manifest =
ImageManifest::from_reader(self.read_content(&image_digest).await?.as_slice())?;
Ok((manifest, image_digest))
Expand Down Expand Up @@ -521,7 +521,7 @@ impl Client {
let info = self.get_info(&digest_to_load).await?;
if let Some(label) = info.labels.get(precompile_id) {
// Safe to unwrap here since we already checked for the label's existence
digest_to_load.clone_from(label);
digest_to_load = label.parse()?;
log::info!(
"layer {} has pre-compiled content: {} ",
info.digest,
Expand Down
19 changes: 9 additions & 10 deletions crates/oci-tar-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use anyhow::{Context, Error, Result};
use indexmap::IndexMap;
use log::{debug, warn};
use oci_spec::image::{
DescriptorBuilder, ImageConfiguration, ImageIndexBuilder, ImageManifestBuilder, MediaType,
PlatformBuilder, SCHEMA_VERSION,
DescriptorBuilder, Digest, ImageConfiguration, ImageIndexBuilder, ImageManifestBuilder,
MediaType, PlatformBuilder, SCHEMA_VERSION,
};
use oci_wasm::{WasmConfig, WASM_ARCHITECTURE};
use serde::Serialize;
Expand Down Expand Up @@ -142,7 +142,6 @@ impl<C: OciConfig> Builder<C> {
for layer in self.layers.iter() {
let dgst = try_digest(layer.0.as_path()).context("failed to digest layer")?;
let meta = metadata(layer.0.clone()).context("could not get layer metadata")?;
let oci_digest = "sha256:".to_owned() + &dgst;

let mut media_type = MediaType::ImageLayer;
if !layer.1.is_empty() {
Expand All @@ -151,11 +150,11 @@ impl<C: OciConfig> Builder<C> {
let desc = DescriptorBuilder::default()
// TODO: check file headers to determine mediatype? Could also just require it to be passed in on add_layer
.media_type(media_type)
.digest(&oci_digest)
.size(meta.len() as i64)
.digest(Digest::try_from(format!("sha256:{dgst}"))?)
.size(meta.len() as u64)

Check failure on line 154 in crates/oci-tar-builder/src/lib.rs

View workflow job for this annotation

GitHub Actions / common / lint on ubuntu-latest

casting to the same type is unnecessary (`u64` -> `u64`)
.build()
.context("failed to build descriptor")?;
layer_digests.insert(oci_digest, desc);
layer_digests.insert(format!("sha256:{dgst}"), desc);

let mut th = tar::Header::new_gnu();
th.set_mode(0o444);
Expand Down Expand Up @@ -185,8 +184,8 @@ impl<C: OciConfig> Builder<C> {

let desc = DescriptorBuilder::default()
.media_type(config.2.clone())
.size(b.len() as i64)
.digest("sha256:".to_owned() + &dgst)
.size(b.len() as u64)
.digest(Digest::try_from(format!("sha256:{dgst}"))?)
.build()
.context("failed to build descriptor")?;

Expand Down Expand Up @@ -245,10 +244,10 @@ impl<C: OciConfig> Builder<C> {

let desc = DescriptorBuilder::default()
.media_type(MediaType::ImageManifest)
.size(b.len() as i64)
.size(b.len() as u64)
.platform(platform)
.annotations(annotations)
.digest("sha256:".to_owned() + &dgst)
.digest(Digest::try_from(format!("sha256:{dgst}"))?)
.build()
.context("failed to build descriptor")?;

Expand Down

0 comments on commit a09ad04

Please sign in to comment.