Merge pull request #5716 from thaJeztah/vendor_moby_master

vendor: github.com/docker/docker 6f6c3b921180 (master, v28.0.0-dev)
This commit is contained in:
Sebastiaan van Stijn 2025-01-02 12:32:32 +01:00 committed by GitHub
commit 7138107e87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 131 additions and 95 deletions

View File

@ -13,7 +13,7 @@ require (
github.com/distribution/reference v0.6.0 github.com/distribution/reference v0.6.0
github.com/docker/cli-docs-tool v0.8.0 github.com/docker/cli-docs-tool v0.8.0
github.com/docker/distribution v2.8.3+incompatible github.com/docker/distribution v2.8.3+incompatible
github.com/docker/docker v27.0.2-0.20241223115700-a72026acbbdf+incompatible // master (v-next) github.com/docker/docker v27.0.2-0.20250101151200-6f6c3b921180+incompatible // master (v-next)
github.com/docker/docker-credential-helpers v0.8.2 github.com/docker/docker-credential-helpers v0.8.2
github.com/docker/go-connections v0.5.0 github.com/docker/go-connections v0.5.0
github.com/docker/go-units v0.5.0 github.com/docker/go-units v0.5.0

View File

@ -51,8 +51,8 @@ github.com/docker/cli-docs-tool v0.8.0/go.mod h1:8TQQ3E7mOXoYUs811LiPdUnAhXrcVsB
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v27.0.2-0.20241223115700-a72026acbbdf+incompatible h1:FOlr2DkAdfOdGc3O8YjP27v2XzFGIrYmwtORXMbbxJI= github.com/docker/docker v27.0.2-0.20250101151200-6f6c3b921180+incompatible h1:R8zzddOp6gD0KL9SGDvRtbGiWZ8fxqzzu2v6t+whvdc=
github.com/docker/docker v27.0.2-0.20241223115700-a72026acbbdf+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v27.0.2-0.20250101151200-6f6c3b921180+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo= github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M= github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0= github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0=

View File

@ -19,13 +19,13 @@ import (
"runtime/debug" "runtime/debug"
"strconv" "strconv"
"strings" "strings"
"sync"
"sync/atomic" "sync/atomic"
"syscall" "syscall"
"time" "time"
"github.com/containerd/log" "github.com/containerd/log"
"github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/pools"
"github.com/klauspost/compress/zstd" "github.com/klauspost/compress/zstd"
"github.com/moby/patternmatcher" "github.com/moby/patternmatcher"
"github.com/moby/sys/sequential" "github.com/moby/sys/sequential"
@ -230,13 +230,51 @@ func (r *readCloserWrapper) Close() error {
return nil return nil
} }
return r.closer() if r.closer != nil {
return r.closer()
}
return nil
}
var (
bufioReader32KPool = &sync.Pool{
New: func() interface{} { return bufio.NewReaderSize(nil, 32*1024) },
}
)
type bufferedReader struct {
buf *bufio.Reader
}
func newBufferedReader(r io.Reader) *bufferedReader {
buf := bufioReader32KPool.Get().(*bufio.Reader)
buf.Reset(r)
return &bufferedReader{buf}
}
func (r *bufferedReader) Read(p []byte) (n int, err error) {
if r.buf == nil {
return 0, io.EOF
}
n, err = r.buf.Read(p)
if err == io.EOF {
r.buf.Reset(nil)
bufioReader32KPool.Put(r.buf)
r.buf = nil
}
return
}
func (r *bufferedReader) Peek(n int) ([]byte, error) {
if r.buf == nil {
return nil, io.EOF
}
return r.buf.Peek(n)
} }
// DecompressStream decompresses the archive and returns a ReaderCloser with the decompressed archive. // DecompressStream decompresses the archive and returns a ReaderCloser with the decompressed archive.
func DecompressStream(archive io.Reader) (io.ReadCloser, error) { func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
p := pools.BufioReader32KPool buf := newBufferedReader(archive)
buf := p.Get(archive)
bs, err := buf.Peek(10) bs, err := buf.Peek(10)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
// Note: we'll ignore any io.EOF error because there are some odd // Note: we'll ignore any io.EOF error because there are some odd
@ -248,26 +286,12 @@ func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
return nil, err return nil, err
} }
wrapReader := func(r io.Reader, cancel context.CancelFunc) io.ReadCloser {
return &readCloserWrapper{
Reader: r,
closer: func() error {
if cancel != nil {
cancel()
}
if readCloser, ok := r.(io.ReadCloser); ok {
readCloser.Close()
}
p.Put(buf)
return nil
},
}
}
compression := DetectCompression(bs) compression := DetectCompression(bs)
switch compression { switch compression {
case Uncompressed: case Uncompressed:
return wrapReader(buf, nil), nil return &readCloserWrapper{
Reader: buf,
}, nil
case Gzip: case Gzip:
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -276,10 +300,18 @@ func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
cancel() cancel()
return nil, err return nil, err
} }
return wrapReader(gzReader, cancel), nil return &readCloserWrapper{
Reader: gzReader,
closer: func() error {
cancel()
return gzReader.Close()
},
}, nil
case Bzip2: case Bzip2:
bz2Reader := bzip2.NewReader(buf) bz2Reader := bzip2.NewReader(buf)
return wrapReader(bz2Reader, nil), nil return &readCloserWrapper{
Reader: bz2Reader,
}, nil
case Xz: case Xz:
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -288,30 +320,44 @@ func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
cancel() cancel()
return nil, err return nil, err
} }
return wrapReader(xzReader, cancel), nil
return &readCloserWrapper{
Reader: xzReader,
closer: func() error {
cancel()
return xzReader.Close()
},
}, nil
case Zstd: case Zstd:
zstdReader, err := zstd.NewReader(buf) zstdReader, err := zstd.NewReader(buf)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return wrapReader(zstdReader, nil), nil return &readCloserWrapper{
Reader: zstdReader,
closer: func() error {
zstdReader.Close()
return nil
},
}, nil
default: default:
return nil, fmt.Errorf("Unsupported compression format %s", (&compression).Extension()) return nil, fmt.Errorf("Unsupported compression format %s", (&compression).Extension())
} }
} }
type nopWriteCloser struct {
io.Writer
}
func (nopWriteCloser) Close() error { return nil }
// CompressStream compresses the dest with specified compression algorithm. // CompressStream compresses the dest with specified compression algorithm.
func CompressStream(dest io.Writer, compression Compression) (io.WriteCloser, error) { func CompressStream(dest io.Writer, compression Compression) (io.WriteCloser, error) {
p := pools.BufioWriter32KPool
buf := p.Get(dest)
switch compression { switch compression {
case Uncompressed: case Uncompressed:
writeBufWrapper := p.NewWriteCloserWrapper(buf, buf) return nopWriteCloser{dest}, nil
return writeBufWrapper, nil
case Gzip: case Gzip:
gzWriter := gzip.NewWriter(dest) return gzip.NewWriter(dest), nil
writeBufWrapper := p.NewWriteCloserWrapper(buf, gzWriter)
return writeBufWrapper, nil
case Bzip2, Xz: case Bzip2, Xz:
// archive/bzip2 does not support writing, and there is no xz support at all // archive/bzip2 does not support writing, and there is no xz support at all
// However, this is not a problem as docker only currently generates gzipped tars // However, this is not a problem as docker only currently generates gzipped tars
@ -382,7 +428,7 @@ func ReplaceFileTarWrapper(inputTarStream io.ReadCloser, mods map[string]TarModi
pipeWriter.CloseWithError(err) pipeWriter.CloseWithError(err)
return return
} }
if _, err := pools.Copy(tarWriter, tarReader); err != nil { if _, err := copyWithBuffer(tarWriter, tarReader); err != nil {
pipeWriter.CloseWithError(err) pipeWriter.CloseWithError(err)
return return
} }
@ -529,7 +575,6 @@ type tarWhiteoutConverter interface {
type tarAppender struct { type tarAppender struct {
TarWriter *tar.Writer TarWriter *tar.Writer
Buffer *bufio.Writer
// for hardlink mapping // for hardlink mapping
SeenFiles map[uint64]string SeenFiles map[uint64]string
@ -547,7 +592,6 @@ func newTarAppender(idMapping idtools.IdentityMapping, writer io.Writer, chownOp
return &tarAppender{ return &tarAppender{
SeenFiles: make(map[uint64]string), SeenFiles: make(map[uint64]string),
TarWriter: tar.NewWriter(writer), TarWriter: tar.NewWriter(writer),
Buffer: pools.BufioWriter32KPool.Get(nil),
IdentityMapping: idMapping, IdentityMapping: idMapping,
ChownOpts: chownOpts, ChownOpts: chownOpts,
} }
@ -665,17 +709,11 @@ func (ta *tarAppender) addTarFile(path, name string) error {
return err return err
} }
ta.Buffer.Reset(ta.TarWriter) _, err = copyWithBuffer(ta.TarWriter, file)
defer ta.Buffer.Reset(nil)
_, err = pools.Copy(ta.Buffer, file)
file.Close() file.Close()
if err != nil { if err != nil {
return err return err
} }
err = ta.Buffer.Flush()
if err != nil {
return err
}
} }
return nil return nil
@ -718,7 +756,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
if err != nil { if err != nil {
return err return err
} }
if _, err := pools.Copy(file, reader); err != nil { if _, err := copyWithBuffer(file, reader); err != nil {
file.Close() file.Close()
return err return err
} }
@ -929,9 +967,6 @@ func (t *Tarballer) Do() {
} }
}() }()
// this buffer is needed for the duration of this piped stream
defer pools.BufioWriter32KPool.Put(ta.Buffer)
// In general we log errors here but ignore them because // In general we log errors here but ignore them because
// during e.g. a diff operation the container can continue // during e.g. a diff operation the container can continue
// mutating the filesystem and we can see transient errors // mutating the filesystem and we can see transient errors
@ -1087,8 +1122,6 @@ func (t *Tarballer) Do() {
// Unpack unpacks the decompressedArchive to dest with options. // Unpack unpacks the decompressedArchive to dest with options.
func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) error { func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) error {
tr := tar.NewReader(decompressedArchive) tr := tar.NewReader(decompressedArchive)
trBuf := pools.BufioReader32KPool.Get(nil)
defer pools.BufioReader32KPool.Put(trBuf)
var dirs []*tar.Header var dirs []*tar.Header
whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat) whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat)
@ -1165,7 +1198,6 @@ loop:
} }
} }
} }
trBuf.Reset(tr)
if err := remapIDs(options.IDMap, hdr); err != nil { if err := remapIDs(options.IDMap, hdr); err != nil {
return err return err
@ -1181,7 +1213,7 @@ loop:
} }
} }
if err := createTarFile(path, dest, hdr, trBuf, options); err != nil { if err := createTarFile(path, dest, hdr, tr, options); err != nil {
return err return err
} }
@ -1384,7 +1416,7 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {
return err return err
} }
if _, err := pools.Copy(tw, srcF); err != nil { if _, err := copyWithBuffer(tw, srcF); err != nil {
return err return err
} }
return nil return nil

