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

fixes for github actions cache #2387

Merged
merged 4 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 38 additions & 5 deletions cache/remotecache/gha/gha.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"sync"
"time"

"github.com/containerd/containerd/content"
Expand Down Expand Up @@ -141,7 +143,9 @@ func (ce *exporter) Finalize(ctx context.Context) (map[string]string, error) {
return nil, layerDone(err)
}
if err := ce.cache.Save(ctx, key, ra); err != nil {
return nil, layerDone(errors.Wrap(err, "error writing layer blob"))
if !errors.Is(err, os.ErrExist) {
return nil, layerDone(errors.Wrap(err, "error writing layer blob"))
}
}
layerDone(nil)
}
Expand Down Expand Up @@ -305,18 +309,47 @@ func (ci *importer) Resolve(ctx context.Context, _ ocispecs.Descriptor, id strin
}

type ciProvider struct {
desc ocispecs.Descriptor
ci *importer
ci *importer
desc ocispecs.Descriptor
mu sync.Mutex
entries map[digest.Digest]*actionscache.Entry
}

func (p *ciProvider) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) {
func (p *ciProvider) CheckDescriptor(ctx context.Context, desc ocispecs.Descriptor) error {
if desc.Digest != p.desc.Digest {
return nil
}

_, err := p.loadEntry(ctx, desc)
return err
}

func (p *ciProvider) loadEntry(ctx context.Context, desc ocispecs.Descriptor) (*actionscache.Entry, error) {
p.mu.Lock()
defer p.mu.Unlock()

if ce, ok := p.entries[desc.Digest]; ok {
return ce, nil
}
key := "buildkit-blob-" + version + "-" + desc.Digest.String()
ce, err := p.ci.cache.Load(ctx, key)
if err != nil {
return nil, err
}
if ce == nil {
return nil, errors.Errorf("blob not found")
return nil, errors.Errorf("blob %s not found", desc.Digest)
}
if p.entries == nil {
p.entries = make(map[digest.Digest]*actionscache.Entry)
}
p.entries[desc.Digest] = ce
return ce, nil
}

func (p *ciProvider) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) {
ce, err := p.loadEntry(ctx, desc)
if err != nil {
return nil, err
}
rac := ce.Download(context.TODO())
return &readerAt{ReaderAtCloser: rac, desc: desc}, nil
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/tonistiigi/fsutil v0.0.0-20210818161904-4442383b5028
github.com/tonistiigi/go-actions-cache v0.0.0-20210714033416-b93d7f1b2e70
github.com/tonistiigi/go-actions-cache v0.0.0-20211002214948-4d48f2ff622a
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f
github.com/urfave/cli v1.22.4
Expand Down Expand Up @@ -88,6 +88,7 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/docker/go-metrics v0.0.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumC
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8=
github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U=
github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE=
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/docker/cli v0.0.0-20190925022749-754388324470/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
Expand Down Expand Up @@ -1034,8 +1036,8 @@ github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa/go.mod h1:dS
github.com/tonistiigi/fsutil v0.0.0-20201103201449-0834f99b7b85/go.mod h1:a7cilN64dG941IOXfhJhlH0qB92hxJ9A1ewrdUmJ6xo=
github.com/tonistiigi/fsutil v0.0.0-20210818161904-4442383b5028 h1:uEkkUFMCPtzz1HVOa42u15OHems1ugiRt172tSRTWSk=
github.com/tonistiigi/fsutil v0.0.0-20210818161904-4442383b5028/go.mod h1:E6osHKls9ix67jofYQ61RQKwlJhqJOZM2hintp+49iI=
github.com/tonistiigi/go-actions-cache v0.0.0-20210714033416-b93d7f1b2e70 h1:+ZlFs3Tl5qYZJvX2PxfZxGlVXz847LsOJGyNVU5pCHo=
github.com/tonistiigi/go-actions-cache v0.0.0-20210714033416-b93d7f1b2e70/go.mod h1:dNS+PPTqGnSl80x3wEyWWCHeON5xiBGtcM0uD6CgHNU=
github.com/tonistiigi/go-actions-cache v0.0.0-20211002214948-4d48f2ff622a h1:TkwT/jFyObWQRFSUdLPEUIBXXlbqkGzStfOFgu/okCE=
github.com/tonistiigi/go-actions-cache v0.0.0-20211002214948-4d48f2ff622a/go.mod h1:YiIBjH5gP7mao3t0dBrNNBGuKYdeJmcAJjYLXr43k6A=
github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.0.0-20210714055410-d010b05b4939 h1:s6wDMZYNyWt8KvkjhrMpOthFPgI3JB8ipJS+eCV/psg=
github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.0.0-20210714055410-d010b05b4939/go.mod h1:Vm5u/mtkj1OMhtao0v+BGo2LUoLCgHYXvRmj0jWITlE=
github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/net/http/httptrace/otelhttptrace v0.0.0-20210714055410-d010b05b4939 h1:ZZ1KHKvs97BcRoblbm6RhrDzs/OejFv7miYSIcZI7Ds=
Expand Down
2 changes: 2 additions & 0 deletions solver/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,8 @@ func notifyCompleted(ctx context.Context, v *client.Vertex, err error, cached bo
v.Cached = cached
if err != nil {
v.Error = err.Error()
} else {
v.Error = ""
}
pw.Write(v.Digest.String(), *v)
}
Expand Down
20 changes: 20 additions & 0 deletions util/contentutil/multiprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ type MultiProvider struct {
sub map[digest.Digest]content.Provider
}

func (mp *MultiProvider) CheckDescriptor(ctx context.Context, desc ocispecs.Descriptor) error {
type checkDescriptor interface {
CheckDescriptor(context.Context, ocispecs.Descriptor) error
}

mp.mu.RLock()
if p, ok := mp.sub[desc.Digest]; ok {
mp.mu.RUnlock()
if cd, ok := p.(checkDescriptor); ok {
return cd.CheckDescriptor(ctx, desc)
}
} else {
mp.mu.RUnlock()
}
if cd, ok := mp.base.(checkDescriptor); ok {
return cd.CheckDescriptor(ctx, desc)
}
return nil
}

// ReaderAt returns a content.ReaderAt
func (mp *MultiProvider) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) {
mp.mu.RLock()
Expand Down
37 changes: 37 additions & 0 deletions vendor/github.com/dimchansky/utfbom/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions vendor/github.com/dimchansky/utfbom/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading