Skip to content

Update to BuildKit 0.12#45966

Merged
thaJeztah merged 11 commits intomoby:masterfrom
neersighted:buildkit_0.12
Sep 22, 2023
Merged

Update to BuildKit 0.12#45966
thaJeztah merged 11 commits intomoby:masterfrom
neersighted:buildkit_0.12

Conversation

@neersighted
Copy link
Member

@neersighted neersighted commented Jul 13, 2023

- What I did
Update containerd (library) to v1.7 and BuildKit to v0.12.

Make changes to the code to adjust to the new dependency versions, and fix some TODOs that were waiting on these updates. Leave some new TODOs as well, mostly related to the builder-next code and having to re-implement some things instead of re-using them from BuildKit.

- How I did it
With help from my IDE, and with assistance from others (@tonistiigi, @crazy-max, @rumpl) where I ran out of skill and/or time.

- How to verify it
CI ✅

- Description for the changelog

  • Update buildkit to v0.12.2.
  • Update containerd to v1.7.6.

- A picture of a cute animal (not mandatory but encouraged)

@neersighted

This comment was marked as outdated.

@thaJeztah

This comment was marked as outdated.

@neersighted

This comment was marked as outdated.

@neersighted

This comment was marked as outdated.

Comment on lines +30 to +31
exporterAttrs[string(exptypes.OptKeyName)] = strings.Join(reposAndTags, ",")
exporterAttrs[string(exptypes.OptKeyUnpack)] = "true"
Copy link
Member

Choose a reason for hiding this comment

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

For these I was wondering if it's possible to do the reverse (cast to ImageExporterOptKey) ? Haven't looked at this code locally though, just through GitHub's ui

Copy link
Member Author

Choose a reason for hiding this comment

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

The type in the protobuf is string; I don't know that we can control the codegen enough to "do the right thing" here, and this is the pattern BK uses. Still, it's really clunky, and if we can invert it I'm totally in favor.

Copy link
Member

Choose a reason for hiding this comment

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

Ah... gotcha.. didn't realise we're dealing with protobuf here. Was mostly hoping "strong(ish) types" to help discoverability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this is just a newtype to ease discoverability, but it doesn't seem to be totally ergonomic even on the BK side due to protobufs:
https://github.com/moby/buildkit/blob/f53c1752113e1f9c0fbcc1d5c8e18a9b13452afc/control/control.go#L334-L342

Copy link
Member Author

Choose a reason for hiding this comment

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

cc @crazy-max @jedevc if this is something we can change

Copy link
Member

@crazy-max crazy-max Jul 20, 2023

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Maybe map<string, google.protobuf.Any> would have work but the contract is already there.

Copy link
Member Author

@neersighted neersighted Jul 20, 2023

Choose a reason for hiding this comment

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

Right, my thought (and specific inexperience) is that maybe we can change the protobuf definition to use the newtype, and existing clients with the old generated code will continue to interoperate as it's just a type alias to string. That breaks the Go API a little; but in theory the protobuf is the stable component and the generated Go code can change (ala containerd v1.7).

Copy link
Member Author

Choose a reason for hiding this comment

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

It turns out this is not possible as we have multiple types for the keys (ExporterOptKey for all exporters, ImageExporterOptKey for the image exporter).

It looks like this is a wart we'll have to live with; in the future when/if we remove Gogo, the SDK will have to change a fair bit anyway; at that point defining some conversion helper (maybe with generics) ought to be better.

@neersighted neersighted force-pushed the buildkit_0.12 branch 2 times, most recently from 1c661c8 to 21288ba Compare July 20, 2023 14:29
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

changes "LGTM"

  • left some nits about imports and "requires" going in the wrong group
  • commit-order and squashing
  • some minor change that could be moved separate

