Skip to content

Commit

Permalink
fix: mismatched mediaType error when push image build with warmed bas…
Browse files Browse the repository at this point in the history
…e image(OCI format) cache to registry
  • Loading branch information
luxurine committed Jul 2, 2024
1 parent d6aab15 commit 39165ac
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/layout"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/google/go-containerregistry/pkg/v1/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -228,11 +229,6 @@ func mfstFromPath(p string) (*v1.Manifest, error) {
}

func cachedImageFromPath(p string) (v1.Image, error) {
imgTar, err := tarball.ImageFromPath(p, nil)
if err != nil {
return nil, errors.Wrap(err, "getting image from path")
}

// Manifests may be present next to the tar, named with a ".json" suffix
mfstPath := p + ".json"

Expand All @@ -248,9 +244,28 @@ func cachedImageFromPath(p string) (v1.Image, error) {
}
}

var imgTar v1.Image
var err error
switch extractMediaTypeVendor(mfst.MediaType) {
case types.DockerVendorPrefix:
imgTar, err = tarball.ImageFromPath(p, nil)
case types.OCIVendorPrefix:
imgTar, err = tarball.OCIImageFromPath(p, nil)

Check failure on line 253 in pkg/cache/cache.go

View workflow job for this annotation

GitHub Actions / tests (integration-test-layers)

undefined: tarball.OCIImageFromPath

Check failure on line 253 in pkg/cache/cache.go

View workflow job for this annotation

GitHub Actions / tests

undefined: tarball.OCIImageFromPath

Check failure on line 253 in pkg/cache/cache.go

View workflow job for this annotation

GitHub Actions / tests (integration-test-misc)

undefined: tarball.OCIImageFromPath

Check failure on line 253 in pkg/cache/cache.go

View workflow job for this annotation

GitHub Actions / tests (integration-test-misc)

undefined: tarball.OCIImageFromPath

Check failure on line 253 in pkg/cache/cache.go

View workflow job for this annotation

GitHub Actions / tests (integration-test-run)

undefined: tarball.OCIImageFromPath
}
if err != nil {
return nil, errors.Wrap(err, "getting image from path")
}

return &cachedImage{
digest: filepath.Base(p),
Image: imgTar,
mfst: mfst,
}, nil
}

func extractMediaTypeVendor(mt types.MediaType) string {
if strings.Contains(string(mt), types.OCIVendorPrefix) {
return types.OCIVendorPrefix
}
return types.DockerVendorPrefix
}

0 comments on commit 39165ac

Please sign in to comment.