Skip to content

Translate TOML Schema to Images#86

Merged
bschwedler merged 38 commits intomainfrom
toml-schema-translation
Jan 31, 2025
Merged

Translate TOML Schema to Images#86
bschwedler merged 38 commits intomainfrom
toml-schema-translation

Conversation

@bschwedler
Copy link
Contributor

  • Use files to store jinja2 templates
  • Refactor project.py into models/project subdirectory
  • Add basic Image model and matrix tests
  • Add load method for ImageVariant
  • Add labels and tags to the ImageVariant model
  • Add new load method for reading manifest/config
  • WIP: Move to using new Config.load method
  • Move hard-coded manifest fixtures to separate file
  • Add BakePlan object and initial basic test cases
  • WIP: Move project tests to new Manifest/Config/Image objects
  • Render the bake plan using the BakePlan class
  • Use model_dump_json to convert BakePlan to json
  • Set all BaseModels to frozen=True after initialized
  • Get basic manifest tests working
  • Remove older _load method and swich to the Pydantic way
  • Skip goss command tests until the are refactored
  • Create Images class, used to reference and filter images
  • Move creating goss commands to updated Manifest objects
  • Create ImageMetadata class for intermediate data
  • Patch is_file and is_dir at the test file level
  • Move full tag and label generation to ImageVariant
  • Remove remaining old tests

Instead of defining the templates as a multi-line string, we instead
move the templates to files. The templating module reads these files
into the same variable names as before.
These tests check that the number of image versions and variants are
what we would expect by combining imave verions, build oses, and targets
This change also adds the functionality to search for the Containerfile
based on the OS and target.
This sets image labels at various levels throughout the parent Image and
ImageVersion classes.

We intend that these labels will be assembled in the bake plan, and the
image tag prefixes will prefixed there.

Tags are set at the ImageVariant level since tags will be specific to the
OS and target.
Rename the current load method to `_load`

This allows us to iteratively move test cases over to the new load
method while allowing the current tests to continue to pass
This also moves the filtering of images into bake.py
We still need to move the TargetBuild tests to the appropriate test
section, removing duplicates
This was required since we need to be able to filter the images in
multiple ways, in different parts of the code.

The Images class is a dictionary with a couple of extra methods
This is used so that we can pass fewer values around when constructing
the Image and ImageVariant objects.
Prior to this change, each test that required us to patch either
- pathlib.Path.is_file
- pathlib.Path.is_dir
would require context handlers around each call.

We switch to a file-based fixture which is auto-used
This functionality was originally included in the BakePlan.create
method, but we also need it to render the goss information.
@bschwedler bschwedler added the enhancement New feature or request label Jan 27, 2025
@github-actions
Copy link

github-actions bot commented Jan 27, 2025

Test Results

137 tests   134 ✅  47s ⏱️
  1 suites    3 💤
  1 files      0 ❌

Results for commit 17f89aa.

♻️ This comment has been updated with latest results.

@bschwedler bschwedler force-pushed the toml-schema-translation branch from 5e77d0b to 9ce30b9 Compare January 27, 2025 22:14
Copy link
Contributor

@ianpittwood ianpittwood left a comment

Choose a reason for hiding this comment

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

This first pass was mostly trying out commands and making sure things worked. I got everything to work except the render command. In this draft PR I made it works for re-rendering existing versions, but truncates the OS for some reason. It does not work for me on new versions. Everything was tested against the PPM PR to get things updated with no additional changes.

Let's fix up the top-level commands fully and I'll continue additional review for stuff I've missed.

Comment on lines +35 to +36
document = cls.read(filepath)
model = ManifestDocument(**document.unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

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

This part is confusing to me at the moment. Why are we keeping two copies of the same data? Which one should be modified? What's the dump strategy for writing back changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to achieve 2 things:

  1. Store the raw TOMLDocument object, since that includes more information like comments
  2. Store the validated data as a pydantic model, which won't change after being read.

As far as writing out changes, I think that it will probably start with a pydantic model, then get pulled back into the TOMLDocument to write.

Copy link
Contributor

@ianpittwood ianpittwood left a comment

Choose a reason for hiding this comment

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

Round 2

Copy link
Contributor Author

@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.

Thanks for the review. I'm going thorugh and implementing the easy fixes, then I'll move over to the new methods, hopefully adding some functional tests along the way.

Comment on lines +35 to +36
document = cls.read(filepath)
model = ManifestDocument(**document.unwrap())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to achieve 2 things:

  1. Store the raw TOMLDocument object, since that includes more information like comments
  2. Store the validated data as a pydantic model, which won't change after being read.

As far as writing out changes, I think that it will probably start with a pydantic model, then get pulled back into the TOMLDocument to write.

Add --cov-report=term-missing to `just test`

The GitHub Actions workflow uses poetry directly and does not invoke the
justfile.
This allows us to load common files for all tests, enabling re-use of
common step definitions.
This also adds the git commit to the revision label in the bake plan

We still need to address the creation of new projects, images, and
versions
This refactor was done so that we could more easily scope the .new()
method to create a project, image, or version to each file.
Default image templates are created in the templating module
This will prevent unintentional changes to the list of OSes as they are
used elsewhere.
The implements the following changes
- Small format changes to CLI output
- Move the template rendering into the templating module
- Search for BuildOS by pretty or condensed name

We still need to implement updating the manifest file for new versions
@bschwedler bschwedler force-pushed the toml-schema-translation branch 9 times, most recently from 696d391 to 2e6c75e Compare January 31, 2025 18:43
- Add a `slow` pytest marker and skip by default in justfile
- Add a reset() method to BakeryCommand to allow us to invoke the
  command multiple times using the same test fixtures
- Install goss and dgoss for GitHub Actions
@bschwedler bschwedler force-pushed the toml-schema-translation branch from 2e6c75e to e494b29 Compare January 31, 2025 18:49
@bschwedler bschwedler linked an issue Jan 31, 2025 that may be closed by this pull request
@bschwedler bschwedler merged commit bf43e11 into main Jan 31, 2025
3 checks passed
@bschwedler bschwedler deleted the toml-schema-translation branch January 31, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce TOML document schema using pydantic

2 participants