Skip to content

Commit a4f844d

Browse files
committed
add simple ConfigFile() support for schema1
Signed-off-by: Matthias Bertschy <[email protected]>
1 parent 8dadbe7 commit a4f844d

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

pkg/v1/remote/schema1.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,23 @@ func (s *schema1) ConfigName() (v1.Hash, error) {
7171
}
7272

7373
func (s *schema1) ConfigFile() (*v1.ConfigFile, error) {
74-
return nil, newErrSchema1(s.mediaType)
74+
configFile := &v1.ConfigFile{
75+
RootFS: v1.RootFS{
76+
Type: "layers",
77+
},
78+
}
79+
layers, err := s.Layers()
80+
if err != nil {
81+
return nil, err
82+
}
83+
for _, layer := range layers {
84+
d, err := layer.Digest()
85+
if err != nil {
86+
return nil, err
87+
}
88+
configFile.RootFS.DiffIDs = append(configFile.RootFS.DiffIDs, d)
89+
}
90+
return configFile, nil
7591
}
7692

7793
func (s *schema1) RawConfigFile() ([]byte, error) {

pkg/v1/remote/schema1_test.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,17 @@ func TestSchema1(t *testing.T) {
113113
}
114114
}
115115

116-
mustErr(img.ConfigFile())
116+
config, err := img.ConfigFile()
117+
if err != nil {
118+
t.Fatalf("Error loading config file: %v", err)
119+
}
120+
if got, want := len(config.RootFS.DiffIDs), 3; got != want {
121+
t.Fatalf("num diff ids; got %v, want %v", got, want)
122+
}
123+
if got, want := config.RootFS.Type, "layers"; got != want {
124+
t.Fatalf("rootfs type; got %v, want %v", got, want)
125+
}
126+
117127
mustErr(img.Manifest())
118128
mustErr(img.LayerByDiffID(v1.Hash{}))
119129

0 commit comments

Comments
 (0)