Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: replace docker with oras (#904)" #1005

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/lint_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ jobs:
cache_name: run-tests-go-cache

- name: Test
run: make build install-requirements test
run: |
PATH=$PATH:$(go env GOPATH)/bin make build install-requirements test

go-lint:
name: Lint Golang
Expand Down Expand Up @@ -78,6 +79,11 @@ jobs:
cache_name: golint-go-cache

- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
run: |
go install golang.org/x/tools/cmd/goimports@latest
- name: Setup lint
run: |
make -f hack/Makefile golangci-lint
- name: Lint
run: make check
run: |
PATH=$PATH:$(go env GOPATH)/bin make check
File renamed without changes.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ format:
@$(REPO_ROOT)/hack/format.sh $(EFFECTIVE_DIRECTORIES)

.PHONY: check
check: ## Run golangci-lint.
make -f hack/Makefile golangci-lint
golangci-lint run --timeout 10m --config .github/config/golangci.yaml $(EFFECTIVE_DIRECTORIES)
check:
@$(REPO_ROOT)/hack/check.sh --golangci-lint-config=./.golangci.yaml $(EFFECTIVE_DIRECTORIES)

.PHONY: check-and-fix
check-and-fix:
Expand Down
12 changes: 6 additions & 6 deletions api/credentials/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,25 @@ func GuessConsumerType(ctxp ContextProvider, spec string) string {
}
}
if fix == "" {
minVal := -1
min := -1
for _, i := range matchers.List() {
idx := strings.Index(i.Type, ".")
if idx > 0 {
d := levenshtein.DistanceForStrings([]rune(lspec), []rune(strings.ToLower(i.Type[:idx])), levenshtein.DefaultOptions)
if d < 5 && fix == "" || minVal > d {
if d < 5 && fix == "" || min > d {
fix = i.Type
minVal = d
min = d
}
}
}
}
if fix == "" {
minVal := -1
min := -1
for _, i := range matchers.List() {
d := levenshtein.DistanceForStrings([]rune(lspec), []rune(strings.ToLower(i.Type)), levenshtein.DefaultOptions)
if d < 5 && fix == "" || minVal > d {
if d < 5 && fix == "" || min > d {
fix = i.Type
minVal = d
min = d
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions api/oci/cpi/support/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func (a *ArtifactAccessImpl) ManifestAccess(v cpi.ArtifactAccess) internal.Manif
return nil
}
}

return NewManifestForArtifact(v, a)
}

Expand Down Expand Up @@ -178,7 +177,7 @@ func (a *ArtifactAccessImpl) GetBlob(digest digest.Digest) (cpi.BlobAccess, erro
if d != nil {
size, data, err := a.container.GetBlobData(digest)
if err != nil {
return nil, fmt.Errorf("failed to get blob data for artifact access with digest %s: %w", digest.String(), err)
return nil, err
}
err = AdjustSize(d, size)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/oci/extensions/repositories/docker/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (a *artBlobCache) Unref() error {
func (a *artBlobCache) GetBlobData(digest digest.Digest) (int64, blobaccess.DataAccess, error) {
blob, err := a.access.GetBlob(digest)
if err != nil {
return -1, nil, fmt.Errorf("error getting blob for docker repo %s: %w", digest, err)
return -1, nil, err
}
return blob.Size(), blob, err
}
Expand Down
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