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

[s3 cache] Fix upload of downloaded layer #5597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 15 additions & 7 deletions cache/remotecache/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ func ResolveCacheExporterFunc() remotecache.ResolveCacheExporterFunc {
}
}

type readerFromReaderAt struct {
ra io.ReaderAt
off int64
}

func (r *readerFromReaderAt) Read(p []byte) (n int, err error) {
n, err = r.ra.ReadAt(p, r.off)
if err != nil {
return n, err
}
r.off += int64(n)
return n, nil
}

type exporter struct {
solver.CacheExporterTarget
chains *v1.CacheChains
Expand All @@ -192,12 +206,6 @@ func (e *exporter) Config() remotecache.Config {
}
}

type nopCloserSectionReader struct {
*io.SectionReader
}

func (*nopCloserSectionReader) Close() error { return nil }

func (e *exporter) Finalize(ctx context.Context) (map[string]string, error) {
cacheConfig, descs, err := e.chains.Marshal(ctx)
if err != nil {
Expand Down Expand Up @@ -256,7 +264,7 @@ func (e *exporter) Finalize(ctx context.Context) (map[string]string, error) {
return layerDone(errors.Wrap(err, "error reading layer blob from provider"))
}
defer ra.Close()
if err := e.s3Client.saveMutableAt(groupCtx, key, &nopCloserSectionReader{io.NewSectionReader(ra, 0, ra.Size())}); err != nil {
if err := e.s3Client.saveMutableAt(groupCtx, key, &readerFromReaderAt{ra, 0}); err != nil {
return layerDone(errors.Wrap(err, "error writing layer blob"))
}
layerDone(nil)
Expand Down
Loading