Skip to content

Commit

Permalink
Add a test case to exercise the fact that parallel export in different
Browse files Browse the repository at this point in the history
image formats generated different metadata.

Signed-off-by: a-palchikov <[email protected]>
  • Loading branch information
a-palchikov committed Dec 15, 2024
1 parent ef73c2d commit 1799133
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
testTarExporterSymlink,
testMultipleRegistryCacheImportExport,
testMultipleExporters,
testMultipleImageExporters,
testSourceMap,
testSourceMapFromRef,
testLazyImagePush,
Expand Down Expand Up @@ -3108,6 +3109,87 @@ func testMultipleExporters(t *testing.T, sb integration.Sandbox) {
}
}

func testMultipleImageExporters(t *testing.T, sb integration.Sandbox) {
workers.CheckFeatureCompat(t, sb, workers.FeatureOCIExporter)
requiresLinux(t)

c, err := New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

def, err := llb.Scratch().Marshal(context.TODO())
require.NoError(t, err)

destDir := t.TempDir()
ociTar := filepath.Join(destDir, "oci.tar")
ociOut, err := os.Create(ociTar)
require.NoError(t, err)
defer ociOut.Close()

dockerTar := filepath.Join(destDir, "docker.tar")
dockerOut, err := os.Create(dockerTar)
require.NoError(t, err)
defer dockerOut.Close()

exporters := []ExportEntry{
{
Type: ExporterOCI,
Attrs: map[string]string{
"dest": ociTar,
},
Output: fixedWriteCloser(ociOut),
},
{
Type: ExporterDocker,
Attrs: map[string]string{
"dest": dockerTar,
},
Output: fixedWriteCloser(dockerOut),
},
}

ref := identity.NewID()
_, err = c.Solve(sb.Context(), def, SolveOpt{
Ref: ref,
Exports: exporters,
}, nil)
require.NoError(t, err)

require.FileExists(t, filepath.Join(destDir, "oci.tar"))
require.FileExists(t, filepath.Join(destDir, "docker.tar"))

ociConfig := extractImageConfig(t, ociTar)
dockerConfig := extractImageConfig(t, dockerTar)
// Validate that the image configurtion is not empty
require.NotEmpty(t, ociConfig.Architecture, "architecture is missing")
require.NotEmpty(t, dockerConfig.Architecture, "architecture is missing")
}

func extractImageConfig(t *testing.T, path string) ocispecs.Image {
t.Helper()

dt, err := os.ReadFile(path)
require.NoError(t, err)

m, err := testutil.ReadTarToMap(dt, false)
require.NoError(t, err)

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
require.NoError(t, err)
require.NotEmpty(t, index.Manifests, "index is missing platform manifests")

var manifest ocispecs.Manifest
err = json.Unmarshal(m[filepath.Join("blobs", "sha256", index.Manifests[0].Digest.Encoded())].Data, &manifest)
require.NoError(t, err)

var config ocispecs.Image
err = json.Unmarshal(m[filepath.Join("blobs", "sha256", manifest.Config.Digest.Encoded())].Data, &config)
require.NoError(t, err)

return config
}

func testOCIExporter(t *testing.T, sb integration.Sandbox) {
workers.CheckFeatureCompat(t, sb, workers.FeatureOCIExporter)
requiresLinux(t)
Expand Down

0 comments on commit 1799133

Please sign in to comment.