Skip to content

Commit

Permalink
Revert "Always produce OCI images and indexes (#449)" (#462)
Browse files Browse the repository at this point in the history
This reverts commit 465eca2.

This breaks pushing to quay.io.
  • Loading branch information
imjasonh committed Oct 6, 2021
1 parent 465eca2 commit 42723d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 41 deletions.
27 changes: 15 additions & 12 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,6 @@ func (g *gobuild) configForImportPath(ip string) Config {
func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, platform *v1.Platform) (v1.Image, error) {
ref := newRef(refStr)

// Always produce OCI images, even if the base image isn't an OCI image.
base = mutate.MediaType(base, types.OCIManifestSchema1)

cf, err := base.ConfigFile()
if err != nil {
return nil, err
Expand Down Expand Up @@ -880,15 +877,16 @@ func (g *gobuild) Build(ctx context.Context, s string) (Result, error) {
}

// Annotate the image or index with base image information.
// If the result is an Index, it should be an OCI index that supports
// annotations.
anns := map[string]string{
specsv1.AnnotationBaseImageDigest: baseDigest.String(),
}
if _, ok := baseRef.(name.Tag); ok {
anns[specsv1.AnnotationBaseImageName] = baseRef.Name()
// (Docker manifest lists don't support annotations)
if mt != types.DockerManifestList {
anns := map[string]string{
specsv1.AnnotationBaseImageDigest: baseDigest.String(),
}
if _, ok := baseRef.(name.Tag); ok {
anns[specsv1.AnnotationBaseImageName] = baseRef.Name()
}
res = mutate.Annotations(res, anns).(Result)
}
res = mutate.Annotations(res, anns).(Result)

return res, nil
}
Expand Down Expand Up @@ -924,13 +922,18 @@ func (g *gobuild) buildAll(ctx context.Context, ref string, baseIndex v1.ImageIn
Add: img,
Descriptor: v1.Descriptor{
URLs: desc.URLs,
MediaType: desc.MediaType,
Annotations: desc.Annotations,
Platform: desc.Platform,
},
})
}

idx := mutate.IndexMediaType(mutate.AppendManifests(empty.Index, adds...), types.OCIImageIndex)
baseType, err := baseIndex.MediaType()
if err != nil {
return nil, err
}
idx := mutate.IndexMediaType(mutate.AppendManifests(empty.Index, adds...), baseType)

return idx, nil
}
Expand Down
29 changes: 0 additions & 29 deletions pkg/build/gobuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/google/go-containerregistry/pkg/v1/empty"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/random"
"github.com/google/go-containerregistry/pkg/v1/types"
specsv1 "github.com/opencontainers/image-spec/specs-go/v1"
)

Expand Down Expand Up @@ -421,17 +420,6 @@ func TestGoBuildNoKoData(t *testing.T) {
t.Errorf("created = %v, want %v", actual, creationTime)
}
})

t.Run("check OCI media type", func(t *testing.T) {
mt, err := img.MediaType()
if err != nil {
t.Errorf("MediaType() = %v", err)
}

if got, want := mt, types.OCIManifestSchema1; got != want {
t.Errorf("mediaType = %v, want %v", got, want)
}
})
}

func validateImage(t *testing.T, img v1.Image, baseLayers int64, creationTime v1.Time, checkAnnotations bool) {
Expand Down Expand Up @@ -743,23 +731,6 @@ func TestGoBuildIndex(t *testing.T) {
t.Errorf("Digest mismatch: %s != %s", d1, d2)
}
})

t.Run("check OCI media type", func(t *testing.T) {
mt, err := idx.MediaType()
if err != nil {
t.Fatalf("MediaType() = %v", err)
}

if got, want := mt, types.OCIImageIndex; got != want {
t.Errorf("mediaType = %v, want %v", got, want)
}

for i, mf := range im.Manifests {
if got, want := mf.MediaType, types.OCIManifestSchema1; got != want {
t.Errorf("manifest[%d] mediaType = %s, want %s", i, got, want)
}
}
})
}

func TestNestedIndex(t *testing.T) {
Expand Down

0 comments on commit 42723d7

Please sign in to comment.