commit
88cbbe5345
|
@ -3,6 +3,7 @@ package llb
|
|||
import (
|
||||
_ "crypto/sha256"
|
||||
|
||||
"github.com/moby/buildkit/solver/pb"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -48,7 +49,7 @@ func (s *State) Run(opts ...RunOption) *ExecState {
|
|||
meta: meta,
|
||||
mounts: []*mount{},
|
||||
root: &mount{
|
||||
dest: "/",
|
||||
dest: pb.RootMount,
|
||||
source: s.source,
|
||||
parent: s.mount,
|
||||
hasOutput: true,
|
||||
|
|
|
@ -111,20 +111,16 @@ func TestControl(t *testing.T) {
|
|||
Cwd: "/",
|
||||
}
|
||||
|
||||
m := make(map[string]cache.Mountable)
|
||||
m["/"] = snap
|
||||
|
||||
stderr := bytes.NewBuffer(nil)
|
||||
|
||||
err = w.Exec(ctx, meta, m, nil, &nopCloser{stderr})
|
||||
err = w.Exec(ctx, meta, snap, nil, nil, &nopCloser{stderr})
|
||||
assert.Error(t, err) // Read-only root
|
||||
assert.Contains(t, stderr.String(), "Read-only file system")
|
||||
|
||||
root, err := cm.New(ctx, snap)
|
||||
assert.NoError(t, err)
|
||||
|
||||
m["/"] = root
|
||||
err = w.Exec(ctx, meta, m, nil, nil)
|
||||
err = w.Exec(ctx, meta, root, nil, nil, nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
rf, err := root.Freeze()
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/moby/buildkit/cache"
|
||||
"github.com/moby/buildkit/client"
|
||||
|
@ -45,9 +46,9 @@ func (e *execOp) CacheKey(ctx context.Context, inputs []string) (string, error)
|
|||
}
|
||||
|
||||
func (e *execOp) Run(ctx context.Context, inputs []Reference) ([]Reference, error) {
|
||||
mounts := make(map[string]cache.Mountable)
|
||||
|
||||
var mounts []worker.Mount
|
||||
var outputs []cache.MutableRef
|
||||
var root cache.Mountable
|
||||
|
||||
defer func() {
|
||||
for _, o := range outputs {
|
||||
|
@ -84,9 +85,17 @@ func (e *execOp) Run(ctx context.Context, inputs []Reference) ([]Reference, erro
|
|||
outputs = append(outputs, active)
|
||||
mountable = active
|
||||
}
|
||||
mounts[m.Dest] = mountable
|
||||
if m.Dest == pb.RootMount {
|
||||
root = mountable
|
||||
} else {
|
||||
mounts = append(mounts, worker.Mount{Src: mountable, Dest: m.Dest})
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(mounts, func(i, j int) bool {
|
||||
return mounts[i].Dest < mounts[j].Dest
|
||||
})
|
||||
|
||||
meta := worker.Meta{
|
||||
Args: e.op.Meta.Args,
|
||||
Env: e.op.Meta.Env,
|
||||
|
@ -98,7 +107,7 @@ func (e *execOp) Run(ctx context.Context, inputs []Reference) ([]Reference, erro
|
|||
stderr := newStreamWriter(ctx, 2)
|
||||
defer stderr.Close()
|
||||
|
||||
if err := e.w.Exec(ctx, meta, mounts, stdout, stderr); err != nil {
|
||||
if err := e.w.Exec(ctx, meta, root, mounts, stdout, stderr); err != nil {
|
||||
return nil, errors.Wrapf(err, "worker failed running %v", meta.Args)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package pb
|
||||
|
||||
const RootMount = "/"
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/moby/buildkit/cache"
|
||||
"github.com/moby/buildkit/worker"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -12,7 +11,7 @@ import (
|
|||
|
||||
// Ideally we don't have to import whole containerd just for the default spec
|
||||
|
||||
func GenerateSpec(ctx context.Context, meta worker.Meta, mounts map[string]cache.Mountable) (*specs.Spec, error) {
|
||||
func GenerateSpec(ctx context.Context, meta worker.Meta, mounts []worker.Mount) (*specs.Spec, error) {
|
||||
s, err := containerd.GenerateSpec(containerd.WithHostNamespace(specs.NetworkNamespace))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -22,17 +21,14 @@ func GenerateSpec(ctx context.Context, meta worker.Meta, mounts map[string]cache
|
|||
s.Process.Cwd = meta.Cwd
|
||||
// TODO: User
|
||||
|
||||
for dest, m := range mounts {
|
||||
if dest == "/" {
|
||||
continue
|
||||
}
|
||||
mounts, err := m.Mount(ctx)
|
||||
for _, m := range mounts {
|
||||
mounts, err := m.Src.Mount(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to mount to %s", dest)
|
||||
return nil, errors.Wrapf(err, "failed to mount %s", m.Dest)
|
||||
}
|
||||
for _, mount := range mounts {
|
||||
s.Mounts = append(s.Mounts, specs.Mount{
|
||||
Destination: dest,
|
||||
Destination: m.Dest,
|
||||
Type: mount.Type,
|
||||
Source: mount.Source,
|
||||
Options: mount.Options,
|
||||
|
|
|
@ -54,12 +54,7 @@ func New(root string) (worker.Worker, error) {
|
|||
return w, nil
|
||||
}
|
||||
|
||||
func (w *runcworker) Exec(ctx context.Context, meta worker.Meta, mounts map[string]cache.Mountable, stdout, stderr io.WriteCloser) error {
|
||||
root, ok := mounts["/"]
|
||||
if !ok {
|
||||
return errors.Errorf("no root mount")
|
||||
}
|
||||
|
||||
func (w *runcworker) Exec(ctx context.Context, meta worker.Meta, root cache.Mountable, mounts []worker.Mount, stdout, stderr io.WriteCloser) error {
|
||||
rootMount, err := root.Mount(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -16,7 +16,13 @@ type Meta struct {
|
|||
// DisableNetworking bool
|
||||
}
|
||||
|
||||
type Mount struct {
|
||||
Src cache.Mountable
|
||||
Dest string
|
||||
ReadOnly bool
|
||||
}
|
||||
|
||||
type Worker interface {
|
||||
// TODO: add stdout/err
|
||||
Exec(ctx context.Context, meta Meta, mounts map[string]cache.Mountable, stdout, stderr io.WriteCloser) error
|
||||
Exec(ctx context.Context, meta Meta, rootfs cache.Mountable, mounts []Mount, stdout, stderr io.WriteCloser) error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue