Files
zot/pkg/extensions/sync/oci_layout.go
T
peusebiu 0e2aa81439 feat(sync): use regclient for sync extension (#2903)
* feat(sync): use regclient for sync extension

replaced containers/image package with regclient/regclient package

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>

* fix(sync): fixed converting innner docker list mediatype

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>

* feat(sync): added option to preserve digest

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>

* fix(sync): added coverage and various fixes

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>

* fix(metadb): fixed converting manifest list not setting platform and annotations

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>

* fix(sync): remove read lock on storage, not used concurrently

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>

* feat(sync): added cache for repo tags

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>

* fix(sync): fixed Makefile
removed opengpg tag

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>

* fix(sync): add test for on demand referrer

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>

---------

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>
2025-04-15 16:58:15 -07:00

64 lines
1.5 KiB
Go

//go:build sync
// +build sync
package sync
import (
"fmt"
"path"
"github.com/gofrs/uuid"
"github.com/regclient/regclient/types/ref"
zerr "zotregistry.dev/zot/errors"
"zotregistry.dev/zot/pkg/extensions/sync/constants"
"zotregistry.dev/zot/pkg/storage"
"zotregistry.dev/zot/pkg/test/inject"
)
type OciLayoutStorageImpl struct {
storeController storage.StoreController
}
func NewOciLayoutStorage(storeController storage.StoreController) OciLayoutStorage {
return OciLayoutStorageImpl{
storeController: storeController,
}
}
func (oci OciLayoutStorageImpl) GetImageReference(repo string, reference string) (ref.Ref, error) {
localImageStore := oci.storeController.GetImageStore(repo)
if localImageStore == nil {
return ref.Ref{}, zerr.ErrLocalImgStoreNotFound
}
tempSyncPath := path.Join(localImageStore.RootDir(), repo, constants.SyncBlobUploadDir)
// create session folder
uuid, err := uuid.NewV4()
// hard to reach test case, injected error, see pkg/test/dev.go
if err := inject.Error(err); err != nil {
return ref.Ref{}, err
}
sessionRepoPath := path.Join(tempSyncPath, uuid.String())
sessionRepo := path.Join(sessionRepoPath, repo)
var imageRefPath string
digest, ok := parseReference(reference)
if ok {
imageRefPath = fmt.Sprintf("ocidir://%s@%s", sessionRepo, digest.String())
} else {
imageRefPath = fmt.Sprintf("ocidir://%s:%s", sessionRepo, reference) //nolint: nosprintfhostport
}
imageReference, err := ref.New(imageRefPath)
if err != nil {
return ref.Ref{}, err
}
return imageReference, nil
}