From 228e42a7793c770c3a6b8960a05b32a0bcacc68f Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Thu, 18 Jan 2024 00:21:03 -0800 Subject: [PATCH] hypha: include squashfs version in image cache key --- hypha/src/image/mod.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hypha/src/image/mod.rs b/hypha/src/image/mod.rs index 73ef13b..74ea9a1 100644 --- a/hypha/src/image/mod.rs +++ b/hypha/src/image/mod.rs @@ -16,6 +16,8 @@ use std::path::PathBuf; use uuid::Uuid; use walkdir::WalkDir; +pub const IMAGE_SQUASHFS_VERSION: u64 = 1; + pub struct ImageInfo { pub squashfs: PathBuf, pub manifest: ImageManifest, @@ -75,8 +77,13 @@ impl ImageCompiler<'_> { let mut client = Client::new(image.registry_url()?, name.clone())?; let manifest = client.get_manifest(reference)?; let manifest_serialized = serde_json::to_string(&manifest)?; - let manifest_digest = sha256::digest(manifest_serialized); - if let Some(cached) = self.cache.recall(&manifest_digest)? { + let cache_key = format!( + "manifest\n{}squashfs-version\n{}\n", + manifest_serialized, IMAGE_SQUASHFS_VERSION + ); + let cache_digest = sha256::digest(cache_key); + + if let Some(cached) = self.cache.recall(&cache_digest)? { return Ok(cached); } @@ -114,7 +121,7 @@ impl ImageCompiler<'_> { ); self.squash(image_dir, squash_file)?; let info = ImageInfo::new(squash_file.clone(), manifest.clone(), config)?; - return self.cache.store(&manifest_digest, &info); + return self.cache.store(&cache_digest, &info); } Err(Error::MissingLayer.into()) }