Skip to content

Update uses of Image platform fields in OCI image-spec#3104

Merged
tonistiigi merged 1 commit intomoby:masterfrom
thaJeztah:image_spec_no_literal
Apr 29, 2023
Merged

Update uses of Image platform fields in OCI image-spec#3104
tonistiigi merged 1 commit intomoby:masterfrom
thaJeztah:image_spec_no_literal

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah commented Sep 10, 2022

The OCI image spec is considering to change the Image struct and embedding the
Platform type (see opencontainers/image-spec#959) in the go implementation.
BuildKit currently uses some struct-literals to propagate the platform fields,
which will break once those changes in the OCI spec are merged.

Ideally (once that change arrives) we would update the code to set the Platform
information as a whole, instead of assigning related fields individually, but
in some cases in the code, image platform information is only partially set
(for example, OSVersion and OSFeatures are not preserved in all cases). This
may be on purpose, so needs to be reviewed.

This patch keeps the current behavior (assigning only specific fields), but
removes the use of struct-literals to make the code compatible with the
upcoming changes in the image-spec module.

NOTE:

I added cherry-pick labels for this, to prevent issues for projects that depend both on BuildKit and other projects that may be using the image-spec, which (through go modules) may force them to update the image-spec version to a version with the linked patch.

Comment on lines +554 to +536
img := ocispecs.Image{}
img.Architecture = pl.Architecture
img.OS = pl.OS
img.Variant = pl.Variant
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is where I noticed that in some cases we're discarding the OSVersion and OSFeatures fields (there may be other locations where we do this). Perhaps this is intentional, but we should probably review the code to see if we unintentionally discard those fields, and update the code where needed.

@thaJeztah
Copy link
Copy Markdown
Member Author

Hm... now alpine having issues?

 > [build 1/2] RUN apk add --no-cache file:
#0 0.073 fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
#13 5.082 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.16/main: temporary error (try again later)
#13 5.082 fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
#13 5.381 ERROR: unable to select packages:
#13 5.410   file (no such package):
#13 5.410     required by: world[file]

@tonistiigi
Copy link
Copy Markdown
Member

I don't think we would need to make such predictions and I don't consider the per-field setting cleaner. If it breaks, we will fix it with the vendor update.

@thaJeztah
Copy link
Copy Markdown
Member Author

I agree the struct literal is nicer. The point is that fixing it in BuildKit itself is easy, but I know we have a complicated dependency tree, which means that any other project may go through hell if this needs to be updated, and it may be out of their hands.

I'm trying to prevent that; I think the slightly less pretty (at least temporary) code is worth the trade-off.

@tonistiigi
Copy link
Copy Markdown
Member

tonistiigi commented Sep 20, 2022

The point is that fixing it in BuildKit itself is easy, but I know we have a complicated dependency tree, which means that any other project may go through hell if this needs to be updated, and it may be out of their hands.

I don't understand this. This change here only matters if user is including buildkit and if we fix it in buildkit then user would only change their code. There is no backward compatibility case as well as gomod defines the minimum version requirement.

So if the upstream PR gets merged then just update our gomod to use that change.

@thaJeztah
Copy link
Copy Markdown
Member Author

The issue is that opencontainers/image-spec is (either directly or indirectly) a dependency of many projects (runc, containerd, moby, docker/cli, docker/compose, docker/buildx). Any of those may update their "minimum required version" of the spec at any point, which will force any project that may require a newer version of those (and which also depends on BuildKit) to update. At that point, there won't be a version of BuildKit that's compatible. With the circular dependency of BuildKit on Moby, getting back to a compatible state may take multiple rounds of updating things.
So, I'm trying to have the code prepared for that case, so that we don't have to got through a potential dependency hell.

The OCI image spec is considering to change the Image struct and embedding the
Platform type (see opencontainers/image-spec#959) in the go implementation.
BuildKit currently uses some struct-literals to propagate the platform fields,
which will break once those changes in the OCI spec are merged.

Ideally (once that change arrives) we would update the code to set the Platform
information as a whole, instead of assigning related fields individually, but
in some cases in the code, image platform information is only partially set
(for example, OSVersion and OSFeatures are not preserved in all cases). This
may be on purpose, so needs to be reviewed.

This patch keeps the current behavior (assigning only specific fields), but
removes the use of struct-literals to make the code compatible with the
upcoming changes in the image-spec module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the image_spec_no_literal branch from f51b779 to 09afe32 Compare April 29, 2023 00:18
@thaJeztah
Copy link
Copy Markdown
Member Author

@tonistiigi PTAL; image-spec v1.1.0-rc3 was released, and BuildKit can't build with it now 😢 (see moby/moby#45437)

@tonistiigi tonistiigi merged commit b0c05cd into moby:master Apr 29, 2023
@thaJeztah thaJeztah deleted the image_spec_no_literal branch April 29, 2023 22:41
sir-xw pushed a commit to openkylin/docker.io that referenced this pull request Apr 22, 2025
Origin: moby/buildkit#3104
Applied-Upstream: buildkit v0.11, engine v25


Gbp-Pq: Name engine-buildkit-image-spec-platform.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants