2020-08-05 01:11:32 +00:00
|
|
|
package gateway
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-09-15 06:40:05 +00:00
|
|
|
"fmt"
|
2020-10-27 21:51:51 +00:00
|
|
|
"runtime"
|
2020-09-15 06:40:05 +00:00
|
|
|
"sort"
|
2020-08-05 01:11:32 +00:00
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/cache"
|
|
|
|
"github.com/moby/buildkit/executor"
|
|
|
|
"github.com/moby/buildkit/frontend/gateway/client"
|
2020-09-15 06:40:05 +00:00
|
|
|
"github.com/moby/buildkit/session"
|
2020-10-27 06:13:39 +00:00
|
|
|
"github.com/moby/buildkit/snapshot"
|
2020-09-15 06:40:05 +00:00
|
|
|
"github.com/moby/buildkit/solver/llbsolver/mounts"
|
2020-08-05 01:11:32 +00:00
|
|
|
opspb "github.com/moby/buildkit/solver/pb"
|
|
|
|
"github.com/moby/buildkit/util/stack"
|
|
|
|
utilsystem "github.com/moby/buildkit/util/system"
|
|
|
|
"github.com/moby/buildkit/worker"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
)
|
|
|
|
|
|
|
|
type NewContainerRequest struct {
|
2020-10-02 05:36:33 +00:00
|
|
|
ContainerID string
|
|
|
|
NetMode opspb.NetMode
|
|
|
|
Mounts []Mount
|
2020-10-27 21:51:51 +00:00
|
|
|
Platform *opspb.Platform
|
|
|
|
Constraints *opspb.WorkerConstraints
|
2020-08-05 01:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mount used for the gateway.Container is nearly identical to the client.Mount
|
|
|
|
// except is has a RefProxy instead of Ref to allow for a common abstraction
|
|
|
|
// between gateway clients.
|
|
|
|
type Mount struct {
|
2020-11-14 05:58:20 +00:00
|
|
|
*opspb.Mount
|
2020-10-28 21:07:44 +00:00
|
|
|
WorkerRef *worker.WorkerRef
|
2020-08-05 01:11:32 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
func NewContainer(ctx context.Context, w worker.Worker, sm *session.Manager, g session.Group, req NewContainerRequest) (client.Container, error) {
|
2020-08-05 01:11:32 +00:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
|
|
eg, ctx := errgroup.WithContext(ctx)
|
2020-10-27 21:51:51 +00:00
|
|
|
platform := opspb.Platform{
|
|
|
|
OS: runtime.GOOS,
|
|
|
|
Architecture: runtime.GOARCH,
|
|
|
|
}
|
|
|
|
if req.Platform != nil {
|
|
|
|
platform = *req.Platform
|
|
|
|
}
|
2020-08-05 01:11:32 +00:00
|
|
|
ctr := &gatewayContainer{
|
2020-10-02 05:36:33 +00:00
|
|
|
id: req.ContainerID,
|
|
|
|
netMode: req.NetMode,
|
2020-10-27 21:51:51 +00:00
|
|
|
platform: platform,
|
2020-11-14 05:58:20 +00:00
|
|
|
executor: w.Executor(),
|
2020-10-02 05:36:33 +00:00
|
|
|
errGroup: eg,
|
|
|
|
ctx: ctx,
|
|
|
|
cancel: cancel,
|
2020-08-05 01:11:32 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
var (
|
|
|
|
mnts []*opspb.Mount
|
|
|
|
refs []*worker.WorkerRef
|
|
|
|
)
|
|
|
|
for _, m := range req.Mounts {
|
|
|
|
mnts = append(mnts, m.Mount)
|
|
|
|
if m.WorkerRef != nil {
|
|
|
|
refs = append(refs, m.WorkerRef)
|
|
|
|
m.Mount.Input = opspb.InputIndex(len(refs) - 1)
|
|
|
|
} else {
|
|
|
|
m.Mount.Input = opspb.Empty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
name := fmt.Sprintf("container %s", req.ContainerID)
|
|
|
|
mm := mounts.NewMountManager(name, w.CacheManager(), sm, w.MetadataStore())
|
|
|
|
p, err := PrepareMounts(ctx, mm, w.CacheManager(), g, mnts, refs, func(m *opspb.Mount, ref cache.ImmutableRef) (cache.MutableRef, error) {
|
|
|
|
cm := w.CacheManager()
|
|
|
|
if m.Input != opspb.Empty {
|
|
|
|
cm = refs[m.Input].Worker.CacheManager()
|
2020-08-05 01:11:32 +00:00
|
|
|
}
|
2020-11-14 05:58:20 +00:00
|
|
|
return cm.New(ctx, ref, g)
|
|
|
|
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
for i := len(p.Actives) - 1; i >= 0; i-- { // call in LIFO order
|
2020-11-16 21:20:45 +00:00
|
|
|
p.Actives[i].Ref.Release(context.TODO())
|
2020-11-14 05:58:20 +00:00
|
|
|
}
|
|
|
|
for _, o := range p.OutputRefs {
|
|
|
|
o.Ref.Release(context.TODO())
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ctr.rootFS = p.Root
|
|
|
|
ctr.mounts = p.Mounts
|
|
|
|
|
|
|
|
for _, o := range p.OutputRefs {
|
2020-11-14 06:58:49 +00:00
|
|
|
o := o
|
2020-09-15 06:40:05 +00:00
|
|
|
ctr.cleanup = append(ctr.cleanup, func() error {
|
2020-11-14 05:58:20 +00:00
|
|
|
return o.Ref.Release(context.TODO())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
for _, active := range p.Actives {
|
2020-11-14 06:58:49 +00:00
|
|
|
active := active
|
2020-11-14 05:58:20 +00:00
|
|
|
ctr.cleanup = append(ctr.cleanup, func() error {
|
2020-11-16 21:20:45 +00:00
|
|
|
return active.Ref.Release(context.TODO())
|
2020-09-15 06:40:05 +00:00
|
|
|
})
|
|
|
|
}
|
2020-08-05 01:11:32 +00:00
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
return ctr, nil
|
|
|
|
}
|
2020-09-15 06:40:05 +00:00
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
type PreparedMounts struct {
|
|
|
|
Root executor.Mount
|
|
|
|
ReadonlyRootFS bool
|
|
|
|
Mounts []executor.Mount
|
2020-11-16 21:20:45 +00:00
|
|
|
OutputRefs []MountRef
|
|
|
|
Actives []MountMutableRef
|
2020-11-14 05:58:20 +00:00
|
|
|
}
|
2020-09-15 06:40:05 +00:00
|
|
|
|
2020-11-16 21:20:45 +00:00
|
|
|
type MountRef struct {
|
2020-11-14 05:58:20 +00:00
|
|
|
Ref cache.Ref
|
|
|
|
MountIndex int
|
|
|
|
}
|
2020-09-15 06:40:05 +00:00
|
|
|
|
2020-11-16 21:20:45 +00:00
|
|
|
type MountMutableRef struct {
|
|
|
|
Ref cache.MutableRef
|
|
|
|
MountIndex int
|
2021-02-03 07:20:44 +00:00
|
|
|
NoCommit bool
|
2020-11-16 21:20:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
type MakeMutable func(m *opspb.Mount, ref cache.ImmutableRef) (cache.MutableRef, error)
|
2020-09-15 06:40:05 +00:00
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
func PrepareMounts(ctx context.Context, mm *mounts.MountManager, cm cache.Manager, g session.Group, mnts []*opspb.Mount, refs []*worker.WorkerRef, makeMutable MakeMutable) (p PreparedMounts, err error) {
|
|
|
|
// loop over all mounts, fill in mounts, root and outputs
|
|
|
|
for i, m := range mnts {
|
|
|
|
var (
|
|
|
|
mountable cache.Mountable
|
|
|
|
ref cache.ImmutableRef
|
|
|
|
)
|
2020-09-15 06:40:05 +00:00
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
if m.Dest == opspb.RootMount && m.MountType != opspb.MountType_BIND {
|
|
|
|
return p, errors.Errorf("invalid mount type %s for %s", m.MountType.String(), m.Dest)
|
|
|
|
}
|
2020-09-15 06:40:05 +00:00
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
// if mount is based on input validate and load it
|
|
|
|
if m.Input != opspb.Empty {
|
2020-11-16 21:20:45 +00:00
|
|
|
if int(m.Input) >= len(refs) {
|
2020-11-14 05:58:20 +00:00
|
|
|
return p, errors.Errorf("missing input %d", m.Input)
|
2020-09-15 06:40:05 +00:00
|
|
|
}
|
2020-11-14 05:58:20 +00:00
|
|
|
ref = refs[int(m.Input)].ImmutableRef
|
|
|
|
mountable = ref
|
2020-09-15 06:40:05 +00:00
|
|
|
}
|
2020-11-14 05:58:20 +00:00
|
|
|
|
2020-09-15 06:40:05 +00:00
|
|
|
switch m.MountType {
|
|
|
|
case opspb.MountType_BIND:
|
2020-11-14 05:58:20 +00:00
|
|
|
// if mount creates an output
|
|
|
|
if m.Output != opspb.SkipOutput {
|
|
|
|
// if it is readonly and not root then output is the input
|
|
|
|
if m.Readonly && ref != nil && m.Dest != opspb.RootMount {
|
2020-11-16 21:20:45 +00:00
|
|
|
p.OutputRefs = append(p.OutputRefs, MountRef{
|
2020-11-14 05:58:20 +00:00
|
|
|
MountIndex: i,
|
|
|
|
Ref: ref.Clone(),
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
// otherwise output and mount is the mutable child
|
|
|
|
active, err := makeMutable(m, ref)
|
|
|
|
if err != nil {
|
|
|
|
return p, err
|
|
|
|
}
|
|
|
|
mountable = active
|
2020-11-16 21:20:45 +00:00
|
|
|
p.OutputRefs = append(p.OutputRefs, MountRef{
|
2020-11-14 05:58:20 +00:00
|
|
|
MountIndex: i,
|
|
|
|
Ref: active,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else if (!m.Readonly || ref == nil) && m.Dest != opspb.RootMount {
|
|
|
|
// this case is empty readonly scratch without output that is not really useful for anything but don't error
|
|
|
|
active, err := makeMutable(m, ref)
|
|
|
|
if err != nil {
|
|
|
|
return p, err
|
|
|
|
}
|
2020-11-16 21:20:45 +00:00
|
|
|
p.Actives = append(p.Actives, MountMutableRef{
|
|
|
|
MountIndex: i,
|
|
|
|
Ref: active,
|
|
|
|
})
|
2020-11-14 05:58:20 +00:00
|
|
|
mountable = active
|
|
|
|
}
|
|
|
|
|
2020-09-15 06:40:05 +00:00
|
|
|
case opspb.MountType_CACHE:
|
2020-11-14 05:58:20 +00:00
|
|
|
active, err := mm.MountableCache(ctx, m, ref, g)
|
2020-09-15 06:40:05 +00:00
|
|
|
if err != nil {
|
2020-11-14 05:58:20 +00:00
|
|
|
return p, err
|
|
|
|
}
|
|
|
|
mountable = active
|
2020-11-16 21:20:45 +00:00
|
|
|
p.Actives = append(p.Actives, MountMutableRef{
|
|
|
|
MountIndex: i,
|
|
|
|
Ref: active,
|
2021-02-03 07:20:44 +00:00
|
|
|
NoCommit: true,
|
2020-11-16 21:20:45 +00:00
|
|
|
})
|
2020-11-14 05:58:20 +00:00
|
|
|
if m.Output != opspb.SkipOutput && ref != nil {
|
2020-11-16 21:20:45 +00:00
|
|
|
p.OutputRefs = append(p.OutputRefs, MountRef{
|
2020-11-14 05:58:20 +00:00
|
|
|
MountIndex: i,
|
|
|
|
Ref: ref.Clone(),
|
|
|
|
})
|
2020-09-15 06:40:05 +00:00
|
|
|
}
|
2020-11-14 05:58:20 +00:00
|
|
|
|
2020-09-15 06:40:05 +00:00
|
|
|
case opspb.MountType_TMPFS:
|
|
|
|
mountable = mm.MountableTmpFS()
|
|
|
|
case opspb.MountType_SECRET:
|
|
|
|
var err error
|
2020-11-14 05:58:20 +00:00
|
|
|
mountable, err = mm.MountableSecret(ctx, m, g)
|
2020-09-15 06:40:05 +00:00
|
|
|
if err != nil {
|
2020-11-14 05:58:20 +00:00
|
|
|
return p, err
|
2020-09-15 06:40:05 +00:00
|
|
|
}
|
|
|
|
if mountable == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
case opspb.MountType_SSH:
|
|
|
|
var err error
|
2020-11-14 05:58:20 +00:00
|
|
|
mountable, err = mm.MountableSSH(ctx, m, g)
|
2020-09-15 06:40:05 +00:00
|
|
|
if err != nil {
|
2020-11-14 05:58:20 +00:00
|
|
|
return p, err
|
2020-09-15 06:40:05 +00:00
|
|
|
}
|
|
|
|
if mountable == nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-11-14 05:58:20 +00:00
|
|
|
|
2020-09-15 06:40:05 +00:00
|
|
|
default:
|
2020-11-14 05:58:20 +00:00
|
|
|
return p, errors.Errorf("mount type %s not implemented", m.MountType)
|
2020-09-15 06:40:05 +00:00
|
|
|
}
|
2020-09-11 16:48:24 +00:00
|
|
|
|
2020-09-15 06:40:05 +00:00
|
|
|
// validate that there is a mount
|
|
|
|
if mountable == nil {
|
2020-11-14 05:58:20 +00:00
|
|
|
return p, errors.Errorf("mount %s has no input", m.Dest)
|
2020-08-05 01:11:32 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
// if dest is root we need mutable ref even if there is no output
|
|
|
|
if m.Dest == opspb.RootMount {
|
|
|
|
root := mountable
|
|
|
|
p.ReadonlyRootFS = m.Readonly
|
|
|
|
if m.Output == opspb.SkipOutput && p.ReadonlyRootFS {
|
|
|
|
active, err := makeMutable(m, ref)
|
|
|
|
if err != nil {
|
|
|
|
return p, err
|
|
|
|
}
|
2020-11-16 21:20:45 +00:00
|
|
|
p.Actives = append(p.Actives, MountMutableRef{
|
|
|
|
MountIndex: i,
|
|
|
|
Ref: active,
|
|
|
|
})
|
2020-11-14 05:58:20 +00:00
|
|
|
root = active
|
|
|
|
}
|
|
|
|
p.Root = mountWithSession(root, g)
|
|
|
|
} else {
|
|
|
|
mws := mountWithSession(mountable, g)
|
|
|
|
mws.Dest = m.Dest
|
|
|
|
mws.Readonly = m.Readonly
|
|
|
|
mws.Selector = m.Selector
|
|
|
|
p.Mounts = append(p.Mounts, mws)
|
2020-08-05 01:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-15 06:40:05 +00:00
|
|
|
// sort mounts so parents are mounted first
|
2020-11-14 05:58:20 +00:00
|
|
|
sort.Slice(p.Mounts, func(i, j int) bool {
|
|
|
|
return p.Mounts[i].Dest < p.Mounts[j].Dest
|
2020-09-15 06:40:05 +00:00
|
|
|
})
|
|
|
|
|
2020-11-14 05:58:20 +00:00
|
|
|
return p, nil
|
2020-08-05 01:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type gatewayContainer struct {
|
2020-10-02 07:09:35 +00:00
|
|
|
id string
|
|
|
|
netMode opspb.NetMode
|
2020-10-27 21:51:51 +00:00
|
|
|
platform opspb.Platform
|
2020-11-02 07:55:46 +00:00
|
|
|
rootFS executor.Mount
|
2020-10-02 07:09:35 +00:00
|
|
|
mounts []executor.Mount
|
|
|
|
executor executor.Executor
|
|
|
|
started bool
|
|
|
|
errGroup *errgroup.Group
|
|
|
|
mu sync.Mutex
|
|
|
|
cleanup []func() error
|
|
|
|
ctx context.Context
|
|
|
|
cancel func()
|
2020-08-05 01:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gwCtr *gatewayContainer) Start(ctx context.Context, req client.StartRequest) (client.ContainerProcess, error) {
|
|
|
|
resize := make(chan executor.WinSize)
|
|
|
|
procInfo := executor.ProcessInfo{
|
|
|
|
Meta: executor.Meta{
|
|
|
|
Args: req.Args,
|
|
|
|
Env: req.Env,
|
|
|
|
User: req.User,
|
|
|
|
Cwd: req.Cwd,
|
|
|
|
Tty: req.Tty,
|
|
|
|
NetMode: gwCtr.netMode,
|
2020-10-02 05:36:33 +00:00
|
|
|
SecurityMode: req.SecurityMode,
|
2020-08-05 01:11:32 +00:00
|
|
|
},
|
|
|
|
Stdin: req.Stdin,
|
|
|
|
Stdout: req.Stdout,
|
|
|
|
Stderr: req.Stderr,
|
|
|
|
Resize: resize,
|
|
|
|
}
|
2020-10-02 20:54:00 +00:00
|
|
|
if procInfo.Meta.Cwd == "" {
|
|
|
|
procInfo.Meta.Cwd = "/"
|
|
|
|
}
|
2020-10-27 21:51:51 +00:00
|
|
|
procInfo.Meta.Env = addDefaultEnvvar(procInfo.Meta.Env, "PATH", utilsystem.DefaultPathEnv(gwCtr.platform.OS))
|
2020-08-05 01:11:32 +00:00
|
|
|
if req.Tty {
|
|
|
|
procInfo.Meta.Env = addDefaultEnvvar(procInfo.Meta.Env, "TERM", "xterm")
|
|
|
|
}
|
|
|
|
|
|
|
|
// mark that we have started on the first call to execProcess for this
|
|
|
|
// container, so that future calls will call Exec rather than Run
|
|
|
|
gwCtr.mu.Lock()
|
|
|
|
started := gwCtr.started
|
|
|
|
gwCtr.started = true
|
|
|
|
gwCtr.mu.Unlock()
|
|
|
|
|
|
|
|
eg, ctx := errgroup.WithContext(gwCtr.ctx)
|
|
|
|
gwProc := &gatewayContainerProcess{
|
|
|
|
resize: resize,
|
|
|
|
errGroup: eg,
|
|
|
|
groupCtx: ctx,
|
|
|
|
}
|
|
|
|
|
|
|
|
if !started {
|
|
|
|
startedCh := make(chan struct{})
|
|
|
|
gwProc.errGroup.Go(func() error {
|
|
|
|
logrus.Debugf("Starting new container for %s with args: %q", gwCtr.id, procInfo.Meta.Args)
|
|
|
|
err := gwCtr.executor.Run(ctx, gwCtr.id, gwCtr.rootFS, gwCtr.mounts, procInfo, startedCh)
|
|
|
|
return stack.Enable(err)
|
|
|
|
})
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
case <-startedCh:
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gwProc.errGroup.Go(func() error {
|
|
|
|
logrus.Debugf("Execing into container %s with args: %q", gwCtr.id, procInfo.Meta.Args)
|
|
|
|
err := gwCtr.executor.Exec(ctx, gwCtr.id, procInfo)
|
|
|
|
return stack.Enable(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
gwCtr.errGroup.Go(gwProc.errGroup.Wait)
|
|
|
|
|
|
|
|
return gwProc, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gwCtr *gatewayContainer) Release(ctx context.Context) error {
|
|
|
|
gwCtr.cancel()
|
|
|
|
err1 := gwCtr.errGroup.Wait()
|
|
|
|
|
|
|
|
var err2 error
|
|
|
|
for i := len(gwCtr.cleanup) - 1; i >= 0; i-- { // call in LIFO order
|
|
|
|
err := gwCtr.cleanup[i]()
|
|
|
|
if err2 == nil {
|
|
|
|
err2 = err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err1 != nil {
|
|
|
|
return stack.Enable(err1)
|
|
|
|
}
|
|
|
|
return stack.Enable(err2)
|
|
|
|
}
|
|
|
|
|
|
|
|
type gatewayContainerProcess struct {
|
|
|
|
errGroup *errgroup.Group
|
|
|
|
groupCtx context.Context
|
|
|
|
resize chan<- executor.WinSize
|
|
|
|
mu sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gwProc *gatewayContainerProcess) Wait() error {
|
|
|
|
err := stack.Enable(gwProc.errGroup.Wait())
|
|
|
|
gwProc.mu.Lock()
|
|
|
|
defer gwProc.mu.Unlock()
|
|
|
|
close(gwProc.resize)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gwProc *gatewayContainerProcess) Resize(ctx context.Context, size client.WinSize) error {
|
|
|
|
gwProc.mu.Lock()
|
|
|
|
defer gwProc.mu.Unlock()
|
|
|
|
|
|
|
|
// is the container done or should we proceed with sending event?
|
|
|
|
select {
|
|
|
|
case <-gwProc.groupCtx.Done():
|
|
|
|
return nil
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
// now we select on contexts again in case p.resize blocks b/c
|
|
|
|
// container no longer reading from it. In that case when
|
|
|
|
// the errgroup finishes we want to unblock on the write
|
|
|
|
// and exit
|
|
|
|
select {
|
|
|
|
case <-gwProc.groupCtx.Done():
|
|
|
|
case <-ctx.Done():
|
|
|
|
case gwProc.resize <- executor.WinSize{Cols: size.Cols, Rows: size.Rows}:
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func addDefaultEnvvar(env []string, k, v string) []string {
|
|
|
|
for _, e := range env {
|
|
|
|
if strings.HasPrefix(e, k+"=") {
|
|
|
|
return env
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return append(env, k+"="+v)
|
|
|
|
}
|
2020-10-27 06:13:39 +00:00
|
|
|
|
2020-11-02 07:55:46 +00:00
|
|
|
func mountWithSession(m cache.Mountable, g session.Group) executor.Mount {
|
|
|
|
_, readonly := m.(cache.ImmutableRef)
|
|
|
|
return executor.Mount{
|
2020-11-14 05:58:20 +00:00
|
|
|
Src: &mountable{m: m, g: g},
|
2020-11-02 07:55:46 +00:00
|
|
|
Readonly: readonly,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 06:13:39 +00:00
|
|
|
type mountable struct {
|
|
|
|
m cache.Mountable
|
|
|
|
g session.Group
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mountable) Mount(ctx context.Context, readonly bool) (snapshot.Mountable, error) {
|
|
|
|
return m.m.Mount(ctx, readonly, m.g)
|
|
|
|
}
|