mirror of https://github.com/harness/drone.git
fix: [AH-544]: fix cross registry mount (#2846)
* fix: [AH_544]: fix cross registry mountpull/3576/head
parent
874f9957ab
commit
5af278c2bb
|
@ -16,7 +16,6 @@ package oci
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/harness/gitness/registry/app/pkg/commons"
|
||||
)
|
||||
|
@ -28,13 +27,8 @@ func (h *Handler) InitiateUploadBlob(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
fromParam := r.FormValue("from")
|
||||
fromParamParts := strings.Split(fromParam, "/")
|
||||
fromRepo := ""
|
||||
if len(fromParamParts) > 1 {
|
||||
fromRepo = fromParamParts[1]
|
||||
}
|
||||
mountDigest := r.FormValue("mount")
|
||||
headers, errs := h.Controller.InitiateUploadBlob(r.Context(), info, fromRepo, mountDigest)
|
||||
headers, errs := h.Controller.InitiateUploadBlob(r.Context(), info, fromParam, mountDigest)
|
||||
if commons.IsEmpty(errs) {
|
||||
headers.WriteToResponse(w)
|
||||
}
|
||||
|
|
|
@ -236,7 +236,7 @@ func (c *Controller) GetBlob(ctx context.Context, info pkg.RegistryInfo) Respons
|
|||
func (c *Controller) InitiateUploadBlob(
|
||||
ctx context.Context,
|
||||
info pkg.RegistryInfo,
|
||||
fromRepo string,
|
||||
fromImageRef string,
|
||||
mountDigest string,
|
||||
) (*commons.ResponseHeaders, []error) {
|
||||
err := GetRegistryCheckAccess(
|
||||
|
@ -246,7 +246,7 @@ func (c *Controller) InitiateUploadBlob(
|
|||
if err != nil {
|
||||
return nil, []error{errcode.ErrCodeDenied}
|
||||
}
|
||||
return c.local.InitBlobUpload(ctx, info, fromRepo, mountDigest)
|
||||
return c.local.InitBlobUpload(ctx, info, fromImageRef, mountDigest)
|
||||
}
|
||||
|
||||
func (c *Controller) GetUploadBlobStatus(
|
||||
|
|
|
@ -35,6 +35,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/harness/gitness/app/api/request"
|
||||
"github.com/harness/gitness/app/paths"
|
||||
"github.com/harness/gitness/registry/app/dist_temp/dcontext"
|
||||
"github.com/harness/gitness/registry/app/dist_temp/errcode"
|
||||
"github.com/harness/gitness/registry/app/manifest"
|
||||
|
@ -1848,7 +1849,7 @@ func (r *LocalRegistry) dbGetTags(
|
|||
}
|
||||
|
||||
func (r *LocalRegistry) dbMountBlob(
|
||||
ctx context.Context, fromRepo, toRepo string,
|
||||
ctx context.Context, fromImageRef, toRepo string,
|
||||
d digest.Digest, info pkg.RegistryInfo,
|
||||
) error {
|
||||
log.Debug().Msgf("cross repository blob mounting")
|
||||
|
@ -1863,6 +1864,22 @@ func (r *LocalRegistry) dbMountBlob(
|
|||
toRepo,
|
||||
)
|
||||
}
|
||||
|
||||
_, imageRef, err := paths.DisectRoot(fromImageRef)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"failed to parse image reference from: [%s]",
|
||||
fromImageRef,
|
||||
)
|
||||
}
|
||||
fromRepo, fromImageName, err := paths.DisectRoot(imageRef)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"failed to parse image name from: [%s]",
|
||||
imageRef,
|
||||
)
|
||||
}
|
||||
|
||||
sourceRepo, err := r.registryDao.GetByParentIDAndName(ctx, info.ParentID, fromRepo)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1876,7 +1893,7 @@ func (r *LocalRegistry) dbMountBlob(
|
|||
|
||||
b, err := r.ms.DBFindRepositoryBlob(
|
||||
ctx, manifest.Descriptor{Digest: d},
|
||||
sourceRepo.ID, info,
|
||||
sourceRepo.ID, fromImageName,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -113,8 +113,7 @@ type ManifestService interface {
|
|||
DeleteManifest(ctx context.Context, repoKey string, d digest.Digest, info pkg.RegistryInfo) error
|
||||
AddManifestAssociation(ctx context.Context, repoKey string, digest digest.Digest, info pkg.RegistryInfo) error
|
||||
DBFindRepositoryBlob(
|
||||
ctx context.Context, desc manifest.Descriptor, repoID int64,
|
||||
info pkg.RegistryInfo,
|
||||
ctx context.Context, desc manifest.Descriptor, repoID int64, imageName string,
|
||||
) (*types.Blob, error)
|
||||
}
|
||||
|
||||
|
@ -413,7 +412,7 @@ func (l *manifestService) dbPutManifestV2(
|
|||
}
|
||||
|
||||
// Find the config now to ensure that the config's blob is associated with the repository.
|
||||
dbCfgBlob, err := l.DBFindRepositoryBlob(ctx, mfst.Config(), dbRepo.ID, info)
|
||||
dbCfgBlob, err := l.DBFindRepositoryBlob(ctx, mfst.Config(), dbRepo.ID, info.Image)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -501,7 +500,7 @@ func (l *manifestService) dbPutManifestV2(
|
|||
|
||||
// find and associate distributable manifest layer blobs
|
||||
for _, reqLayer := range mfst.DistributableLayers() {
|
||||
dbBlob, err := l.DBFindRepositoryBlob(ctx, reqLayer, dbRepo.ID, info)
|
||||
dbBlob, err := l.DBFindRepositoryBlob(ctx, reqLayer, dbRepo.ID, info.Image)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -525,10 +524,9 @@ func (l *manifestService) dbPutManifestV2(
|
|||
|
||||
func (l *manifestService) DBFindRepositoryBlob(
|
||||
ctx context.Context, desc manifest.Descriptor,
|
||||
repoID int64, info pkg.RegistryInfo,
|
||||
repoID int64, imageName string,
|
||||
) (*types.Blob, error) {
|
||||
image := info.Image
|
||||
b, err := l.blobRepo.FindByDigestAndRepoID(ctx, desc.Digest, repoID, image)
|
||||
b, err := l.blobRepo.FindByDigestAndRepoID(ctx, desc.Digest, repoID, imageName)
|
||||
if err != nil {
|
||||
if errors.Is(err, gitnessstore.ErrResourceNotFound) {
|
||||
return nil, fmt.Errorf("blob not found in database")
|
||||
|
|
Loading…
Reference in New Issue