Skip to content

Commit d0154d3

Browse files
committed
Update to use github.com/moby/go-archive
Update use of idtools to moby/user for archive and other deprecated uses Signed-off-by: Derek McGowan <[email protected]>
1 parent 57a042b commit d0154d3

77 files changed

Lines changed: 264 additions & 286 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/server/router/container/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/docker/docker/api/types/container"
99
"github.com/docker/docker/api/types/filters"
1010
containerpkg "github.com/docker/docker/container"
11-
"github.com/docker/docker/pkg/archive"
11+
"github.com/moby/go-archive"
1212
)
1313

1414
// execBackend includes functions to implement to provide exec functionality.

builder/builder-next/adapters/snapshot/snapshot.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/moby/buildkit/snapshot"
1919
"github.com/moby/buildkit/util/leaseutil"
2020
"github.com/moby/locker"
21+
"github.com/moby/sys/user"
2122
"github.com/opencontainers/go-digest"
2223
"github.com/pkg/errors"
2324
bolt "go.etcd.io/bbolt"
@@ -36,7 +37,7 @@ type Opt struct {
3637
GraphDriver graphdriver.Driver
3738
LayerStore layer.Store
3839
Root string
39-
IdentityMapping idtools.IdentityMapping
40+
IdentityMapping user.IdentityMapping
4041
}
4142