Comment on lines -95 to +107
func (is *Source) resolveRemote(ctx context.Context, ref string, platform *ocispec.Platform, sm *session.Manager, g session.Group) (digest.Digest, []byte, error) {
func (is *Source) resolveRemote(ctx context.Context, ref string, platform *ocispec.Platform, sm *session.Manager, g session.Group) (string, digest.Digest, []byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this commit is needed for the BuildKit update (otherwise it doesn't compile)

Copy link
Member Author

@neersighted neersighted Sep 21, 2023

Choose a reason for hiding this comment

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

I'd rather keep this separate, but it is possible to first stub this (like I did in an earlier version of this PR), and then apply Tonis's implementation on top. That's not my preference, however, as there will have to be non-buildable commits in this PR to keep things reviewable/discrete.

type BuilderHistoryConfig struct {
MaxAge int64 `json:",omitempty"`
MaxEntries int64 `json:",omitempty"`
MaxAge bkconfig.Duration `json:",omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

This change does not affect how the config is interpreted? (i.e. existing config still means the same?) because I think this may be part of config options set through daemon.json 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Existing options should work fine; you can see in moby/buildkit@e06c962 that a custom deserializer is implemented to handle the existing int64 format, but also parse a Go time.Duration string.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yes looks good. I didn't look yet, and was curious if the * times.Second was handled; I've (ahum) seen cases where that part was overlooked, and now the duration going from "seconds" to "nanoseconds" 😂

@thaJeztah
Copy link
Member

@neersighted I did a quick rebase of this one after #46522 was merged;

We should probably still squash some of the commits so that the intermediate commits can compile (we can keep some of the "improvements", such as functions that can now be used from buildkit and/or containerd separate if we want them to be more visible in history).

Copy link
Contributor

Choose a reason for hiding this comment

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

If we get a builder-next executor for Windows, will this file need to be renamed again? What about executor_notimplemented.go, since we're not relying on the GOOS filename tag anymore, and then any future executors only need to update the build-tag to exclude their newly-implemented GOOS from the not-implemented list.

Or am I misunderstanding, and this can never be implemented on non-Linux, e.g., even if we have BuildKit working for Windows.

Copy link
Member Author

Choose a reason for hiding this comment

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

This could be implemented for Windows, based on @gabriel-samfira and your work, as I understand it. We would need to rename the file, but I like it like this for now as _nolinux is a BuildKit-ism that we are symmetric with (when you look at the built-in executor implementations).

When BuildKit changes, I expect we'll rename this/change the build tags to once again be symmetric.

Copy link
Member

Choose a reason for hiding this comment

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

The only consideration could be to name this _unsupported.go (done that in some other cases, to be slightly more generic, and sometimes preventing some renames).

Not a blocker for me though

neersighted and others added 9 commits September 21, 2023 14:18
The current executor is only tested on Linux, so let's be honest about
that. Stubbing this correctly helps avoid incorrectly trying to call
into Linux-only code in e.g. libnetwork.

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
The DeepEqual ignore required in the daemon tests is a bit ugly, but it
works given the new protoc output.

We also have to ignore lints related to schema1 deprecations; these do
not apply as we must continue to support this schema version.

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Introduced in containerd/containerd@dd3eedf

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
The following changes were required:
* integration/build: progressui's signature changed in moby/buildkit@6b8fbed
* builder-next: flightcontrol.Group has become a generic type in moby/buildkit@8ffc03b
* builder-next/executor: add github.com/moby/buildkit/executor/resources types, necessitated by moby/buildkit@6e87e4b
* builder-next: stub util/network/Namespace.Sample(), necessitated by moby/buildkit@963f161

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
Co-authored-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
With BuildKit 0.12, some existing types are now required to be wrapped
by new types:

* containerd's LeaseManager and ContentStore have to be a
  (namespace-aware) BuildKit type since moby/buildkit@f044e0a
* BuildKit's solver.CacheManager is used instead of
  bboltstorage.CacheKeyStorage since moby/buildkit@2b30693
* The MaxAge config field is a bkconfig.Duration since moby/buildkit@e06c962

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
SourcePolicy was accounted for in moby/buildkit@330cf7a

TODO: replace applySourcePolicies with BuildKit's implementation, which
is currently unexported.

Co-authored-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Introduced years ago in moby/buildkit@6644e1b

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Introduced in moby/buildkit@4fc2d7b

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Now that this is a generic, we can define a struct type at the package
level, and remove the casting logic necessary when we had to use
interface{}.

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
This exposes `ACTIONS_RUNTIME_TOKEN` and `ACTIONS_CACHE_URL`, which are
used to skip cache exporter tests, when combined with
moby/buildkit@a8789cb

Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

Skipping digest-related tests is no longer necessary after containerd/containerd@4065831

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
)

type Result[T any] struct {
type Result[T comparable] struct {
Copy link
Member

Choose a reason for hiding this comment

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

# github.com/moby/buildkit/frontend/gateway/client
vendor/github.com/moby/buildkit/frontend/gateway/client/client.go:18:29: Reference does not implement comparable
note: module requires Go 1.20

If we want to keep this change, we should update vendor.mod to go 1.20, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good catch! I should have tested with an older Go compiler.

Copy link
Member

Choose a reason for hiding this comment

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

I guess that's #46069 👀

Copy link
Member

Choose a reason for hiding this comment

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

Oh, nope, that doesn't touch the go line 😅

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yes, I decided not to force go1.21 in that PR (as most of the code definitely would still work on older versions); perhaps we still should? At least setting the go.mod to go1.20 could be reasonable I guess. (with go1.19 being EOL); at least for the master / v25.0-dev branch.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was planning on a follow-up PR (as I have some plans for the go line after Go 1.21), but I think that adding a go 1.20 line to your PR makes some sense 👍

Copy link
Member

Choose a reason for hiding this comment

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

I'll make it a separate commit, as we don't need it for the 24.0 (and other branches)

I guess in that case we might as well make it a separate PR; want to open one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/builder/buildkit Build area/builder Build containerd-integration Issues and PRs related to containerd integration impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/4-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.