Skip to content

Commit

Permalink
Add custom platform matcher for testing purposes
Browse files Browse the repository at this point in the history
This is a hack so that we can test out fetching a specific OS version
variant of an image.
Since the platforms package only does OSVersion comparison on for
"windows" we just create our own dumby OS where we can do some basic
tests.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Jan 13, 2025
1 parent 3713196 commit 3214d21
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9439,12 +9439,12 @@ func testPlatformWithOSVersion(t *testing.T, sb integration.Sandbox) {

f := getFrontend(t, sb)
p1 := ocispecs.Platform{
OS: "foo",
OS: "internalbuildkitintegration",
OSVersion: "1.2.3",
Architecture: "bar",
}
p2 := ocispecs.Platform{
OS: "foo",
OS: "internalbuildkitintegration",
OSVersion: "1.1.0",
Architecture: "bar",
}
Expand Down
23 changes: 23 additions & 0 deletions util/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,36 @@ func (p *Puller) tryLocalResolve(ctx context.Context) error {
return nil
}

type simpleVersionMatcher struct {
platforms.MatchComparer
OSVersion string
}

func (m simpleVersionMatcher) Match(p ocispecs.Platform) bool {
if !m.MatchComparer.Match(p) {
return false
}
if m.OSVersion == "" || p.OSVersion == "" {
return true
}
return m.OSVersion == p.OSVersion
}

func (p *Puller) PullManifests(ctx context.Context, getResolver SessionResolver) (*PulledManifests, error) {
err := p.resolve(ctx, p.Resolver)
if err != nil {
return nil, err
}

platform := platforms.Only(p.Platform)
if p.Platform.OS == "internalbuildkitintegration" {
// NOTE: HACK: This is a special case for testing purposes.
// It is used to test that we can pull images based on a specific OS version.
//
// The default platform, currently, matcher ignores OS version unless p.OS is set to windows.
// Hence the need for a custom platform matcher which will include OS version.
platform = simpleVersionMatcher{OSVersion: p.Platform.OSVersion, MatchComparer: platform}
}

var mu sync.Mutex // images.Dispatch calls handlers in parallel
metadata := make(map[digest.Digest]ocispecs.Descriptor)
Expand Down

0 comments on commit 3214d21

Please sign in to comment.