2018-04-13 21:03:55 +00:00
|
|
|
package ops
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2018-08-01 21:15:43 +00:00
|
|
|
"net"
|
2018-05-25 18:15:32 +00:00
|
|
|
"os"
|
2018-04-13 21:03:55 +00:00
|
|
|
"path"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
|
2019-02-27 22:53:52 +00:00
|
|
|
"github.com/containerd/containerd/platforms"
|
2018-04-13 21:03:55 +00:00
|
|
|
"github.com/moby/buildkit/cache"
|
2018-05-15 19:09:09 +00:00
|
|
|
"github.com/moby/buildkit/cache/metadata"
|
2018-04-13 21:03:55 +00:00
|
|
|
"github.com/moby/buildkit/executor"
|
2018-07-19 21:44:18 +00:00
|
|
|
"github.com/moby/buildkit/session"
|
2020-10-27 06:13:39 +00:00
|
|
|
"github.com/moby/buildkit/snapshot"
|
2018-05-11 05:58:41 +00:00
|
|
|
"github.com/moby/buildkit/solver"
|
|
|
|
"github.com/moby/buildkit/solver/llbsolver"
|
2020-10-28 21:07:44 +00:00
|
|
|
"github.com/moby/buildkit/solver/llbsolver/errdefs"
|
2020-09-15 06:40:05 +00:00
|
|
|
"github.com/moby/buildkit/solver/llbsolver/mounts"
|
2018-04-13 21:03:55 +00:00
|
|
|
"github.com/moby/buildkit/solver/pb"
|
|
|
|
"github.com/moby/buildkit/util/progress/logs"
|
2018-09-20 12:57:28 +00:00
|
|
|
utilsystem "github.com/moby/buildkit/util/system"
|
2018-04-13 21:03:55 +00:00
|
|
|
"github.com/moby/buildkit/worker"
|
|
|
|
digest "github.com/opencontainers/go-digest"
|
2019-02-27 22:53:52 +00:00
|
|
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
2018-04-13 21:03:55 +00:00
|
|
|
"github.com/pkg/errors"
|
2018-05-15 19:09:09 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-04-13 21:03:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const execCacheType = "buildkit.exec.v0"
|
|
|
|
|
|
|
|
type execOp struct {
|
|
|
|
op *pb.ExecOp
|
|
|
|
cm cache.Manager
|
2020-10-02 05:41:18 +00:00
|
|
|
mm *mounts.MountManager
|
2018-04-13 21:03:55 +00:00
|
|
|
exec executor.Executor
|
|
|
|
w worker.Worker
|
2019-02-27 22:53:52 +00:00
|
|
|
platform *pb.Platform
|
2018-04-13 21:03:55 +00:00
|
|
|
numInputs int
|
|
|
|
}
|
|
|
|
|
2019-02-27 22:53:52 +00:00
|
|
|
func NewExecOp(v solver.Vertex, op *pb.Op_Exec, platform *pb.Platform, cm cache.Manager, sm *session.Manager, md *metadata.Store, exec executor.Executor, w worker.Worker) (solver.Op, error) {
|
2019-06-15 00:26:27 +00:00
|
|
|
if err := llbsolver.ValidateOp(&pb.Op{Op: op}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-15 06:40:05 +00:00
|
|
|
name := fmt.Sprintf("exec %s", strings.Join(op.Exec.Meta.Args, " "))
|
2018-04-13 21:03:55 +00:00
|
|
|
return &execOp{
|
2020-09-15 06:40:05 +00:00
|
|
|
op: op.Exec,
|
|
|
|
mm: mounts.NewMountManager(name, cm, sm, md),
|
|
|
|
cm: cm,
|
|
|
|
exec: exec,
|
|
|
|
numInputs: len(v.Inputs()),
|
|
|
|
w: w,
|
|
|
|
platform: platform,
|
2018-04-13 21:03:55 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func cloneExecOp(old *pb.ExecOp) pb.ExecOp {
|
|
|
|
n := *old
|
2018-05-20 21:48:35 +00:00
|
|
|
meta := *n.Meta
|
2018-08-01 21:15:43 +00:00
|
|
|
meta.ExtraHosts = nil
|
|
|
|
for i := range n.Meta.ExtraHosts {
|
|
|
|
h := *n.Meta.ExtraHosts[i]
|
|
|
|
meta.ExtraHosts = append(meta.ExtraHosts, &h)
|
|
|
|
}
|
2018-05-20 21:48:35 +00:00
|
|
|
n.Meta = &meta
|
2018-04-13 21:03:55 +00:00
|
|
|
n.Mounts = nil
|
|
|
|
for i := range n.Mounts {
|
|
|
|
m := *n.Mounts[i]
|
|
|
|
n.Mounts = append(n.Mounts, &m)
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
2020-06-30 01:06:02 +00:00
|
|
|
func (e *execOp) CacheMap(ctx context.Context, g session.Group, index int) (*solver.CacheMap, bool, error) {
|
2018-04-13 21:03:55 +00:00
|
|
|
op := cloneExecOp(e.op)
|
2018-08-01 21:15:43 +00:00
|
|
|
for i := range op.Meta.ExtraHosts {
|
|
|
|
h := op.Meta.ExtraHosts[i]
|
|
|
|
h.IP = ""
|
|
|
|
op.Meta.ExtraHosts[i] = h
|
|
|
|
}
|
2018-04-13 21:03:55 +00:00
|
|
|
for i := range op.Mounts {
|
|
|
|
op.Mounts[i].Selector = ""
|
|
|
|
}
|
2018-05-20 21:48:35 +00:00
|
|
|
op.Meta.ProxyEnv = nil
|
2018-04-13 21:03:55 +00:00
|
|
|
|
2019-02-27 22:53:52 +00:00
|
|
|
p := platforms.DefaultSpec()
|
|
|
|
if e.platform != nil {
|
|
|
|
p = specs.Platform{
|
|
|
|
OS: e.platform.OS,
|
|
|
|
Architecture: e.platform.Architecture,
|
|
|
|
Variant: e.platform.Variant,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:03:55 +00:00
|
|
|
dt, err := json.Marshal(struct {
|
2019-02-27 22:53:52 +00:00
|
|
|
Type string
|
|
|
|
Exec *pb.ExecOp
|
|
|
|
OS string
|
|
|
|
Arch string
|
|
|
|
Variant string `json:",omitempty"`
|
2018-04-13 21:03:55 +00:00
|
|
|
}{
|
2019-02-27 22:53:52 +00:00
|
|
|
Type: execCacheType,
|
|
|
|
Exec: &op,
|
|
|
|
OS: p.OS,
|
|
|
|
Arch: p.Architecture,
|
|
|
|
Variant: p.Variant,
|
2018-04-13 21:03:55 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2018-04-24 21:00:58 +00:00
|
|
|
return nil, false, err
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cm := &solver.CacheMap{
|
|
|
|
Digest: digest.FromBytes(dt),
|
|
|
|
Deps: make([]struct {
|
|
|
|
Selector digest.Digest
|
|
|
|
ComputeDigestFunc solver.ResultBasedCacheFunc
|
2020-10-31 03:55:33 +00:00
|
|
|
PreprocessFunc solver.PreprocessFunc
|
2018-04-13 21:03:55 +00:00
|
|
|
}, e.numInputs),
|
|
|
|
}
|
|
|
|
|
|
|
|
deps, err := e.getMountDeps()
|
|
|
|
if err != nil {
|
2018-04-24 21:00:58 +00:00
|
|
|
return nil, false, err
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, dep := range deps {
|
|
|
|
if len(dep.Selectors) != 0 {
|
|
|
|
dgsts := make([][]byte, 0, len(dep.Selectors))
|
|
|
|
for _, p := range dep.Selectors {
|
|
|
|
dgsts = append(dgsts, []byte(p))
|
|
|
|
}
|
|
|
|
cm.Deps[i].Selector = digest.FromBytes(bytes.Join(dgsts, []byte{0}))
|
|
|
|
}
|
|
|
|
if !dep.NoContentBasedHash {
|
2019-02-27 22:40:45 +00:00
|
|
|
cm.Deps[i].ComputeDigestFunc = llbsolver.NewContentHashFunc(toSelectors(dedupePaths(dep.Selectors)))
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
2020-10-31 03:55:33 +00:00
|
|
|
cm.Deps[i].PreprocessFunc = llbsolver.UnlazyResultFunc
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 21:00:58 +00:00
|
|
|
return cm, true, nil
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func dedupePaths(inp []string) []string {
|
|
|
|
old := make(map[string]struct{}, len(inp))
|
|
|
|
for _, p := range inp {
|
|
|
|
old[p] = struct{}{}
|
|
|
|
}
|
|
|
|
paths := make([]string, 0, len(old))
|
|
|
|
for p1 := range old {
|
|
|
|
var skip bool
|
|
|
|
for p2 := range old {
|
2019-03-06 01:58:36 +00:00
|
|
|
if p1 != p2 && strings.HasPrefix(p1, p2+"/") {
|
2018-04-13 21:03:55 +00:00
|
|
|
skip = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !skip {
|
|
|
|
paths = append(paths, p1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Slice(paths, func(i, j int) bool {
|
|
|
|
return paths[i] < paths[j]
|
|
|
|
})
|
|
|
|
return paths
|
|
|
|
}
|
|
|
|
|
2019-02-27 22:40:45 +00:00
|
|
|
func toSelectors(p []string) []llbsolver.Selector {
|
|
|
|
sel := make([]llbsolver.Selector, 0, len(p))
|
|
|
|
for _, p := range p {
|
2019-03-03 00:45:45 +00:00
|
|
|
sel = append(sel, llbsolver.Selector{Path: p, FollowLinks: true})
|
2019-02-27 22:40:45 +00:00
|
|
|
}
|
|
|
|
return sel
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:03:55 +00:00
|
|
|
type dep struct {
|
|
|
|
Selectors []string
|
|
|
|
NoContentBasedHash bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *execOp) getMountDeps() ([]dep, error) {
|
|
|
|
deps := make([]dep, e.numInputs)
|
|
|
|
for _, m := range e.op.Mounts {
|
|
|
|
if m.Input == pb.Empty {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if int(m.Input) >= len(deps) {
|
|
|
|
return nil, errors.Errorf("invalid mountinput %v", m)
|
|
|
|
}
|
|
|
|
|
|
|
|
sel := m.Selector
|
|
|
|
if sel != "" {
|
|
|
|
sel = path.Join("/", sel)
|
|
|
|
deps[m.Input].Selectors = append(deps[m.Input].Selectors, sel)
|
|
|
|
}
|
|
|
|
|
2019-04-03 02:19:10 +00:00
|
|
|
if (!m.Readonly || m.Dest == pb.RootMount) && m.Output != -1 { // exclude read-only rootfs && read-write mounts
|
2018-04-13 21:03:55 +00:00
|
|
|
deps[m.Input].NoContentBasedHash = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deps, nil
|
|
|
|
}
|
|
|
|
|
2018-09-20 12:57:28 +00:00
|
|
|
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-11-05 00:51:53 +00:00
|
|
|
func (e *execOp) Exec(ctx context.Context, g session.Group, inputs []solver.Result) (refs []solver.Result, err error) {
|
2018-04-13 21:03:55 +00:00
|
|
|
var mounts []executor.Mount
|
|
|
|
var root cache.Mountable
|
|
|
|
var readonlyRootFS bool
|
|
|
|
|
|
|
|
var outputs []cache.Ref
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
for _, o := range outputs {
|
|
|
|
if o != nil {
|
|
|
|
go o.Release(context.TODO())
|
|
|
|
}
|
|
|
|
}
|
2020-11-05 00:51:53 +00:00
|
|
|
if err != nil {
|
|
|
|
err = errdefs.WithExecError(errors.Wrapf(err, "executor failed running %v", e.op.Meta.Args), inputs, refs)
|
|
|
|
}
|
2018-04-13 21:03:55 +00:00
|
|
|
}()
|
|
|
|
|
2018-05-15 17:37:56 +00:00
|
|
|
// loop over all mounts, fill in mounts, root and outputs
|
2018-04-13 21:03:55 +00:00
|
|
|
for _, m := range e.op.Mounts {
|
|
|
|
var mountable cache.Mountable
|
|
|
|
var ref cache.ImmutableRef
|
2018-05-15 17:37:56 +00:00
|
|
|
|
2018-05-15 19:09:09 +00:00
|
|
|
if m.Dest == pb.RootMount && m.MountType != pb.MountType_BIND {
|
|
|
|
return nil, errors.Errorf("invalid mount type %s for %s", m.MountType.String(), m.Dest)
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:37:56 +00:00
|
|
|
// if mount is based on input validate and load it
|
2018-04-13 21:03:55 +00:00
|
|
|
if m.Input != pb.Empty {
|
|
|
|
if int(m.Input) > len(inputs) {
|
|
|
|
return nil, errors.Errorf("missing input %d", m.Input)
|
|
|
|
}
|
|
|
|
inp := inputs[int(m.Input)]
|
|
|
|
workerRef, ok := inp.Sys().(*worker.WorkerRef)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.Errorf("invalid reference for exec %T", inp.Sys())
|
|
|
|
}
|
|
|
|
ref = workerRef.ImmutableRef
|
|
|
|
mountable = ref
|
|
|
|
}
|
|
|
|
|
2019-08-09 04:02:19 +00:00
|
|
|
makeMutable := func(ref cache.ImmutableRef) (cache.MutableRef, error) {
|
2018-04-13 21:03:55 +00:00
|
|
|
desc := fmt.Sprintf("mount %s from exec %s", m.Dest, strings.Join(e.op.Meta.Args, " "))
|
2020-10-27 06:13:39 +00:00
|
|
|
return e.cm.New(ctx, ref, g, cache.WithDescription(desc))
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 19:09:09 +00:00
|
|
|
switch m.MountType {
|
|
|
|
case pb.MountType_BIND:
|
|
|
|
// if mount creates an output
|
|
|
|
if m.Output != pb.SkipOutput {
|
2020-09-15 06:40:05 +00:00
|
|
|
// if it is readonly and not root then output is the input
|
2018-05-15 19:09:09 +00:00
|
|
|
if m.Readonly && ref != nil && m.Dest != pb.RootMount {
|
|
|
|
outputs = append(outputs, ref.Clone())
|
|
|
|
} else {
|
|
|
|
// otherwise output and mount is the mutable child
|
|
|
|
active, err := makeMutable(ref)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
outputs = append(outputs, active)
|
|
|
|
mountable = active
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
2019-08-09 04:02:19 +00:00
|
|
|
} else if (!m.Readonly || ref == nil) && m.Dest != pb.RootMount {
|
2018-06-07 20:54:04 +00:00
|
|
|
// this case is empty readonly scratch without output that is not really useful for anything but don't error
|
|
|
|
active, err := makeMutable(ref)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer active.Release(context.TODO())
|
|
|
|
mountable = active
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
2018-06-07 20:54:04 +00:00
|
|
|
|
2018-05-15 19:09:09 +00:00
|
|
|
case pb.MountType_CACHE:
|
2020-10-27 06:13:39 +00:00
|
|
|
mRef, err := e.mm.MountableCache(ctx, m, ref, g)
|
2018-05-15 19:09:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
mountable = mRef
|
|
|
|
defer func() {
|
|
|
|
go mRef.Release(context.TODO())
|
|
|
|
}()
|
|
|
|
if m.Output != pb.SkipOutput && ref != nil {
|
|
|
|
outputs = append(outputs, ref.Clone())
|
|
|
|
}
|
2018-06-08 05:28:52 +00:00
|
|
|
|
|
|
|
case pb.MountType_TMPFS:
|
2020-09-15 06:40:05 +00:00
|
|
|
mountable = e.mm.MountableTmpFS()
|
2018-07-19 21:44:18 +00:00
|
|
|
case pb.MountType_SECRET:
|
2020-09-15 06:40:05 +00:00
|
|
|
var err error
|
|
|
|
mountable, err = e.mm.MountableSecret(ctx, m, g)
|
2018-07-19 21:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-15 06:40:05 +00:00
|
|
|
if mountable == nil {
|
2018-07-19 21:44:18 +00:00
|
|
|
continue
|
|
|
|
}
|
2018-09-04 23:33:07 +00:00
|
|
|
case pb.MountType_SSH:
|
2020-09-15 06:40:05 +00:00
|
|
|
var err error
|
|
|
|
mountable, err = e.mm.MountableSSH(ctx, m, g)
|
2018-09-04 23:33:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-15 06:40:05 +00:00
|
|
|
if mountable == nil {
|
2018-09-04 23:33:07 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-05-15 19:09:09 +00:00
|
|
|
default:
|
|
|
|
return nil, errors.Errorf("mount type %s not implemented", m.MountType)
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 17:37:56 +00:00
|
|
|
// validate that there is a mount
|
2018-04-13 21:03:55 +00:00
|
|
|
if mountable == nil {
|
|
|
|
return nil, errors.Errorf("mount %s has no input", m.Dest)
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:37:56 +00:00
|
|
|
// if dest is root we need mutable ref even if there is no output
|
2018-04-13 21:03:55 +00:00
|
|
|
if m.Dest == pb.RootMount {
|
|
|
|
root = mountable
|
|
|
|
readonlyRootFS = m.Readonly
|
|
|
|
if m.Output == pb.SkipOutput && readonlyRootFS {
|
2018-05-15 17:37:56 +00:00
|
|
|
active, err := makeMutable(ref)
|
2018-04-13 21:03:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
go active.Release(context.TODO())
|
|
|
|
}()
|
|
|
|
root = active
|
|
|
|
}
|
|
|
|
} else {
|
2020-11-02 07:55:46 +00:00
|
|
|
mws := mountWithSession(mountable, g)
|
|
|
|
mws.Dest = m.Dest
|
|
|
|
mws.Readonly = m.Readonly
|
|
|
|
mws.Selector = m.Selector
|
|
|
|
mounts = append(mounts, mws)
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:37:56 +00:00
|
|
|
// sort mounts so parents are mounted first
|
2018-04-13 21:03:55 +00:00
|
|
|
sort.Slice(mounts, func(i, j int) bool {
|
|
|
|
return mounts[i].Dest < mounts[j].Dest
|
|
|
|
})
|
|
|
|
|
2018-08-01 21:15:43 +00:00
|
|
|
extraHosts, err := parseExtraHosts(e.op.Meta.ExtraHosts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-06-03 02:05:32 +00:00
|
|
|
emu, err := getEmulator(e.platform, e.cm.IdentityMapping())
|
|
|
|
if err == nil && emu != nil {
|
|
|
|
e.op.Meta.Args = append([]string{qemuMountName}, e.op.Meta.Args...)
|
|
|
|
|
|
|
|
mounts = append(mounts, executor.Mount{
|
|
|
|
Readonly: true,
|
|
|
|
Src: emu,
|
|
|
|
Dest: qemuMountName,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warn(err.Error()) // TODO: remove this with pull support
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:03:55 +00:00
|
|
|
meta := executor.Meta{
|
|
|
|
Args: e.op.Meta.Args,
|
|
|
|
Env: e.op.Meta.Env,
|
|
|
|
Cwd: e.op.Meta.Cwd,
|
|
|
|
User: e.op.Meta.User,
|
2020-06-16 14:49:44 +00:00
|
|
|
Hostname: e.op.Meta.Hostname,
|
2018-04-13 21:03:55 +00:00
|
|
|
ReadonlyRootFS: readonlyRootFS,
|
2018-08-01 21:15:43 +00:00
|
|
|
ExtraHosts: extraHosts,
|
2018-08-04 19:42:01 +00:00
|
|
|
NetMode: e.op.Network,
|
2019-01-10 02:24:25 +00:00
|
|
|
SecurityMode: e.op.Security,
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-20 21:48:35 +00:00
|
|
|
if e.op.Meta.ProxyEnv != nil {
|
|
|
|
meta.Env = append(meta.Env, proxyEnvList(e.op.Meta.ProxyEnv)...)
|
|
|
|
}
|
2020-10-23 18:17:41 +00:00
|
|
|
var currentOS string
|
|
|
|
if e.platform != nil {
|
|
|
|
currentOS = e.platform.OS
|
|
|
|
}
|
|
|
|
meta.Env = addDefaultEnvvar(meta.Env, "PATH", utilsystem.DefaultPathEnv(currentOS))
|
2018-05-20 21:48:35 +00:00
|
|
|
|
2018-05-25 18:15:32 +00:00
|
|
|
stdout, stderr := logs.NewLogStreams(ctx, os.Getenv("BUILDKIT_DEBUG_EXEC_OUTPUT") == "1")
|
2018-04-13 21:03:55 +00:00
|
|
|
defer stdout.Close()
|
|
|
|
defer stderr.Close()
|
|
|
|
|
2020-10-28 21:07:44 +00:00
|
|
|
execErr := e.exec.Run(ctx, "", mountWithSession(root, g), mounts, executor.ProcessInfo{
|
|
|
|
Meta: meta,
|
|
|
|
Stdin: nil,
|
|
|
|
Stdout: stdout,
|
|
|
|
Stderr: stderr,
|
|
|
|
}, nil)
|
2018-04-13 21:03:55 +00:00
|
|
|
|
|
|
|
for i, out := range outputs {
|
|
|
|
if mutable, ok := out.(cache.MutableRef); ok {
|
|
|
|
ref, err := mutable.Commit(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "error committing %s", mutable.ID())
|
|
|
|
}
|
|
|
|
refs = append(refs, worker.NewWorkerRefResult(ref, e.w))
|
|
|
|
} else {
|
|
|
|
refs = append(refs, worker.NewWorkerRefResult(out.(cache.ImmutableRef), e.w))
|
|
|
|
}
|
|
|
|
outputs[i] = nil
|
|
|
|
}
|
2020-10-28 21:07:44 +00:00
|
|
|
|
2020-11-05 00:51:53 +00:00
|
|
|
return refs, execErr
|
2018-04-13 21:03:55 +00:00
|
|
|
}
|
2018-05-20 21:48:35 +00:00
|
|
|
|
|
|
|
func proxyEnvList(p *pb.ProxyEnv) []string {
|
|
|
|
out := []string{}
|
|
|
|
if v := p.HttpProxy; v != "" {
|
|
|
|
out = append(out, "HTTP_PROXY="+v, "http_proxy="+v)
|
|
|
|
}
|
|
|
|
if v := p.HttpsProxy; v != "" {
|
|
|
|
out = append(out, "HTTPS_PROXY="+v, "https_proxy="+v)
|
|
|
|
}
|
|
|
|
if v := p.FtpProxy; v != "" {
|
|
|
|
out = append(out, "FTP_PROXY="+v, "ftp_proxy="+v)
|
|
|
|
}
|
|
|
|
if v := p.NoProxy; v != "" {
|
|
|
|
out = append(out, "NO_PROXY="+v, "no_proxy="+v)
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
2018-06-08 05:28:52 +00:00
|
|
|
|
2018-08-01 21:15:43 +00:00
|
|
|
func parseExtraHosts(ips []*pb.HostIP) ([]executor.HostIP, error) {
|
|
|
|
out := make([]executor.HostIP, len(ips))
|
|
|
|
for i, hip := range ips {
|
|
|
|
ip := net.ParseIP(hip.IP)
|
|
|
|
if ip == nil {
|
|
|
|
return nil, errors.Errorf("failed to parse IP %s", hip.IP)
|
|
|
|
}
|
|
|
|
out[i] = executor.HostIP{
|
|
|
|
IP: ip,
|
|
|
|
Host: hip.Host,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|
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{
|
|
|
|
Src: &mountable{m: m, g: g},
|
|
|
|
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)
|
|
|
|
}
|