-
Notifications
You must be signed in to change notification settings - Fork 461
Remove docker/docker as a dependency #2298
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
35d5820
29af5c1
ac21060
88f1020
770f75e
e6b58d8
768976b
e12d83d
62d0b32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,12 @@ import ( | |
| "runtime" | ||
| "strings" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| "github.com/docker/docker/pkg/archive" | ||
| "github.com/docker/docker/pkg/idtools" | ||
| "github.com/docker/docker/pkg/pools" | ||
| "github.com/docker/docker/pkg/system" | ||
| "github.com/moby/go-archive" | ||
| "github.com/moby/go-archive/compression" | ||
| "github.com/moby/sys/sequential" | ||
| mobyuser "github.com/moby/sys/user" | ||
| ) | ||
|
|
||
| type ( | ||
|
|
@@ -26,14 +26,11 @@ type ( | |
|
|
||
| // TarOptions wraps the tar options. | ||
| TarOptions struct { | ||
| IncludeFiles []string | ||
| ExcludePatterns []string | ||
| Compression Compression | ||
| NoLchown bool | ||
| // REMOVED: use remap instead | ||
| //UIDMaps []idtools.IDMap | ||
| //GIDMaps []idtools.IDMap | ||
| ChownOpts *idtools.Identity | ||
| IncludeFiles []string | ||
| ExcludePatterns []string | ||
| Compression Compression | ||
| NoLchown bool | ||
| ChownOpts *Identity | ||
| IncludeSourceDir bool | ||
| // WhiteoutFormat is the expected on disk format for whiteout files. | ||
| // This format will be converted to the standard format on pack | ||
|
|
@@ -69,21 +66,27 @@ type AlterHeader interface { | |
| Alter(*tar.Header) (bool, error) | ||
| } | ||
|
|
||
| // Identity holds a UID and GID pair. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Structurally they are the same so we could. Only reason I have to argue against it is that |
||
| type Identity struct { | ||
| UID int | ||
| GID int | ||
| } | ||
|
|
||
| type RemapIDs struct { | ||
| mappings *idtools.IdentityMapping | ||
| mappings *mobyuser.IdentityMapping | ||
| } | ||
|
|
||
| func (r RemapIDs) Alter(hdr *tar.Header) (bool, error) { | ||
| ids, err := r.mappings.ToHost(idtools.Identity{UID: hdr.Uid, GID: hdr.Gid}) | ||
| hdr.Uid, hdr.Gid = ids.UID, ids.GID | ||
| uid, gid, err := r.mappings.ToHost(hdr.Uid, hdr.Gid) | ||
| hdr.Uid, hdr.Gid = uid, gid | ||
| return true, err | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // ApplyLayer is copied from github.com/docker/docker/pkg/archive | ||
| func ApplyLayer(dest string, layer io.Reader, options *TarOptions) (int64, error) { | ||
| dest = filepath.Clean(dest) | ||
| var err error | ||
| layer, err = archive.DecompressStream(layer) | ||
| layer, err = compression.DecompressStream(layer) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
|
|
@@ -96,8 +99,6 @@ func ApplyLayer(dest string, layer io.Reader, options *TarOptions) (int64, error | |
| // Returns the size in bytes of the contents of the layer. | ||
| func unpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64, err error) { | ||
| tr := tar.NewReader(layer) | ||
| trBuf := pools.BufioReader32KPool.Get(tr) | ||
| defer pools.BufioReader32KPool.Put(trBuf) | ||
|
|
||
| var dirs []*tar.Header | ||
| unpackedPaths := make(map[string]struct{}) | ||
|
|
@@ -183,7 +184,7 @@ func unpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64, | |
| parentPath := filepath.Join(dest, parent) | ||
|
|
||
| if _, err := os.Lstat(parentPath); err != nil && os.IsNotExist(err) { | ||
| err = system.MkdirAll(parentPath, 0600) | ||
| err = os.MkdirAll(parentPath, 0600) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
|
|
@@ -262,8 +263,7 @@ func unpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64, | |
| } | ||
| } | ||
|
|
||
| trBuf.Reset(tr) | ||
| srcData := io.Reader(trBuf) | ||
| srcData := io.Reader(tr) | ||
| srcHdr := hdr | ||
|
|
||
| // Hard links into /.wh..wh.plnk don't work, as we don't extract that directory, so | ||
|
|
@@ -301,15 +301,15 @@ func unpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64, | |
|
|
||
| for _, hdr := range dirs { | ||
| path := filepath.Join(dest, hdr.Name) | ||
| if err := system.Chtimes(path, hdr.AccessTime, hdr.ModTime); err != nil { | ||
| if err := chtimes(path, hdr.AccessTime, hdr.ModTime); err != nil { | ||
| return 0, err | ||
| } | ||
| } | ||
|
|
||
| return size, nil | ||
| } | ||
|
|
||
| func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, Lchown bool, chownOpts *idtools.Identity, inUserns bool, currentUser *user.User) error { | ||
| func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, Lchown bool, chownOpts *Identity, inUserns bool, currentUser *user.User) error { | ||
| // hdr.Mode is in linux format, which we can use for sycalls, | ||
| // but for os.Foo() calls we need the mode converted to os.FileMode, | ||
| // so use hdrInfo.Mode() (they differ for e.g. setuid bits) | ||
|
|
@@ -388,7 +388,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L | |
| // Lchown is not supported on Windows. | ||
| if Lchown && runtime.GOOS != "windows" { | ||
| if chownOpts == nil { | ||
| chownOpts = &idtools.Identity{UID: hdr.Uid, GID: hdr.Gid} | ||
| chownOpts = &Identity{UID: hdr.Uid, GID: hdr.Gid} | ||
| } | ||
| if err := os.Lchown(path, chownOpts.UID, chownOpts.GID); err != nil { | ||
| return err | ||
|
|
@@ -401,8 +401,8 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L | |
| if key == "security.capability" && currentUser != nil && currentUser.Username != "root" { | ||
| continue | ||
| } | ||
| if err := system.Lsetxattr(path, key, []byte(value), 0); err != nil { | ||
| if err == system.ErrNotSupportedPlatform { | ||
| if err := lsetxattr(path, key, []byte(value), 0); err != nil { | ||
| if err == errNotSupportedPlatform { | ||
| // we ignore not supported platform errors | ||
| // to proceed archiving on platforms like darwin. | ||
| continue | ||
|
|
@@ -434,19 +434,37 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L | |
| // system.Chtimes doesn't support a NOFOLLOW flag atm | ||
| if hdr.Typeflag == tar.TypeLink { | ||
| if fi, err := os.Lstat(hdr.Linkname); err == nil && (fi.Mode()&os.ModeSymlink == 0) { | ||
| if err := system.Chtimes(path, aTime, hdr.ModTime); err != nil { | ||
| if err := chtimes(path, aTime, hdr.ModTime); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } else if hdr.Typeflag != tar.TypeSymlink { | ||
| if err := system.Chtimes(path, aTime, hdr.ModTime); err != nil { | ||
| if err := chtimes(path, aTime, hdr.ModTime); err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| ts := []syscall.Timespec{timeToTimespec(aTime), timeToTimespec(hdr.ModTime)} | ||
| if err := system.LUtimesNano(path, ts); err != nil && err != system.ErrNotSupportedPlatform { | ||
| if err := lutimesNano(path, ts); err != nil && err != errNotSupportedPlatform { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| var ( | ||
| unixEpoch = time.Unix(0, 0) | ||
| unixMaxTime = time.Unix(0, 1<<63-1) | ||
| ) | ||
|
|
||
| // chtimes clamps atime/mtime to a valid Unix range before calling os.Chtimes. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document about where do we copy this from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, added attribution to all the functions that were copied over and a NOTICE file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fwiw, I was working on a similar patch for
I had to change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @efussi if those replacings work, that would be simpler and less regression prone. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My testing wasn't very comprehensive, but I successfully used
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to open a PR, if you have worked on it already. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ardaguclu I am afraid I am currently too tied up in the work for my employer to babysit a PR like this. But here are the automated patches that we use for our private build of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docker took pools out entirely (for the paths that we use), we can follow their lead on that. That way we don't need to depend on
Good call on |
||
| // os.Chtimes has undefined behavior for times outside [epoch, max], so we | ||
| // default out-of-range values to the epoch. | ||
| func chtimes(name string, atime, mtime time.Time) error { | ||
| if atime.Before(unixEpoch) || atime.After(unixMaxTime) { | ||
| atime = unixEpoch | ||
| } | ||
| if mtime.Before(unixEpoch) || mtime.After(unixMaxTime) { | ||
| mtime = unixEpoch | ||
| } | ||
| return os.Chtimes(name, atime, mtime) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.