Skip to content

feat: image-optimize#517

Draft
Harshal96 wants to merge 1 commit into
bazel-contrib:mainfrom
Harshal96:feat/image-optimize
Draft

feat: image-optimize#517
Harshal96 wants to merge 1 commit into
bazel-contrib:mainfrom
Harshal96:feat/image-optimize

Conversation

@Harshal96
Copy link
Copy Markdown
Contributor

Summary

Adds an explicit image_optimize rule for image-wide layer optimization.

This lets users rewrite every available layer in an image_manifest or image_index, including eagerly materialized base-image layers, and enables whole-image eStargz output without changing the default shallow-pull behavior.

Why

Issue #421 asks about applying eStargz at the image/base-image level. Instead of making image_manifest or image_index implicitly download and rewrite base layers, this adds a separate opt-in rule. That keeps shallow pulls cheap by default while giving users a clear path when they intentionally want all layers optimized.

Changes

  • Adds image_optimize to @rules_img//img:image.bzl
  • Supports both single-platform manifests and multi-platform indexes
  • Recompresses every available layer using selected compression settings
  • Supports estargz = "enabled" for whole-image eStargz conversion
  • Fails clearly if any input layer blob is unavailable or shallow
  • Preserves source image manifest/config/index metadata while replacing layer descriptors and config rootfs.diff_ids
  • Preserves existing layer annotations during recompression, while replacing stale eStargz-generated annotations
  • Regenerates docs/image.md
  • Adds toolchain and e2e coverage

Test Plan

  • bazel test @rules_img_tool//cmd/img:test
  • bazel test //tests/img_toolchain:img_toolchain_test
  • bazel test //util:buildifier.check
  • cd e2e/generic && bazel test //:optimize_tests

@malt3
Copy link
Copy Markdown
Collaborator

malt3 commented May 15, 2026

This looks very promising at first glance. I'll need some more time for an in-depth review. Thank you for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants