0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-23 22:27:35 -05:00
zot/pkg/extensions/sync/oci_layout.go
peusebiu b80deb9927
refactor(storage): refactor storage into a single ImageStore (#1656)
unified both local and s3 ImageStore logic into a single ImageStore
added a new driver interface for common file/dirs manipulations
to be implemented by different storage types

refactor(gc): drop umoci dependency, implemented internal gc

added retentionDelay config option that specifies
the garbage collect delay for images without tags

this will also clean manifests which are part of an index image
(multiarch) that no longer exist.

fix(dedupe): skip blobs under .sync/ directory

if startup dedupe is running while also syncing is running
ignore blobs under sync's temporary storage

fix(storage): do not allow image indexes modifications

when deleting a manifest verify that it is not part of a multiarch image
and throw a MethodNotAllowed error to the client if it is.
we don't want to modify multiarch images

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
2023-09-01 10:54:39 -07:00

71 lines
1.7 KiB
Go

//go:build sync
// +build sync
package sync
import (
"fmt"
"os"
"path"
"github.com/containers/image/v5/oci/layout"
"github.com/containers/image/v5/types"
"github.com/gofrs/uuid"
"zotregistry.io/zot/pkg/extensions/sync/constants"
"zotregistry.io/zot/pkg/storage"
storageConstants "zotregistry.io/zot/pkg/storage/constants"
"zotregistry.io/zot/pkg/test/inject"
)
type OciLayoutStorageImpl struct {
storeController storage.StoreController
context *types.SystemContext
}
func NewOciLayoutStorage(storeController storage.StoreController) OciLayoutStorage {
context := &types.SystemContext{}
// preserve compression
context.OCIAcceptUncompressedLayers = true
return OciLayoutStorageImpl{
storeController: storeController,
context: context,
}
}
func (oci OciLayoutStorageImpl) GetContext() *types.SystemContext {
return oci.context
}
func (oci OciLayoutStorageImpl) GetImageReference(repo string, reference string) (types.ImageReference, error) {
localImageStore := oci.storeController.GetImageStore(repo)
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 nil, err
}
sessionRepoPath := path.Join(tempSyncPath, uuid.String())
localRepo := path.Join(sessionRepoPath, repo)
if err := os.MkdirAll(localRepo, storageConstants.DefaultDirPerms); err != nil {
return nil, err
}
_, refIsDigest := parseReference(reference)
if !refIsDigest {
localRepo = fmt.Sprintf("%s:%s", localRepo, reference)
}
localImageRef, err := layout.ParseReference(localRepo)
if err != nil {
return nil, err
}
return localImageRef, nil
}