Skip to content

Commit

Permalink
oci: fix 'cfsctl oci pull'
Browse files Browse the repository at this point in the history
This broke when applied to many popular registries.  It turns out we
shouldn't try to access the config via its descriptor.

Closes #17
  • Loading branch information
allisonkarlitskaya committed Oct 25, 2024
1 parent 0228722 commit 7b141df
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/oci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,17 @@ impl<'repo> ImageOp<'repo> {
} else {
// We need to add the config to the repo. We need to parse the config and make sure we
// have all of the layers first.
let (mut blob_reader, driver) =
self.proxy.get_descriptor(&self.img, descriptor).await?;
let mut raw_config = vec![];
let (a, b) = tokio::join!(blob_reader.read_to_end(&mut raw_config), driver);
a?;
b?;

//
let raw_config = self.proxy.fetch_config_raw(&self.img).await?;
let config = ImageConfiguration::from_reader(raw_config.as_slice())?;

let mut config_maps = DigestMap::new();
for (mld, cld) in zip(manifest_layers, config.rootfs().diff_ids()) {
let layer_sha256 = sha256_from_digest(cld)?;
let layer_id = self.ensure_layer(&layer_sha256, mld).await?;
let layer_id = self
.ensure_layer(&layer_sha256, mld)
.await
.with_context(|| format!("Failed to fetch layer {cld} via {mld:?}"))?;
config_maps.insert(&layer_sha256, &layer_id);
}

Expand All @@ -130,8 +128,6 @@ impl<'repo> ImageOp<'repo> {
}

pub async fn pull(&self) -> Result<(Sha256HashValue, Sha256HashValue)> {
dbg!("ensure_manifest", &self.img);

let (_manifest_digest, raw_manifest) = self
.proxy
.fetch_manifest_raw_oci(&self.img)
Expand All @@ -141,17 +137,23 @@ impl<'repo> ImageOp<'repo> {
// We need to add the manifest to the repo. We need to parse the manifest and make
// sure we have the config first (which will also pull in the layers).
let manifest = ImageManifest::from_reader(raw_manifest.as_slice())?;
dbg!(&manifest);
let config_descriptor = manifest.config();
let layers = manifest.layers();
self.ensure_config(layers, config_descriptor).await
self.ensure_config(layers, config_descriptor)
.await
.with_context(|| format!("Failed to pull config {config_descriptor:?}"))
}
}

/// Pull the target image, and add the provided tag. If this is a mountable
/// image (i.e. not an artifact), it is *not* unpacked by default.
pub async fn pull(repo: &Repository, imgref: &str, reference: Option<&str>) -> Result<()> {
let op = ImageOp::new(repo, imgref).await?;
let (sha256, id) = op.pull().await?;
let (sha256, id) = op
.pull()
.await
.with_context(|| format!("Unable to pull container image {imgref}"))?;

if let Some(name) = reference {
repo.name_stream(sha256, name)?;
Expand Down

0 comments on commit 7b141df

Please sign in to comment.