Skip to content

feat: Track and emit per-layer history annotations#454

Closed
rossdylan wants to merge 3 commits into
bazel-contrib:mainfrom
rossdylan:history-support
Closed

feat: Track and emit per-layer history annotations#454
rossdylan wants to merge 3 commits into
bazel-contrib:mainfrom
rossdylan:history-support

Conversation

@rossdylan

Copy link
Copy Markdown

Previously there was some support for tracking history from non-bazel defined layers. This PR expands that to automatically add history from all bazel layer targets.

We write that history out to a new file and then used that in img_tool to add it to the final image spec.

Previously there was some support for tracking history from non-bazel
defined layers. This PR expands that to automatically add history from
layer targets.

We write that history out to a new file and then used that in img_tool
to add it to the final image spec. I'm not sure if this is better or
worse than trying to track the history information in each per-layer
file.
@rossdylan

Copy link
Copy Markdown
Author

For context, I was working with another tool that requires each layer have a valid history entry, which I don't think is required by the OCI spec, but the changes to rules_img seemed small enough that I've just been carrying the patch internally.

I'm not 100% sure if using a separate history file is better than tracking a per-layer history attribute. I'm also not sure if this should be the default behavior since it does embed the bazel target into the metadata.

@malt3

malt3 commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator

That looks good to me, but I'd like to see at least one test for this in tests/img_toolchain/testcases. You can create a new one or extend an existing one. The important thing is to check the digest of the generated config given a history.json.

As an aside: I believe users may wish to control the history message at some point, but that is an additional feature to be added if (and only if) someone actually needs it.

@rossdylan

Copy link
Copy Markdown
Author

@malt3 Thanks for the feedback! I've updated one of the manifest test cases to use the new flag, and changed the hashes to match the new expected output.

@malt3 malt3 added this pull request to the merge queue Apr 15, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 15, 2026
@malt3

malt3 commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

During the merge queue, one of the integration tests failed with:

{"errorDetail":{"message":"too many non-empty layers in History section"},"error":"too many non-empty layers in History section"}

something is not up do dockers standards I think.

https://github.com/bazel-contrib/rules_img/actions/runs/24441866086/job/71408550535

probably hitting this: https://github.com/moby/moby/blob/f4825907aeb98d634ab238234ee3abfb77449b07/daemon/images/image_history.go#L36

@malt3

malt3 commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

I think we need to track the history from base images specially. Right now we add the history from pulled images twice:

  • once from the structured config
  • once via an append of the list of layers

@malt3

malt3 commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Maybe it would be better if we tracked history as part of each layer.
In the image_import rule, we take the history of the base image and split it into the layers on a best effort basis:

metadata = dict(
(add history to this dict).
In the image_layer rule, we emit the history for the current layer. This also opens up the path to customize the history in the future.

The history belongs into the "metadata" file of the LayerInfo provider.

@malt3 malt3 self-requested a review April 16, 2026 10:21
@rossdylan

Copy link
Copy Markdown
Author

hm yeah, let me go back to the drawing board on this and see if I can make docker happy

@rossdylan

Copy link
Copy Markdown
Author

Superseded by #568

@rossdylan rossdylan closed this Jun 19, 2026
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