Skip to content

Commit

Permalink
Revert "Empty config (#262)"
Browse files Browse the repository at this point in the history
This reverts commit 069da31.
  • Loading branch information
Wwwsylvia authored Sep 5, 2022
1 parent 6d3ce22 commit f7eb445
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ func Pack(ctx context.Context, pusher content.Pusher, layers []ocispec.Descripto
if opts.ConfigDescriptor != nil {
configDesc = *opts.ConfigDescriptor
} else {
configBytes := []byte("{}")
configDesc = ocispec.Descriptor{
MediaType: opts.ConfigMediaType,
Digest: digest.FromBytes(nil),
Size: 0,
Digest: digest.FromBytes(configBytes),
Size: int64(len(configBytes)),
Annotations: opts.ConfigAnnotations,
}

// push config
if err := pusher.Push(ctx, configDesc, bytes.NewReader(nil)); err != nil && !errors.Is(err, errdef.ErrAlreadyExists) {
if err := pusher.Push(ctx, configDesc, bytes.NewReader(configBytes)); err != nil && !errors.Is(err, errdef.ErrAlreadyExists) {
return ocispec.Descriptor{}, fmt.Errorf("failed to push config: %w", err)
}
}
Expand Down
10 changes: 6 additions & 4 deletions pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ func Test_Pack_Default(t *testing.T) {
t.Fatal("Oras.Pack() error =", err)
}

expectedConfigBytes := []byte("{}")
expectedManifest := ocispec.Manifest{
Versioned: specs.Versioned{
SchemaVersion: 2, // historical value. does not pertain to OCI or docker version
},
MediaType: ocispec.MediaTypeImageManifest,
Config: ocispec.Descriptor{
MediaType: MediaTypeUnknownConfig,
Digest: "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
Size: 0,
Digest: digest.FromBytes(expectedConfigBytes),
Size: int64(len(expectedConfigBytes)),
},
Layers: layers,
}
Expand Down Expand Up @@ -181,15 +182,16 @@ func Test_Pack_NoLayer(t *testing.T) {
t.Fatal("Oras.Pack() error =", err)
}

expectedConfigBytes := []byte("{}")
expectedManifest := ocispec.Manifest{
Versioned: specs.Versioned{
SchemaVersion: 2, // historical value. does not pertain to OCI or docker version
},
MediaType: ocispec.MediaTypeImageManifest,
Config: ocispec.Descriptor{
MediaType: MediaTypeUnknownConfig,
Digest: "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
Size: 0,
Digest: digest.FromBytes(expectedConfigBytes),
Size: int64(len(expectedConfigBytes)),
},
Layers: []ocispec.Descriptor{},
}
Expand Down

0 comments on commit f7eb445

Please sign in to comment.