Skip to content

Commit

Permalink
Merge pull request #4779 from tonistiigi/v0.13.1-picks
Browse files Browse the repository at this point in the history
[v0.13] v0.13.1 cherry-picks
  • Loading branch information
tonistiigi authored Mar 18, 2024
2 parents 3f62976 + 0aff323 commit 2ae42e0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
9 changes: 9 additions & 0 deletions cache/remotecache/v1/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ type DescriptorProviderPair struct {
Provider content.Provider
}

var _ withCheckDescriptor = DescriptorProviderPair{}

func (p DescriptorProviderPair) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) {
return p.Provider.ReaderAt(ctx, desc)
}
Expand Down Expand Up @@ -156,6 +158,13 @@ func (p DescriptorProviderPair) SnapshotLabels(descs []ocispecs.Descriptor, inde
return nil
}

func (p DescriptorProviderPair) CheckDescriptor(ctx context.Context, desc ocispecs.Descriptor) error {
if cd, ok := p.Provider.(withCheckDescriptor); ok {
return cd.CheckDescriptor(ctx, desc)
}
return nil
}

// item is an implementation of a record in the cache chain. After validation,
// normalization and marshalling into the cache config, the item results form
// into the "layers", while the digests and the links form into the "records".
Expand Down
9 changes: 6 additions & 3 deletions cache/remotecache/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"github.com/pkg/errors"
)

type withCheckDescriptor interface {
// CheckDescriptor is additional method on Provider to check if the descriptor is available without opening the reader
CheckDescriptor(context.Context, ocispecs.Descriptor) error
}

// sortConfig sorts the config structure to make sure it is deterministic
func sortConfig(cc *CacheConfig) {
type indexedLayer struct {
Expand Down Expand Up @@ -279,9 +284,7 @@ func marshalRemote(ctx context.Context, r *solver.Remote, state *marshalState) s
return ""
}

if cd, ok := r.Provider.(interface {
CheckDescriptor(context.Context, ocispecs.Descriptor) error
}); ok && len(r.Descriptors) > 0 {
if cd, ok := r.Provider.(withCheckDescriptor); ok && len(r.Descriptors) > 0 {
for _, d := range r.Descriptors {
if cd.CheckDescriptor(ctx, d) != nil {
return ""
Expand Down
8 changes: 6 additions & 2 deletions executor/oci/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package oci

import (
"context"
"os"
"path"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -197,8 +198,11 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou
}

if tracingSocket != "" {
if mount := getTracingSocketMount(tracingSocket); mount != nil {
s.Mounts = append(s.Mounts, *mount)
// moby/buildkit#4764
if _, err := os.Stat(tracingSocket); err == nil {
if mount := getTracingSocketMount(tracingSocket); mount != nil {
s.Mounts = append(s.Mounts, *mount)
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ func New(opt Opt) (*Solver, error) {

func (s *Solver) Close() error {
s.solver.Close()
err := s.sysSampler.Close()
return err
if s.sysSampler != nil {
return s.sysSampler.Close()
}
return nil
}

func (s *Solver) resolver() solver.ResolveOpFunc {
Expand Down
4 changes: 3 additions & 1 deletion util/gitutil/git_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func ParseGitRef(ref string) (*GitRef, error) {
err error
)

if strings.HasPrefix(ref, "github.com/") {
if strings.HasPrefix(ref, "./") || strings.HasPrefix(ref, "../") {
return nil, errdefs.ErrInvalidArgument
} else if strings.HasPrefix(ref, "github.com/") {
res.IndistinguishableFromLocal = true // Deprecated
remote = fromURL(&url.URL{
Scheme: "https",
Expand Down
9 changes: 9 additions & 0 deletions util/gitutil/git_ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,21 @@ func TestParseGitRef(t *testing.T) {
SubDir: "myfolder",
},
},
{
ref: "./.git",
expected: nil,
},
{
ref: ".git",
expected: nil,
},
}
for _, tt := range cases {
tt := tt
t.Run(tt.ref, func(t *testing.T) {
got, err := ParseGitRef(tt.ref)
if tt.expected == nil {
require.Nil(t, got)
require.Error(t, err)
} else {
require.NoError(t, err)
Expand Down

0 comments on commit 2ae42e0

Please sign in to comment.