Skip to content
Closed
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
4 changes: 2 additions & 2 deletions cli/command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,13 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {

if s != nil {
go func() {
logrus.Debugf("running session: %v", s.UUID())
logrus.Debugf("running session: %v", s.ID())
if err := s.Run(ctx, dockerCli.Client().DialSession); err != nil {
logrus.Error(err)
cancel() // cancel progress context
}
}()
buildOptions.SessionID = s.UUID()
buildOptions.SessionID = s.ID()
}

response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)
Expand Down
15 changes: 14 additions & 1 deletion cli/command/image/build_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/filesync"
"github.com/pkg/errors"
"github.com/tonistiigi/fsutil"
"golang.org/x/time/rate"
)

Expand Down Expand Up @@ -52,8 +53,20 @@ func addDirToSession(session *session.Session, contextDir string, progressOutput
}

p := &sizeProgress{out: progressOutput, action: "Streaming build context to Docker daemon"}
mapUIDAndGID := func(s *fsutil.Stat) bool {
s.Uid = uint32(0)
s.Gid = uint32(0)

workdirProvider := filesync.NewFSSyncProvider(contextDir, excludes)
return true
}

workdirProvider := filesync.NewFSSyncProvider([]filesync.SyncedDir{
{
Dir: contextDir,
Excludes: excludes,
Map: mapUIDAndGID,
},
})
session.Allow(workdirProvider)

// this will be replaced on parallel build jobs. keep the current
Expand Down
37 changes: 37 additions & 0 deletions cli/command/image/build_session_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package image

import (
"bytes"
"path/filepath"
"testing"

"github.com/docker/docker/pkg/streamformatter"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/moby/buildkit/session"
"github.com/stretchr/testify/require"
)

func TestAddDirToSession(t *testing.T) {
dest := fs.NewDir(t, "test-build-session",
fs.WithFile("Dockerfile", `
FROM alpine:3.6
COPY foo /
`),
fs.WithFile("foo", "some content", fs.AsUser(65534, 65534)),
)
defer dest.Remove()

contextDir := dest.Path()
sharedKey, err := getBuildSharedKey(contextDir)
require.NoError(t, err)

var s *session.Session
s, err = session.NewSession(filepath.Base(contextDir), sharedKey)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnephin @tonistiigi ok I guess the best is to mock/fake the session here instead of using the true one. @tonistiigi does it worth that builkit provides a session faker at some point? I can put it in the cli ATM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the CLI depend on a type Session interface{...} instead of the struct would be great, then it should be easy for us to fake.

A fake as part of the CLI testing code sounds fine to me.

require.NoError(t, err)

syncDone := make(chan error)
progressOutput := streamformatter.NewProgressOutput(new(bytes.Buffer))
err = addDirToSession(s, contextDir, progressOutput, syncDone)
// Needs some assertions here to ensure we reset uid/gid to 0 for example
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ github.com/mattn/go-shellwords v1.0.3
github.com/Microsoft/go-winio v0.4.4
github.com/miekg/pkcs11 df8ae6ca730422dba20c768ff38ef7d79077a59f
github.com/mitchellh/mapstructure f3009df150dadf309fdee4a54ed65c124afad715
github.com/moby/buildkit da2b9dc7dab99e824b2b1067ad7d0523e32dd2d9 https://github.com/dmcgowan/buildkit.git
github.com/moby/buildkit c2dbdeb457ea665699a5d97f79eebfac4ab4726f https://github.com/tonistiigi/buildkit.git
github.com/tonistiigi/fsutil 1dedf6e90084bd88c4c518a15e68a37ed1370203
github.com/Nvveen/Gotty a8b993ba6abdb0e0c12b0125c603323a71c7790c https://github.com/ijc25/Gotty
github.com/opencontainers/go-digest 21dfd564fd89c944783d00d069f33e3e7123c448
github.com/opencontainers/image-spec v1.0.0
Expand All @@ -40,7 +41,6 @@ github.com/spf13/cobra v1.5.1 https://github.com/dnephin/cobra.git
github.com/spf13/pflag 9ff6c6923cfffbcd502984b8e0c80539a94968b7
github.com/stevvooe/continuity cd7a8e21e2b6f84799f5dd4b65faf49c8d3ee02d
github.com/stretchr/testify 4d4bfba8f1d1027c4fdbe371823030df51419987
github.com/tonistiigi/fsutil 0ac4c11b053b9c5c7c47558f81f96c7100ce50fb
github.com/xeipuuv/gojsonpointer e0fe6f68307607d540ed8eac07a342c33fa1b54a
github.com/xeipuuv/gojsonreference e02fc20de94c78484cd5ffb007f8af96be030a45
github.com/xeipuuv/gojsonschema 93e72a773fade158921402d6a24c819b48aba29d
Expand Down
70 changes: 0 additions & 70 deletions vendor/github.com/docker/docker/pkg/chrootarchive/archive.go

This file was deleted.

86 changes: 0 additions & 86 deletions vendor/github.com/docker/docker/pkg/chrootarchive/archive_unix.go

This file was deleted.

This file was deleted.

108 changes: 0 additions & 108 deletions vendor/github.com/docker/docker/pkg/chrootarchive/chroot_linux.go

This file was deleted.

Loading