The DigestTracker struct is used to track and validate the lineage of container image layers. It maintains a sequential record of layer metadata, allowing you to compare current image layers against previously recorded history (typically loaded from an Image.md file).
Key Capabilities
- Sequential Recording: Layers must be added in build order. The
add_layer method enforces that the position argument matches the current number of recorded layers. - History Loading: You can reconstruct a tracker by parsing an existing
Image.md file using load_from_file. - Layer Validation: Use
layer_matches to verify if a specific layer in an extracted image matches a recorded entry in the tracker. A match requires:- Matching
is_empty status. - Matching creation timestamps (normalized to handle
Z or +00:00 formats). - For non-empty layers: Matching
digest. - For empty layers: Matching
command.
- Digest Extraction: Provides utilities to derive
sha256: prefixed digests from layer IDs or tarball file paths.
// Example: Creating a tracker and adding layers sequentially
let mut tracker = DigestTracker::new();
tracker.add_layer(
0, // position must be current length
"sha256:abc123".to_string(), // digest
"FROM alpine".to_string(), // command
"2023-01-01T00:00:00Z".to_string(), // created
false, // is_empty
None, // comment
);