llb: ensure meta resolver uses platform form constraints

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.9
Tonis Tiigi 2021-06-22 21:49:07 -07:00
parent e0124e192c
commit 01b50a3df1
2 changed files with 21 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"testing"
"github.com/containerd/containerd/platforms"
"github.com/moby/buildkit/solver/pb"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
@ -21,10 +22,11 @@ func TestImageMetaResolver(t *testing.T) {
require.Equal(t, false, tr.called)
def, err := st.Marshal(context.TODO())
def, err := st.Marshal(context.TODO(), LinuxPpc64le)
require.NoError(t, err)
require.Equal(t, true, tr.called)
require.Equal(t, "linux/ppc64le", tr.platform)
m, arr := parseDef(t, def.Def)
require.Equal(t, 2, len(arr))
@ -69,6 +71,7 @@ type testResolver struct {
digest digest.Digest
dir string
called bool
platform string
}
func (r *testResolver) ResolveImageConfig(ctx context.Context, ref string, opt ResolveImageConfigOpt) (digest.Digest, []byte, error) {
@ -83,6 +86,10 @@ func (r *testResolver) ResolveImageConfig(ctx context.Context, ref string, opt R
img.Config.WorkingDir = r.dir
if opt.Platform != nil {
r.platform = platforms.Format(*opt.Platform)
}
dt, err := json.Marshal(img)
if err != nil {
return "", nil, errors.WithStack(err)

View File

@ -122,8 +122,12 @@ func Image(ref string, opts ...ImageOption) State {
} else if info.metaResolver != nil {
if _, ok := r.(reference.Digested); ok || !info.resolveDigest {
return NewState(src.Output()).Async(func(ctx context.Context, st State, c *Constraints) (State, error) {
p := info.Constraints.Platform
if p == nil {
p = c.Platform
}
_, dt, err := info.metaResolver.ResolveImageConfig(ctx, ref, ResolveImageConfigOpt{
Platform: info.Constraints.Platform,
Platform: p,
ResolveMode: info.resolveMode.String(),
})
if err != nil {
@ -133,8 +137,12 @@ func Image(ref string, opts ...ImageOption) State {
})
}
return Scratch().Async(func(ctx context.Context, _ State, c *Constraints) (State, error) {
p := info.Constraints.Platform
if p == nil {
p = c.Platform
}
dgst, dt, err := info.metaResolver.ResolveImageConfig(context.TODO(), ref, ResolveImageConfigOpt{
Platform: info.Constraints.Platform,
Platform: p,
ResolveMode: info.resolveMode.String(),
})
if err != nil {