View File

@ -15,7 +15,6 @@ import (
"github.com/containerd/log" "github.com/containerd/log"
"github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/pools"
) )
// ChangeType represents the change type. // ChangeType represents the change type.
@ -389,9 +388,6 @@ func ExportChanges(dir string, changes []Change, idMap idtools.IdentityMapping)
go func() { go func() {
ta := newTarAppender(idMap, writer, nil) ta := newTarAppender(idMap, writer, nil)
// this buffer is needed for the duration of this piped stream
defer pools.BufioWriter32KPool.Put(ta.Buffer)
sort.Sort(changesByPath(changes)) sort.Sort(changesByPath(changes))
// In general we log errors here but ignore them because // In general we log errors here but ignore them because

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"sync"
"github.com/containerd/log" "github.com/containerd/log"
) )
@ -20,6 +21,17 @@ var (
ErrInvalidCopySource = errors.New("invalid copy source content") ErrInvalidCopySource = errors.New("invalid copy source content")
) )
var copyPool = sync.Pool{
New: func() interface{} { s := make([]byte, 32*1024); return &s },
}
func copyWithBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
buf := copyPool.Get().(*[]byte)
written, err = io.CopyBuffer(dst, src, *buf)
copyPool.Put(buf)
return
}
// PreserveTrailingDotOrSeparator returns the given cleaned path (after // PreserveTrailingDotOrSeparator returns the given cleaned path (after
// processing using any utility functions from the path or filepath stdlib // processing using any utility functions from the path or filepath stdlib
// packages) and appends a trailing `/.` or `/` if its corresponding original // packages) and appends a trailing `/.` or `/` if its corresponding original

