Skip to content

Commit

Permalink
test: add test case for multi-platform scratch
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Chadwell <[email protected]>
  • Loading branch information
jedevc committed Jan 5, 2024
1 parent 7c0f37b commit 84c8662
Showing 1 changed file with 75 additions and 6 deletions.
81 changes: 75 additions & 6 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2266,19 +2266,61 @@ func testBuildExportScratch(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)
defer c.Close()

st := llb.Scratch()
def, err := st.Marshal(sb.Context())
require.NoError(t, err)

registry, err := sb.NewRegistry()
if errors.Is(err, integration.ErrRequirements) {
t.Skip(err.Error())
}
require.NoError(t, err)

makeFrontend := func(ps []string) func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
return func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
st := llb.Scratch()
def, err := st.Marshal(sb.Context())
require.NoError(t, err)

r, err := c.Solve(ctx, gateway.SolveRequest{
Definition: def.ToPB(),
})
if err != nil {
return nil, err
}

ref, err := r.SingleRef()
if err != nil {
return nil, err
}

res := gateway.NewResult()
if ps == nil {
res.SetRef(ref)
} else {
for _, p := range ps {
res.AddRef(p, ref)
}

expPlatforms := &exptypes.Platforms{
Platforms: make([]exptypes.Platform, len(ps)),
}
for i, p := range ps {
expPlatforms.Platforms[i] = exptypes.Platform{
ID: p,
Platform: platforms.MustParse(p),
}
}
dt, err := json.Marshal(expPlatforms)
if err != nil {
return nil, err
}
res.AddMeta(exptypes.ExporterPlatformsKey, dt)
}

return res, nil
}
}

target := registry + "/buildkit/build/exporter:withnocompressed"

_, err = c.Solve(sb.Context(), def, SolveOpt{
_, err = c.Build(sb.Context(), SolveOpt{
Exports: []ExportEntry{
{
Type: ExporterImage,
Expand All @@ -2290,7 +2332,23 @@ func testBuildExportScratch(t *testing.T, sb integration.Sandbox) {
},
},
},
}, nil)
}, "", makeFrontend(nil), nil)
require.NoError(t, err)

targetMulti := registry + "/buildkit/build/exporter-multi:withnocompressed"
_, err = c.Build(sb.Context(), SolveOpt{
Exports: []ExportEntry{
{
Type: ExporterImage,
Attrs: map[string]string{
"name": targetMulti,
"push": "true",
"unpack": "true",
"compression": "uncompressed",
},
},
},
}, "", makeFrontend([]string{"linux/amd64", "linux/arm64"}), nil)
require.NoError(t, err)

ctx := namespaces.WithNamespace(sb.Context(), "buildkit")
Expand All @@ -2308,6 +2366,17 @@ func testBuildExportScratch(t *testing.T, sb integration.Sandbox) {
require.Equal(t, 0, len(mfst.Layers))
err = client.ImageService().Delete(ctx, target, images.SynchronousDelete())
require.NoError(t, err)

img, err = client.GetImage(ctx, targetMulti)
require.NoError(t, err)
mfst, err = images.Manifest(ctx, client.ContentStore(), img.Target(), platforms.Only(platforms.MustParse("linux/amd64")))
require.NoError(t, err)
require.Equal(t, 0, len(mfst.Layers))
mfst, err = images.Manifest(ctx, client.ContentStore(), img.Target(), platforms.Only(platforms.MustParse("linux/arm64")))
require.NoError(t, err)
require.Equal(t, 0, len(mfst.Layers))
err = client.ImageService().Delete(ctx, targetMulti, images.SynchronousDelete())
require.NoError(t, err)
}
}

Expand Down

0 comments on commit 84c8662

Please sign in to comment.