4243
type graphIDRegistrar interface {
@@ -112,7 +113,9 @@ func (s *snapshotter) IdentityMapping() *idtools.IdentityMapping {
112113
if s.opt.IdentityMapping.Empty() {
113114
return nil
114115
}
115-
return &s.opt.IdentityMapping
116+
// TODO: Update this once BuildKit switches from idtools
117+
idMap := idtools.FromUserIdentityMapping(s.opt.IdentityMapping)
118+
return &idMap
116119
}
117120

118121
func (s *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) error {
@@ -494,7 +497,7 @@ type mountable struct {
494497
acquire func() ([]mount.Mount, func() error, error)
495498
release func() error
496499
refCount int
497-
idmap idtools.IdentityMapping
500+
idmap user.IdentityMapping
498501
}
499502

500503
func (m *mountable) Mount() ([]mount.Mount, func() error, error) {
@@ -544,5 +547,7 @@ func (m *mountable) IdentityMapping() *idtools.IdentityMapping {
544547
if m.idmap.Empty() {
545548
return nil
546549
}
547-
return &m.idmap
550+
// TODO: Update this once BuildKit switches from idtools
551+
idtoolsMap := idtools.FromUserIdentityMapping(m.idmap)
552+
return &idtoolsMap
548553
}

builder/builder-next/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/docker/docker/errdefs"
2727
"github.com/docker/docker/libnetwork"
2828
"github.com/docker/docker/opts"
29-
"github.com/docker/docker/pkg/idtools"
3029
"github.com/docker/docker/pkg/streamformatter"
3130
controlapi "github.com/moby/buildkit/api/services/control"
3231
"github.com/moby/buildkit/client"
@@ -35,6 +34,7 @@ import (
3534
"github.com/moby/buildkit/session"
3635
"github.com/moby/buildkit/util/entitlements"
3736
"github.com/moby/buildkit/util/tracing"
37+
"github.com/moby/sys/user"
3838
"github.com/pkg/errors"
3939
"golang.org/x/sync/errgroup"
4040
"google.golang.org/grpc"
@@ -89,7 +89,7 @@ type Opt struct {
8989
RegistryHosts docker.RegistryHosts
9090
BuilderConfig config.BuilderConfig
9191
Rootless bool
92-
IdentityMapping idtools.IdentityMapping
92+
IdentityMapping user.IdentityMapping
9393
DNSConfig config.DNSConfig
9494
ApparmorProfile string
9595
UseSnapshotter bool

builder/builder-next/executor_linux.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import (
2222
"github.com/moby/buildkit/solver/llbsolver/cdidevices"
2323
"github.com/moby/buildkit/solver/pb"
2424
"github.com/moby/buildkit/util/network"
25+
"github.com/moby/sys/user"
2526
"github.com/opencontainers/runtime-spec/specs-go"
2627
)
2728

2829
const networkName = "bridge"
2930

30-
func newExecutor(root, cgroupParent string, net *libnetwork.Controller, dnsConfig *oci.DNSConfig, rootless bool, idmap idtools.IdentityMapping, apparmorProfile string, cdiManager *cdidevices.Manager) (executor.Executor, error) {
31+
func newExecutor(root, cgroupParent string, net *libnetwork.Controller, dnsConfig *oci.DNSConfig, rootless bool, idmap user.IdentityMapping, apparmorProfile string, cdiManager *cdidevices.Manager) (executor.Executor, error) {
3132
netRoot := filepath.Join(root, "net")
3233
networkProviders := map[pb.NetMode]network.Provider{
3334
pb.NetMode_UNSET: &bridgeProvider{Controller: net, Root: netRoot},
@@ -48,7 +49,9 @@ func newExecutor(root, cgroupParent string, net *libnetwork.Controller, dnsConfi
4849

4950
// Returning a non-nil but empty *IdentityMapping breaks BuildKit:
5051
// https://github.com/moby/moby/pull/39444
51-
pidmap := &idmap
52+
// TODO: Remove conversion once buildkit updates
53+
idtoolsMap := idtools.FromUserIdentityMapping(idmap)
54+
pidmap := &idtoolsMap
5255
if idmap.Empty() {
5356
pidmap = nil
5457
}

builder/builder-next/executor_nolinux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99

1010
"github.com/docker/docker/daemon/config"
1111
"github.com/docker/docker/libnetwork"
12-
"github.com/docker/docker/pkg/idtools"
1312
"github.com/moby/buildkit/executor"
1413
"github.com/moby/buildkit/executor/oci"
1514
resourcetypes "github.com/moby/buildkit/executor/resources/types"
1615
"github.com/moby/buildkit/solver/llbsolver/cdidevices"
16+
"github.com/moby/sys/user"
1717
)
1818

19-
func newExecutor(_, _ string, _ *libnetwork.Controller, _ *oci.DNSConfig, _ bool, _ idtools.IdentityMapping, _ string, _ *cdidevices.Manager) (executor.Executor, error) {
19+
func newExecutor(_, _ string, _ *libnetwork.Controller, _ *oci.DNSConfig, _ bool, _ user.IdentityMapping, _ string, _ *cdidevices.Manager) (executor.Executor, error) {
2020
return &stubExecutor{}, nil
2121
}
2222

builder/dockerfile/builder.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import (
1616
"github.com/docker/docker/builder"
1717
"github.com/docker/docker/builder/remotecontext"
1818
"github.com/docker/docker/errdefs"
19-
"github.com/docker/docker/pkg/idtools"
2019
"github.com/docker/docker/pkg/streamformatter"
2120
"github.com/docker/docker/pkg/stringid"
2221
"github.com/moby/buildkit/frontend/dockerfile/instructions"
2322
"github.com/moby/buildkit/frontend/dockerfile/parser"
2423
"github.com/moby/buildkit/frontend/dockerfile/shell"
24+
"github.com/moby/sys/user"
2525
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2626
"github.com/pkg/errors"
2727
"golang.org/x/sync/syncmap"
@@ -47,13 +47,13 @@ const (
4747

4848
// BuildManager is shared across all Builder objects
4949
type BuildManager struct {
50-
idMapping idtools.IdentityMapping
50+
idMapping user.IdentityMapping
5151
backend builder.Backend
5252
pathCache pathCache // TODO: make this persistent
5353
}
5454

5555
// NewBuildManager creates a BuildManager
56-
func NewBuildManager(b builder.Backend, identityMapping idtools.IdentityMapping) (*BuildManager, error) {
56+
func NewBuildManager(b builder.Backend, identityMapping user.IdentityMapping) (*BuildManager, error) {
5757
bm := &BuildManager{
5858
backend: b,
5959
pathCache: &syncmap.Map{},
@@ -103,7 +103,7 @@ type builderOptions struct {
103103
Backend builder.Backend
104104
ProgressWriter backend.ProgressWriter
105105
PathCache pathCache
106-
IDMapping idtools.IdentityMapping
106+
IDMapping user.IdentityMapping
107107
}
108108

109109
// Builder is a Dockerfile builder
@@ -118,7 +118,7 @@ type Builder struct {
118118

119119
docker builder.Backend
120120

121-
idMapping idtools.IdentityMapping
121+
idMapping user.IdentityMapping
122122
disableCommit bool
123123
imageSources *imageSources
124124
pathCache pathCache

builder/dockerfile/copy.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import (
1717
"github.com/docker/docker/builder"
1818
"github.com/docker/docker/builder/remotecontext"
1919
"github.com/docker/docker/builder/remotecontext/urlutil"
20-
"github.com/docker/docker/pkg/archive"
21-
"github.com/docker/docker/pkg/idtools"
2220
"github.com/docker/docker/pkg/longpath"
2321
"github.com/docker/docker/pkg/progress"
2422
"github.com/docker/docker/pkg/streamformatter"
2523
"github.com/docker/docker/pkg/system"
2624
"github.com/moby/buildkit/frontend/dockerfile/instructions"
25+
"github.com/moby/go-archive"
2726
"github.com/moby/sys/symlink"
27+
"github.com/moby/sys/user"
2828
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2929
"github.com/pkg/errors"
3030
)
@@ -446,9 +446,15 @@ func downloadSource(output io.Writer, stdout io.Writer, srcURL string) (remote b
446446
return lc, filename, err
447447
}
448448

449+
type identity struct {
450+
UID int
451+
GID int
452+
SID string
453+
}
454+
449455
type copyFileOptions struct {
450456
decompress bool
451-
identity *idtools.Identity
457+
identity *identity
452458
archiver *archive.Archiver
453459
}
454460

@@ -498,7 +504,7 @@ func performCopyForInfo(dest copyInfo, source copyInfo, options copyFileOptions)
498504
return copyFile(archiver, srcPath, destPath, options.identity)
499505
}
500506

501-
func copyDirectory(archiver *archive.Archiver, source, dest string, identity *idtools.Identity) error {
507+
func copyDirectory(archiver *archive.Archiver, source, dest string, identity *identity) error {
502508
destExists, err := isExistingDirectory(dest)
503509
if err != nil {
504510
return errors.Wrapf(err, "failed to query destination path")
@@ -513,13 +519,13 @@ func copyDirectory(archiver *archive.Archiver, source, dest string, identity *id
513519
return nil
514520
}
515521

516-
func copyFile(archiver *archive.Archiver, source, dest string, identity *idtools.Identity) error {
522+
func copyFile(archiver *archive.Archiver, source, dest string, identity *identity) error {
517523
if identity == nil {
518524
if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
519525
return err
520526
}
521527
} else {
522-
if err := idtools.MkdirAllAndChownNew(filepath.Dir(dest), 0o755, *identity); err != nil {
528+
if err := user.MkdirAllAndChown(filepath.Dir(dest), 0o755, identity.UID, identity.GID, user.WithOnlyNew); err != nil {
523529
return errors.Wrapf(err, "failed to create new directory")
524530
}
525531
}

builder/dockerfile/copy_unix.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import (
77
"path"
88
"path/filepath"
99
"strings"
10-
11-
"github.com/docker/docker/pkg/idtools"
1210
)
1311

14-
func fixPermissions(source, destination string, identity idtools.Identity, overrideSkip bool) error {
12+
func fixPermissions(source, destination string, id identity, overrideSkip bool) error {
1513
var (
1614
skipChownRoot bool
1715
err error
@@ -39,7 +37,7 @@ func fixPermissions(source, destination string, identity idtools.Identity, overr
3937
}
4038

4139
fullpath = filepath.Join(destination, cleaned)
42-
return os.Lchown(fullpath, identity.UID, identity.GID)
40+
return os.Lchown(fullpath, id.UID, id.GID)
4341
})
4442
}
4543

builder/dockerfile/copy_windows.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
winio "github.com/Microsoft/go-winio"
1010
"github.com/docker/docker/internal/usergroup"
11-
"github.com/docker/docker/pkg/idtools"
1211
"github.com/docker/docker/pkg/system"
1312
"github.com/moby/sys/reexec"
1413
"github.com/pkg/errors"
@@ -24,12 +23,12 @@ func init() {
2423
reexec.Register("windows-fix-permissions", fixPermissionsReexec)
2524
}
2625

27-
func fixPermissions(source, destination string, identity idtools.Identity, _ bool) error {
28-
if identity.SID == "" {
26+
func fixPermissions(source, destination string, id identity, _ bool) error {
27+
if id.SID == "" {
2928
return nil
3029
}
3130

32-
cmd := reexec.Command("windows-fix-permissions", source, destination, identity.SID)
31+
cmd := reexec.Command("windows-fix-permissions", source, destination, id.SID)
3332
output, err := cmd.CombinedOutput()
3433

3534
return errors.Wrapf(err, "failed to exec windows-fix-permissions: %s", output)

builder/dockerfile/evaluator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"testing"
88

99
"github.com/docker/docker/builder/remotecontext"
10-
"github.com/docker/docker/pkg/archive"
1110
"github.com/moby/buildkit/frontend/dockerfile/instructions"
11+
"github.com/moby/go-archive"
1212
"github.com/moby/sys/reexec"
1313
"gotest.tools/v3/assert"
1414
is "gotest.tools/v3/assert/cmp"

0 commit comments

Comments
 (0)