Update image export to support Docker format

Add manifest.json file which is used by Docker
to import images.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2019-04-01 15:20:46 -07:00
parent f2a20ead83
commit 4754d2aeee
9 changed files with 643 additions and 354 deletions

View File

@@ -17,6 +17,7 @@
package containerd
import (
"bytes"
"context"
"encoding/json"
"io"
@@ -35,9 +36,9 @@ import (
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// TestOCIExportAndImport exports testImage as a tar stream,
// TestExportAndImport exports testImage as a tar stream,
// and import the tar stream as a new image.
func TestOCIExportAndImport(t *testing.T) {
func TestExportAndImport(t *testing.T) {
// TODO: support windows
if testing.Short() || runtime.GOOS == "windows" {
t.Skip()
@@ -51,12 +52,13 @@ func TestOCIExportAndImport(t *testing.T) {
}
defer client.Close()
pulled, err := client.Fetch(ctx, testImage)
_, err = client.Fetch(ctx, testImage)
if err != nil {
t.Fatal(err)
}
exported, err := client.Export(ctx, pulled.Target)
wb := bytes.NewBuffer(nil)
err = client.Export(ctx, wb, archive.WithAllPlatforms(), archive.WithImage(client.ImageService(), testImage))
if err != nil {
t.Fatal(err)
}
@@ -64,12 +66,15 @@ func TestOCIExportAndImport(t *testing.T) {
opts := []ImportOpt{
WithImageRefTranslator(archive.AddRefPrefix("foo/bar")),
}
imgrecs, err := client.Import(ctx, exported, opts...)
imgrecs, err := client.Import(ctx, bytes.NewReader(wb.Bytes()), opts...)
if err != nil {
t.Fatalf("Import failed: %+v", err)
}
for _, imgrec := range imgrecs {
if imgrec.Name == testImage {
continue
}
err = client.ImageService().Delete(ctx, imgrec.Name)
if err != nil {
t.Fatal(err)