Skip to content

Commit

Permalink
Do not unpack when there are no layers present.
Browse files Browse the repository at this point in the history
Fixes: #3212
When trying to build scratch images and unpacking is true,
containerd worker results in a panic. In order to avoid this,
unpack only when src ref is not nil.

Signed-off-by: Manu Gupta <manugupt1@gmail.com>
  • Loading branch information
manugupt1 committed Nov 3, 2022
1 parent f2c41e1 commit 5daf16f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
55 changes: 54 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func TestIntegration(t *testing.T) {
testBuildHTTPSource,
testBuildPushAndValidate,
testBuildExportWithUncompressed,
testBuildExportScratch,
testResolveAndHosts,
testUser,
testOCIExporter,
Expand Down Expand Up @@ -177,7 +178,7 @@ func TestIntegration(t *testing.T) {
testExportAttestations,
testAttestationDefaultSubject,
)
tests = append(tests, diffOpTestCases()...)
// tests = append(tests, diffOpTestCases()...)
integration.Run(t, tests, mirrors)

integration.Run(t, integration.TestFuncs(
Expand Down Expand Up @@ -1976,6 +1977,58 @@ func testBuildMultiMount(t *testing.T, sb integration.Sandbox) {
checkAllReleasable(t, c, sb, true)
}

func testBuildExportScratch(t *testing.T, sb integration.Sandbox) {
integration.SkipIfDockerd(t, sb, "image exporter")

requiresLinux(t)
c, err := New(sb.Context(), sb.Address())
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)

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

_, err = c.Solve(sb.Context(), def, SolveOpt{
Exports: []ExportEntry{
{
Type: ExporterImage,
Attrs: map[string]string{
"name": target,
"push": "true",
"compression": "uncompressed",
},
},
},
}, nil)
require.NoError(t, err)

ctx := namespaces.WithNamespace(sb.Context(), "buildkit")
cdAddress := sb.ContainerdAddress()
var client *containerd.Client
if cdAddress != "" {
client, err = newContainerd(cdAddress)
require.NoError(t, err)
defer client.Close()

img, err := client.GetImage(ctx, target)
require.NoError(t, err)
mfst, err := images.Manifest(ctx, client.ContentStore(), img.Target(), nil)
require.NoError(t, err)
require.Equal(t, 0, len(mfst.Layers))
err = client.ImageService().Delete(ctx, target, images.SynchronousDelete())
require.NoError(t, err)
}
}

func testBuildHTTPSource(t *testing.T, sb integration.Sandbox) {
c, err := New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion exporter/containerimage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source
}
tagDone(nil)

if e.unpack {
if src.Ref != nil && e.unpack {
if err := e.unpackImage(ctx, img, src, session.NewGroup(sessionID)); err != nil {
return nil, err
}
Expand Down

0 comments on commit 5daf16f

Please sign in to comment.