View File

@ -11,7 +11,6 @@ import (
"strings" "strings"
"github.com/containerd/log" "github.com/containerd/log"
"github.com/docker/docker/pkg/pools"
) )
// UnpackLayer unpack `layer` to a `dest`. The stream `layer` can be // UnpackLayer unpack `layer` to a `dest`. The stream `layer` can be
@ -19,8 +18,6 @@ import (
// Returns the size in bytes of the contents of the layer. // Returns the size in bytes of the contents of the layer.
func UnpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64, err error) { func UnpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64, err error) {
tr := tar.NewReader(layer) tr := tar.NewReader(layer)
trBuf := pools.BufioReader32KPool.Get(tr)
defer pools.BufioReader32KPool.Put(trBuf)
var dirs []*tar.Header var dirs []*tar.Header
unpackedPaths := make(map[string]struct{}) unpackedPaths := make(map[string]struct{})
@ -159,8 +156,7 @@ func UnpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64,
} }
} }
trBuf.Reset(tr) srcData := io.Reader(tr)
srcData := io.Reader(trBuf)
srcHdr := hdr srcHdr := hdr
// Hard links into /.wh..wh.plnk don't work, as we don't extract that directory, so // Hard links into /.wh..wh.plnk don't work, as we don't extract that directory, so

