Skip to content

Commit

Permalink
Revert "feat: replace docker with oras (#904)" (#1005)
Browse files Browse the repository at this point in the history
This reverts commit 3cfa228.

<!-- markdownlint-disable MD041 -->
#### What this PR does / why we need it

#### Which issue(s) this PR fixes
<!--
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

---------

Co-authored-by: Jakob Möller <[email protected]>
  • Loading branch information
Skarlso and jakobmoellerdev authored Oct 24, 2024
1 parent ed93e9a commit c76a2ed
Show file tree
Hide file tree
Showing 18 changed files with 2,414 additions and 189 deletions.
109 changes: 109 additions & 0 deletions api/oci/extensions/repositories/ocireg/blobs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package ocireg

import (
"sync"

"github.com/containerd/containerd/remotes"
"github.com/mandelsoft/goutils/errors"
"github.com/opencontainers/go-digest"
"github.com/sirupsen/logrus"

"ocm.software/ocm/api/oci/cpi"
"ocm.software/ocm/api/oci/extensions/attrs/cacheattr"
"ocm.software/ocm/api/tech/docker/resolve"
"ocm.software/ocm/api/utils/accessio"
"ocm.software/ocm/api/utils/blobaccess/blobaccess"
)

type BlobContainer interface {
GetBlobData(digest digest.Digest) (int64, cpi.DataAccess, error)
AddBlob(blob cpi.BlobAccess) (int64, digest.Digest, error)
Unref() error
}

type blobContainer struct {
accessio.StaticAllocatable
fetcher resolve.Fetcher
pusher resolve.Pusher
mime string
}

type BlobContainers struct {
lock sync.Mutex
cache accessio.BlobCache
fetcher resolve.Fetcher
pusher resolve.Pusher
mimes map[string]BlobContainer
}

func NewBlobContainers(ctx cpi.Context, fetcher remotes.Fetcher, pusher resolve.Pusher) *BlobContainers {
return &BlobContainers{
cache: cacheattr.Get(ctx),
fetcher: fetcher,
pusher: pusher,
mimes: map[string]BlobContainer{},
}
}

func (c *BlobContainers) Get(mime string) (BlobContainer, error) {
c.lock.Lock()
defer c.lock.Unlock()

found := c.mimes[mime]
if found == nil {
container, err := NewBlobContainer(c.cache, mime, c.fetcher, c.pusher)
if err != nil {
return nil, err
}
c.mimes[mime] = container

return container, nil
}

return found, nil
}

func (c *BlobContainers) Release() error {
c.lock.Lock()
defer c.lock.Unlock()
list := errors.ErrListf("releasing mime block caches")
for _, b := range c.mimes {
list.Add(b.Unref())
}
return list.Result()
}

func newBlobContainer(mime string, fetcher resolve.Fetcher, pusher resolve.Pusher) *blobContainer {
return &blobContainer{
mime: mime,
fetcher: fetcher,
pusher: pusher,
}
}

func NewBlobContainer(cache accessio.BlobCache, mime string, fetcher resolve.Fetcher, pusher resolve.Pusher) (BlobContainer, error) {
c := newBlobContainer(mime, fetcher, pusher)

if cache == nil {
return c, nil
}
r, err := accessio.CachedAccess(c, c, cache)
if err != nil {
return nil, err
}
return r, nil
}

func (n *blobContainer) GetBlobData(digest digest.Digest) (int64, cpi.DataAccess, error) {
logrus.Debugf("orig get %s %s\n", n.mime, digest)
acc, err := NewDataAccess(n.fetcher, digest, n.mime, false)
return blobaccess.BLOB_UNKNOWN_SIZE, acc, err
}

func (n *blobContainer) AddBlob(blob cpi.BlobAccess) (int64, digest.Digest, error) {
err := push(dummyContext, n.pusher, blob)
if err != nil {
return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err
}
return blob.Size(), blob.Digest(), err
}
Loading

0 comments on commit c76a2ed

Please sign in to comment.