-
Notifications
You must be signed in to change notification settings - Fork 0
Add the platform to the image layer cache #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
07df7f4
4dda4f1
fa3424e
ac53fa3
2ca7687
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,13 +173,13 @@ jobs: | |
| - name: Build | ||
| env: | ||
| GIT_SHA: ${{ github.sha }} | ||
| # FIXME: Currently pushes to ghcr.io for caching. Needs to be conditional | ||
| run: | | ||
| bakery build --load \ | ||
| --image-name '^${{ matrix.img.image }}$' \ | ||
| --image-version ${{ matrix.img.version }} \ | ||
| --dev-versions ${{ inputs.dev-versions }} \ | ||
| --cache-registry "ghcr.io/${{ github.repository_owner }}" \ | ||
| ${{ inputs.push && '--push-cache' || '' }} \ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I implemented this as part of the initial build step. We could easily move the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be fine where it is. Test failures are something I would consider being independent of the validity of the build cache. The cache, at least as I understand, should not push on a failed build anyways. |
||
| --context ${{ inputs.context }} | ||
|
|
||
| - name: Test | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,12 +90,19 @@ def serialize_path(value: Path | str) -> str: | |
| return str(value) | ||
|
|
||
| @classmethod | ||
| def from_image_target(cls, image_target: ImageTarget) -> "BakeTarget": | ||
| def from_image_target(cls, image_target: ImageTarget, push_cache: bool = False) -> "BakeTarget": | ||
| """Create a BakeTarget from an ImageTarget.""" | ||
| kwargs = {"tags": image_target.tags} | ||
| platforms = image_target.image_os.platforms if image_target.image_os is not None else DEFAULT_PLATFORMS | ||
|
|
||
| if image_target.cache_name is not None: | ||
| kwargs["cache_from"] = [{"type": "registry", "ref": image_target.cache_name}] | ||
| kwargs["cache_to"] = [{"type": "registry", "ref": image_target.cache_name, "mode": "max"}] | ||
| cache_name = image_target.cache_name | ||
| # Append platform suffix to cache name | ||
| platform_suffix = "-".join(p.removeprefix("linux/").replace("/", "-") for p in platforms) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can generate a suffix like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... I don't think this will cover us properly. One possible method I can think of is to move setting the |
||
| cache_name = f"{cache_name}-{platform_suffix}" | ||
| kwargs["cache_from"] = [{"type": "registry", "ref": cache_name}] | ||
| if push_cache: | ||
| kwargs["cache_to"] = [{"type": "registry", "ref": cache_name, "mode": "max"}] | ||
|
|
||
| if image_target.temp_name is not None: | ||
| kwargs["tags"] = [image_target.temp_name.rsplit(":", 1)[0]] | ||
|
|
@@ -107,7 +114,7 @@ def from_image_target(cls, image_target: ImageTarget) -> "BakeTarget": | |
| image_os=image_target.image_os.name if image_target.image_os else None, | ||
| dockerfile=image_target.containerfile, | ||
| labels=image_target.labels, | ||
| platforms=image_target.image_os.platforms if image_target.image_os is not None else DEFAULT_PLATFORMS, | ||
| platforms=platforms, | ||
| **kwargs, | ||
| ) | ||
|
|
||
|
|
@@ -151,11 +158,14 @@ def update_groups( | |
| return groups | ||
|
|
||
| @classmethod | ||
| def from_image_targets(cls, context: Path, image_targets: list[ImageTarget]) -> "BakePlan": | ||
| def from_image_targets( | ||
| cls, context: Path, image_targets: list[ImageTarget], push_cache: bool = False | ||
| ) -> "BakePlan": | ||
| """Create a BakePlan from a list of ImageTarget objects. | ||
|
|
||
| :param context: The absolute path to the build context directory. | ||
| :param image_targets: A list of ImageTarget objects to include in the bake plan. | ||
| :param push_cache: Whether to push build cache to the cache registry. | ||
|
|
||
| :return: A BakePlan object containing the context, groups, and targets. | ||
| """ | ||
|
|
@@ -165,7 +175,7 @@ def from_image_targets(cls, context: Path, image_targets: list[ImageTarget]) -> | |
| targets: dict[str, BakeTarget] = {} | ||
|
|
||
| for image_target in image_targets: | ||
| bake_target = BakeTarget.from_image_target(image_target=image_target) | ||
| bake_target = BakeTarget.from_image_target(image_target=image_target, push_cache=push_cache) | ||
| groups = cls.update_groups( | ||
| groups=groups, | ||
| uid=image_target.uid, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure what this variable is used for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it was something I tried before
steps.normalize-platform.outputs.platformand it wasn't removed.