@@ -2,7 +2,6 @@ package dockerfile
22
33import (
44 "bytes"
5- "errors"
65 "fmt"
76 "io"
87 "io/ioutil"
@@ -21,9 +20,10 @@ import (
2120 "github.com/docker/docker/builder"
2221 "github.com/docker/docker/builder/dockerfile/parser"
2322 "github.com/docker/docker/client/session"
23+ "github.com/docker/docker/client/session/ssh"
2424 "github.com/docker/docker/image"
2525 "github.com/docker/docker/pkg/stringid"
26- perrors "github.com/pkg/errors"
26+ "github.com/pkg/errors"
2727 "golang.org/x/net/context"
2828)
2929
@@ -72,6 +72,7 @@ type Builder struct {
7272 fsCache * FSCache
7373 sessionGetter SessionGetter
7474 auth AuthConfigProvider
75+ sshAuthSock string
7576
7677 dockerfile * parser.Node
7778 runConfig * container.Config // runconfig for cmd, run, entrypoint etc.
@@ -119,14 +120,14 @@ func NewBuildManager(b builder.Backend, sg SessionGetter) (*BuildManager, error)
119120
120121 tmpdir , err := ioutil .TempDir ("" , "fscache" )
121122 if err != nil {
122- return nil , perrors .Wrap (err , "failed to create tmp directory" )
123+ return nil , errors .Wrap (err , "failed to create tmp directory" )
123124 }
124125
125126 fsCache , err := NewFSCache (FSCacheOpt {
126127 Backend : & tmpCacheBackend {tmpdir },
127128 })
128129 if err != nil {
129- return nil , perrors .Wrap (err , "failed to create fscache" )
130+ return nil , errors .Wrap (err , "failed to create fscache" )
130131 }
131132 bm .fsCache = fsCache
132133 fsCache .RegisterTransport (ClientSessionTransportName , NewClientSessionTransport ())
@@ -292,7 +293,7 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
292293 defer cancel ()
293294 _ , caller , err := b .sessionGetter .GetSession (ctx , b .options .SessionId )
294295 if err != nil {
295- return "" , perrors .Wrapf (err , "failed to get session for %s" , b .options .SessionId )
296+ return "" , errors .Wrapf (err , "failed to get session for %s" , b .options .SessionId )
296297 }
297298
298299 if b .options .RemoteContext == "client-session" {
@@ -310,6 +311,18 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
310311 }
311312
312313 b .auth = NewAuthConfigProvider (b .options .AuthConfigs , caller )
314+ sshProvider , err := ssh .NewSSHAuthProvider ("_main" , caller )
315+ if err != nil && errors .Cause (err ) != ssh .ErrNotSupported {
316+ return "" , err
317+ }
318+ // TODO: lazy create
319+ sock , release , err := sshProvider .CreateListenSocket ()
320+ if err != nil {
321+ return "" , err
322+ }
323+ defer release ()
324+ b .sshAuthSock = sock
325+
313326 logrus .Debugf ("sync-time: %v" , time .Since (st ))
314327 } else {
315328 b .auth = NewAuthConfigProvider (b .options .AuthConfigs , nil )
@@ -326,7 +339,7 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
326339 total := len (b .dockerfile .Children )
327340 for _ , n := range b .dockerfile .Children {
328341 if err := b .checkDispatch (n , false ); err != nil {
329- return "" , perrors .Wrapf (err , "Dockerfile parse error line %d" , n .StartLine )
342+ return "" , errors .Wrapf (err , "Dockerfile parse error line %d" , n .StartLine )
330343 }
331344 }
332345
@@ -367,7 +380,7 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
367380 }
368381 b .image , err = b .docker .SquashImage (b .image , fromID )
369382 if err != nil {
370- return "" , perrors .Wrap (err , "error squashing image" )
383+ return "" , errors .Wrap (err , "error squashing image" )
371384 }
372385 }
373386
@@ -459,7 +472,7 @@ type tmpCacheBackend struct {
459472func (tcb * tmpCacheBackend ) Get (id string ) (string , error ) {
460473 d := filepath .Join (tcb .root , id )
461474 if err := os .MkdirAll (d , 0700 ); err != nil {
462- return "" , perrors .Wrapf (err , "failed to create tmp dir for %s" , d )
475+ return "" , errors .Wrapf (err , "failed to create tmp dir for %s" , d )
463476 }
464477 return d , nil
465478}
0 commit comments