Skip to content

Add build metadata output to file#274

Merged
ianpittwood merged 19 commits intomainfrom
metadata-file-outputs
Dec 17, 2025
Merged

Add build metadata output to file#274
ianpittwood merged 19 commits intomainfrom
metadata-file-outputs

Conversation

@ianpittwood
Copy link
Contributor

@ianpittwood ianpittwood commented Dec 15, 2025

Related to #265

  • Add --metadata-file option to bakery build to write all build metadata to a JSON file.
  • Change global settings implementation to an object.
  • Add model representation of image build metadata.
  • Output individual image target builds to a temporary file with higher-level merge function in BakeryConfig to merge data into a single file output.
  • Add metadata file read for run dgoss.

@github-actions
Copy link

github-actions bot commented Dec 15, 2025

Test Results

818 tests   818 ✅  9m 37s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit d0f51b3.

♻️ This comment has been updated with latest results.

@ianpittwood ianpittwood changed the title Metadata file outputs Add build metadata output to file Dec 16, 2025
@ianpittwood ianpittwood marked this pull request as ready for review December 16, 2025 16:16
Copy link
Contributor

@bschwedler bschwedler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes here make sense to me.
Just a few comments/questions on how merging of the amd/arm images will be performed. I am currently assuing that is a follow-up PR.

target.metadata_file = MetadataFile(target_uid=target.uid, filepath=metadata_filepath)

merged_metadata = config._merge_sequential_build_metadata_files()
with open(CONFIG_TESTDATA_DIR / "build_metadata" / "expected.json", "r") as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we just have amd builds here. Am I correct in assuming that the arm builds will be added in a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The distinction will not matter for this test or for multiplatform support. If a platform build is performed in isolation, it will produce one metadata file with unique targets. If a multiplatform build is performed with emulation, it will still only produce one metadata file with unique targets. The merge functionality only exists because sequential builds produce a metadata file per image target and I think it's easier for us to produce one file with every image target, which is what bake would produce if my PR goes through.

"IMAGE_OS_VERSION=22.04",
"--init",
basic_standard_image_target.tags[0],
basic_standard_image_target.ref,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this. Much more deterministic!

@computed_field
@property
def ref(self) -> str:
"""Returns a reference to the image, preferring a build metadata digest if available."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What scenarios will we not have the build metadata? Is that currently only if using bake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will practically never have build metadata right now. This is pretty much only to support dgoss calls when --metadata-file is passed in. In the future, it would be nice if dgoss and other tool calls could read build metadata that we cached for the application in some way, but that won't be the case for a while.

merged_metadata: dict[str, dict[str, Any]] = {}
for target in self.targets:
if target.metadata_file is not None:
merged_metadata[target.uid] = target.metadata_file.metadata.model_dump(exclude_none=True, by_alias=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we are just accumulating these by id.

Will the platform merge be performed with the bakery ci merge command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bakery ci merge will be the only command where we expect multiple builds of the same image target. My original implementation of it was largely logic outside of the rest of the modeling and I expect it to stay that way.

@ianpittwood ianpittwood force-pushed the typer-usage-improvements branch 3 times, most recently from 8cc18e7 to 35e2423 Compare December 17, 2025 19:41
@ianpittwood ianpittwood force-pushed the metadata-file-outputs branch from a32b953 to e22f9bb Compare December 17, 2025 19:59
@ianpittwood ianpittwood force-pushed the typer-usage-improvements branch from 35e2423 to 727679e Compare December 17, 2025 20:21
Base automatically changed from typer-usage-improvements to main December 17, 2025 20:48
@ianpittwood ianpittwood force-pushed the metadata-file-outputs branch from e22f9bb to d0f51b3 Compare December 17, 2025 21:18
@ianpittwood ianpittwood merged commit b8f9046 into main Dec 17, 2025
7 checks passed
@ianpittwood ianpittwood deleted the metadata-file-outputs branch December 17, 2025 21:37
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