Skip to content

Commit

Permalink
export manifest from tar file (#1046)
Browse files Browse the repository at this point in the history
Signed-off-by: 刘畅 <basefly@outlook.com>
  • Loading branch information
hhstu committed Jun 11, 2021
1 parent 5455b5b commit 764823a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/v1/tarball/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ func ImageFromPath(path string, tag *name.Tag) (v1.Image, error) {
return Image(pathOpener(path), tag)
}

// LoadManifest load manifest
func LoadManifest(opener Opener) (Manifest, error) {
m, err := extractFileFromTar(opener, "manifest.json")
if err != nil {
return nil, err
}
defer m.Close()

var manifest Manifest

if err := json.NewDecoder(m).Decode(&manifest); err != nil {
return nil, err
}
return manifest, nil
}

// Image exposes an image from the tarball at the provided path.
func Image(opener Opener, tag *name.Tag) (v1.Image, error) {
img := &image{
Expand Down
11 changes: 11 additions & 0 deletions pkg/v1/tarball/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,14 @@ func TestLayerLink(t *testing.T) {
t.Errorf("layer.Uncompressed() returned a link file")
}
}

func TestLoadManifest(t *testing.T) {

manifest, err := LoadManifest(pathOpener("testdata/test_load_manifest.tar"))
if err != nil {
t.Fatalf("Error load manifest: %v", err)
}
if len(manifest) == 0 {
t.Fatalf("get nothing")
}
}
Binary file added pkg/v1/tarball/testdata/test_load_manifest.tar
Binary file not shown.

0 comments on commit 764823a

Please sign in to comment.