2018-02-05 16:05:59 -05:00
|
|
|
package dockerfile // import "github.com/docker/docker/builder/dockerfile"
|
2017-05-15 17:54:27 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/builder/fscache"
|
|
|
|
"github.com/docker/docker/builder/remotecontext"
|
2017-07-28 19:04:34 -04:00
|
|
|
"github.com/moby/buildkit/session"
|
|
|
|
"github.com/moby/buildkit/session/filesync"
|
2017-05-15 17:54:27 -04:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
const sessionConnectTimeout = 5 * time.Second
|
|
|
|
|
|
|
|
// ClientSessionTransport is a transport for copying files from docker client
|
|
|
|
// to the daemon.
|
|
|
|
type ClientSessionTransport struct{}
|
|
|
|
|
|
|
|
// NewClientSessionTransport returns new ClientSessionTransport instance
|
|
|
|
func NewClientSessionTransport() *ClientSessionTransport {
|
|
|
|
return &ClientSessionTransport{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy data from a remote to a destination directory.
|
|
|
|
func (cst *ClientSessionTransport) Copy(ctx context.Context, id fscache.RemoteIdentifier, dest string, cu filesync.CacheUpdater) error {
|
|
|
|
csi, ok := id.(*ClientSessionSourceIdentifier)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("invalid identifier for client session")
|
|
|
|
}
|
|
|
|
|
|
|
|
return filesync.FSSync(ctx, csi.caller, filesync.FSSendRequestOpt{
|
2017-06-28 01:41:00 -04:00
|
|
|
IncludePatterns: csi.includePatterns,
|
|
|
|
DestDir: dest,
|
|
|
|
CacheUpdater: cu,
|
2017-05-15 17:54:27 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClientSessionSourceIdentifier is an identifier that can be used for requesting
|
|
|
|
// files from remote client
|
|
|
|
type ClientSessionSourceIdentifier struct {
|
2017-06-28 01:41:00 -04:00
|
|
|
includePatterns []string
|
|
|
|
caller session.Caller
|
|
|
|
uuid string
|
2017-05-15 17:54:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewClientSessionSourceIdentifier returns new ClientSessionSourceIdentifier instance
|
2017-06-28 01:41:00 -04:00
|
|
|
func NewClientSessionSourceIdentifier(ctx context.Context, sg SessionGetter, uuid string) (*ClientSessionSourceIdentifier, error) {
|
2017-05-15 17:54:27 -04:00
|
|
|
csi := &ClientSessionSourceIdentifier{
|
2017-06-28 01:41:00 -04:00
|
|
|
uuid: uuid,
|
2017-05-15 17:54:27 -04:00
|
|
|
}
|
|
|
|
caller, err := sg.Get(ctx, uuid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "failed to get session for %s", uuid)
|
|
|
|
}
|
|
|
|
|
|
|
|
csi.caller = caller
|
|
|
|
return csi, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transport returns transport identifier for remote identifier
|
|
|
|
func (csi *ClientSessionSourceIdentifier) Transport() string {
|
|
|
|
return remotecontext.ClientSessionRemote
|
|
|
|
}
|
|
|
|
|
|
|
|
// SharedKey returns shared key for remote identifier. Shared key is used
|
|
|
|
// for finding the base for a repeated transfer.
|
|
|
|
func (csi *ClientSessionSourceIdentifier) SharedKey() string {
|
|
|
|
return csi.caller.SharedKey()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Key returns unique key for remote identifier. Requests with same key return
|
|
|
|
// same data.
|
|
|
|
func (csi *ClientSessionSourceIdentifier) Key() string {
|
|
|
|
return csi.uuid
|
|
|
|
}
|