View File

@ -61,35 +61,6 @@ func NewReaderErrWrapper(r io.Reader, closer func()) io.Reader {
} }
} }
// OnEOFReader wraps an io.ReadCloser and a function
// the function will run at the end of file or close the file.
type OnEOFReader struct {
Rc io.ReadCloser
Fn func()
}
func (r *OnEOFReader) Read(p []byte) (n int, err error) {
n, err = r.Rc.Read(p)
if err == io.EOF {
r.runFunc()
}
return
}
// Close closes the file and run the function.
func (r *OnEOFReader) Close() error {
err := r.Rc.Close()
r.runFunc()
return err
}
func (r *OnEOFReader) runFunc() {
if fn := r.Fn; fn != nil {
fn()
r.Fn = nil
}
}
// cancelReadCloser wraps an io.ReadCloser with a context for cancelling read // cancelReadCloser wraps an io.ReadCloser with a context for cancelling read
// operations. // operations.
type cancelReadCloser struct { type cancelReadCloser struct {

View File

@ -6,6 +6,7 @@ import (
_ "crypto/sha512" _ "crypto/sha512"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
"net/url" "net/url"
@ -15,7 +16,6 @@ import (
"github.com/containerd/log" "github.com/containerd/log"
"github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/ioutils"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -76,6 +76,35 @@ func cloneRequest(r *http.Request) *http.Request {
return r2 return r2
} }
// onEOFReader wraps an io.ReadCloser and a function
// the function will run at the end of file or close the file.
type onEOFReader struct {
Rc io.ReadCloser
Fn func()
}
func (r *onEOFReader) Read(p []byte) (n int, err error) {
n, err = r.Rc.Read(p)
if err == io.EOF {
r.runFunc()
}
return
}
// Close closes the file and run the function.
func (r *onEOFReader) Close() error {
err := r.Rc.Close()
r.runFunc()
return err
}
func (r *onEOFReader) runFunc() {
if fn := r.Fn; fn != nil {
fn()
r.Fn = nil
}
}
// RoundTrip changes an HTTP request's headers to add the necessary // RoundTrip changes an HTTP request's headers to add the necessary
// authentication-related headers // authentication-related headers
func (tr *authTransport) RoundTrip(orig *http.Request) (*http.Response, error) { func (tr *authTransport) RoundTrip(orig *http.Request) (*http.Response, error) {
@ -119,7 +148,7 @@ func (tr *authTransport) RoundTrip(orig *http.Request) (*http.Response, error) {
if len(resp.Header["X-Docker-Token"]) > 0 { if len(resp.Header["X-Docker-Token"]) > 0 {
tr.token = resp.Header["X-Docker-Token"] tr.token = resp.Header["X-Docker-Token"]
} }
resp.Body = &ioutils.OnEOFReader{ resp.Body = &onEOFReader{
Rc: resp.Body, Rc: resp.Body,
Fn: func() { Fn: func() {
tr.mu.Lock() tr.mu.Lock()

2
vendor/modules.txt vendored
View File

@ -55,7 +55,7 @@ github.com/docker/distribution/registry/client/transport
github.com/docker/distribution/registry/storage/cache github.com/docker/distribution/registry/storage/cache
github.com/docker/distribution/registry/storage/cache/memory github.com/docker/distribution/registry/storage/cache/memory
github.com/docker/distribution/uuid github.com/docker/distribution/uuid
# github.com/docker/docker v27.0.2-0.20241223115700-a72026acbbdf+incompatible # github.com/docker/docker v27.0.2-0.20250101151200-6f6c3b921180+incompatible
## explicit ## explicit
github.com/docker/docker/api github.com/docker/docker/api
github.com/docker/docker/api/types github.com/docker/docker/api/types