From 596b03a8a0ff6dcd84ebdd28e057599a42f4d267 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 7 Jun 2018 22:28:52 -0700 Subject: [PATCH 1/2] llbsolver: allow tmpfs mounts Signed-off-by: Tonis Tiigi --- client/client_test.go | 18 +++++ client/llb/exec.go | 17 ++++- client/llb/exec_test.go | 26 +++++++ client/llb/state.go | 4 ++ solver/llbsolver/ops/exec.go | 36 ++++++++++ solver/pb/ops.pb.go | 130 ++++++++++++++++++----------------- solver/pb/ops.proto | 1 + 7 files changed, 168 insertions(+), 64 deletions(-) create mode 100644 client/llb/exec_test.go diff --git a/client/client_test.go b/client/client_test.go index 701e3785..51836291 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -52,9 +52,27 @@ func TestClientIntegration(t *testing.T) { testCachedMounts, testProxyEnv, testLocalSymlinkEscape, + testTmpfsMounts, }) } +func testTmpfsMounts(t *testing.T, sb integration.Sandbox) { + t.Parallel() + requiresLinux(t) + c, err := New(sb.Address()) + require.NoError(t, err) + defer c.Close() + + st := llb.Image("busybox:latest"). + Run(llb.Shlex(`sh -c 'mount | grep /foobar | grep "type tmpfs" && touch /foobar/test'`), llb.AddMount("/foobar", llb.Scratch(), llb.Tmpfs())) + + def, err := st.Marshal() + require.NoError(t, err) + + _, err = c.Solve(context.TODO(), def, SolveOpt{}, nil) + require.NoError(t, err) +} + func testLocalSymlinkEscape(t *testing.T, sb integration.Sandbox) { t.Parallel() requiresLinux(t) diff --git a/client/llb/exec.go b/client/llb/exec.go index abb98854..98be2653 100644 --- a/client/llb/exec.go +++ b/client/llb/exec.go @@ -42,6 +42,7 @@ type mount struct { output Output selector string cacheID string + tmpfs bool // hasOutput bool } @@ -66,6 +67,8 @@ func (e *ExecOp) AddMount(target string, source Output, opt ...MountOption) Outp e.mounts = append(e.mounts, m) if m.readonly { m.output = source + } else if m.tmpfs { + m.output = &output{vertex: e, err: errors.Errorf("tmpfs mount for %s can't be used as a parent", target)} } else { m.output = &output{vertex: e, getIndex: e.getMountIndexFn(m)} } @@ -144,6 +147,9 @@ func (e *ExecOp) Marshal() (digest.Digest, []byte, *OpMetadata, error) { for _, m := range e.mounts { inputIndex := pb.InputIndex(len(pop.Inputs)) if m.source != nil { + if m.tmpfs { + return "", nil, nil, errors.Errorf("tmpfs mounts must use scratch") + } inp, err := m.source.ToInput() if err != nil { return "", nil, nil, err @@ -167,7 +173,7 @@ func (e *ExecOp) Marshal() (digest.Digest, []byte, *OpMetadata, error) { } outputIndex := pb.OutputIndex(-1) - if !m.readonly && m.cacheID == "" { + if !m.readonly && m.cacheID == "" && !m.tmpfs { outputIndex = pb.OutputIndex(outIndex) outIndex++ } @@ -185,6 +191,9 @@ func (e *ExecOp) Marshal() (digest.Digest, []byte, *OpMetadata, error) { ID: m.cacheID, } } + if m.tmpfs { + pm.MountType = pb.MountType_TMPFS + } peo.Mounts = append(peo.Mounts, pm) } @@ -270,6 +279,12 @@ func AsPersistentCacheDir(id string) MountOption { } } +func Tmpfs() MountOption { + return func(m *mount) { + m.tmpfs = true + } +} + type RunOption interface { SetRunOption(es *ExecInfo) } diff --git a/client/llb/exec_test.go b/client/llb/exec_test.go new file mode 100644 index 00000000..280391f6 --- /dev/null +++ b/client/llb/exec_test.go @@ -0,0 +1,26 @@ +package llb + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestTmpfsMountError(t *testing.T) { + t.Parallel() + + st := Image("foo").Run(Shlex("args")).AddMount("/tmp", Scratch(), Tmpfs()) + _, err := st.Marshal() + + require.Error(t, err) + require.Contains(t, err.Error(), "can't be used as a parent") + + st = Image("foo").Run(Shlex("args"), AddMount("/tmp", Scratch(), Tmpfs())).Root() + _, err = st.Marshal() + require.NoError(t, err) + + st = Image("foo").Run(Shlex("args"), AddMount("/tmp", Image("bar"), Tmpfs())).Root() + _, err = st.Marshal() + require.Error(t, err) + require.Contains(t, err.Error(), "must use scratch") +} diff --git a/client/llb/state.go b/client/llb/state.go index 83dbf992..a53b212e 100644 --- a/client/llb/state.go +++ b/client/llb/state.go @@ -188,9 +188,13 @@ func (s State) With(so ...StateOption) State { type output struct { vertex Vertex getIndex func() (pb.OutputIndex, error) + err error } func (o *output) ToInput() (*pb.Input, error) { + if o.err != nil { + return nil, o.err + } var index pb.OutputIndex if o.getIndex != nil { var err error diff --git a/solver/llbsolver/ops/exec.go b/solver/llbsolver/ops/exec.go index 3cae012f..96fc7b55 100644 --- a/solver/llbsolver/ops/exec.go +++ b/solver/llbsolver/ops/exec.go @@ -12,9 +12,11 @@ import ( "strings" "github.com/boltdb/bolt" + "github.com/containerd/containerd/mount" "github.com/moby/buildkit/cache" "github.com/moby/buildkit/cache/metadata" "github.com/moby/buildkit/executor" + "github.com/moby/buildkit/snapshot" "github.com/moby/buildkit/solver" "github.com/moby/buildkit/solver/llbsolver" "github.com/moby/buildkit/solver/pb" @@ -287,6 +289,10 @@ func (e *execOp) Exec(ctx context.Context, inputs []solver.Result) ([]solver.Res if m.Output != pb.SkipOutput && ref != nil { outputs = append(outputs, ref.Clone()) } + + case pb.MountType_TMPFS: + mountable = newTmpfs() + default: return nil, errors.Errorf("mount type %s not implemented", m.MountType) } @@ -372,3 +378,33 @@ func proxyEnvList(p *pb.ProxyEnv) []string { } return out } + +func newTmpfs() cache.Mountable { + return &tmpfs{} +} + +type tmpfs struct { +} + +func (f *tmpfs) Mount(ctx context.Context, readonly bool) (snapshot.Mountable, error) { + return &tmpfsMount{readonly: readonly}, nil +} + +type tmpfsMount struct { + readonly bool +} + +func (m *tmpfsMount) Mount() ([]mount.Mount, error) { + opt := []string{"nosuid"} + if m.readonly { + opt = append(opt, "ro") + } + return []mount.Mount{{ + Type: "tmpfs", + Source: "none", + Options: opt, + }}, nil +} +func (m *tmpfsMount) Release() error { + return nil +} diff --git a/solver/pb/ops.pb.go b/solver/pb/ops.pb.go index 408a5660..d6ac7ad9 100644 --- a/solver/pb/ops.pb.go +++ b/solver/pb/ops.pb.go @@ -57,6 +57,7 @@ const ( MountType_SECRET MountType = 1 MountType_SSH MountType = 2 MountType_CACHE MountType = 3 + MountType_TMPFS MountType = 4 ) var MountType_name = map[int32]string{ @@ -64,12 +65,14 @@ var MountType_name = map[int32]string{ 1: "SECRET", 2: "SSH", 3: "CACHE", + 4: "TMPFS", } var MountType_value = map[string]int32{ "BIND": 0, "SECRET": 1, "SSH": 2, "CACHE": 3, + "TMPFS": 4, } func (x MountType) String() string { @@ -4420,71 +4423,72 @@ var ( func init() { proto.RegisterFile("ops.proto", fileDescriptorOps) } var fileDescriptorOps = []byte{ - // 1053 bytes of a gzipped FileDescriptorProto + // 1062 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xdd, 0x6e, 0x1b, 0xc5, - 0x17, 0xcf, 0xae, 0x3f, 0xb2, 0x7b, 0x36, 0xcd, 0xdf, 0xff, 0x21, 0x2a, 0xc6, 0x94, 0xc4, 0x6c, - 0x11, 0x72, 0xd3, 0xc6, 0x91, 0x8c, 0x40, 0x15, 0x17, 0x95, 0xe2, 0x0f, 0x29, 0x06, 0x95, 0xa0, - 0x49, 0x05, 0x97, 0x91, 0xbd, 0x1e, 0x3b, 0xab, 0x3a, 0x3b, 0xab, 0xdd, 0xd9, 0xc4, 0xbe, 0x00, + 0x17, 0xcf, 0xae, 0x3f, 0xb2, 0x7b, 0x36, 0xed, 0xdf, 0xff, 0x21, 0x2a, 0xc6, 0x94, 0xc4, 0x6c, + 0x11, 0x72, 0xd3, 0xc6, 0x91, 0x8c, 0x84, 0x2a, 0x2e, 0x2a, 0xe2, 0x0f, 0x14, 0x83, 0x42, 0xaa, + 0x49, 0x04, 0x97, 0x91, 0xbd, 0x1e, 0x3b, 0xab, 0x3a, 0x3b, 0xab, 0xdd, 0xd9, 0x24, 0xbe, 0x00, 0x89, 0x3e, 0x01, 0x12, 0x4f, 0xc1, 0x43, 0xc0, 0x75, 0x2f, 0xb9, 0x85, 0x8b, 0x82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0x5b, 0x2f, 0xb9, 0x7b, 0xcd, 0x79, 0x2a, 0x7a, 0x6f, 0xa5, 0x62, 0x3b, + 0x9f, 0x82, 0x9b, 0x6f, 0x77, 0xe6, 0x40, 0xb9, 0x3b, 0xfc, 0xb2, 0x5f, 0x5b, 0x63, 0x00, 0xd5, + 0xe3, 0x41, 0x8f, 0x0f, 0x4e, 0x6a, 0x16, 0x5b, 0x87, 0xd2, 0xf1, 0xf1, 0x41, 0xcd, 0x66, 0x2e, + 0x54, 0x7a, 0xfb, 0xbd, 0x83, 0x41, 0xad, 0x84, 0xc7, 0x93, 0xc3, 0x27, 0x9f, 0x1d, 0xd7, 0xca, + 0xdd, 0xda, 0xf3, 0xeb, 0x2d, 0xeb, 0x97, 0xeb, 0x2d, 0xeb, 0x8f, 0xeb, 0x2d, 0xeb, 0xfb, 0x3f, + 0xb7, 0xd6, 0xc6, 0x55, 0xfa, 0x17, 0xf4, 0xd1, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa8, 0x76, + 0x25, 0x54, 0x45, 0x09, 0x00, 0x00, } diff --git a/solver/pb/ops.proto b/solver/pb/ops.proto index a05c1f3d..8b7af2d4 100644 --- a/solver/pb/ops.proto +++ b/solver/pb/ops.proto @@ -59,6 +59,7 @@ enum MountType { SECRET = 1; SSH = 2; CACHE = 3; + TMPFS = 4; } message CacheOpt { From 6f569455d07d7fbc7764c348ed78b1d924770b43 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 8 Jun 2018 13:42:38 -0700 Subject: [PATCH 2/2] =?UTF-8?q?dockerfile:=20enable=20tmpfs=20mounts=20on?= =?UTF-8?q?=20run=20=E2=80=94mount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tonis Tiigi --- .../dockerfile2llb/convert_runmount.go | 12 ++++++--- .../instructions/commands_runmount.go | 25 +++++++++++++------ solver/llbsolver/ops/exec.go | 2 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/frontend/dockerfile/dockerfile2llb/convert_runmount.go b/frontend/dockerfile/dockerfile2llb/convert_runmount.go index 487cea7c..f1b20293 100644 --- a/frontend/dockerfile/dockerfile2llb/convert_runmount.go +++ b/frontend/dockerfile/dockerfile2llb/convert_runmount.go @@ -16,11 +16,11 @@ func detectRunMount(cmd *command, dispatchStatesByName map[string]*dispatchState mounts := instructions.GetMounts(c) sources := make([]*dispatchState, len(mounts)) for i, mount := range mounts { - if mount.From == "" && mount.Type == "cache" { + if mount.From == "" && mount.Type == instructions.MountTypeCache { mount.From = emptyImageName } from := mount.From - if from == "" { + if from == "" || mount.Type == instructions.MountTypeTmpfs { continue } stn, ok := dispatchStatesByName[strings.ToLower(from)] @@ -45,7 +45,7 @@ func dispatchRunMounts(d *dispatchState, c *instructions.RunCommand, sources []* mounts := instructions.GetMounts(c) for i, mount := range mounts { - if mount.From == "" && mount.Type == "cache" { + if mount.From == "" && mount.Type == instructions.MountTypeCache { mount.From = emptyImageName } st := opt.buildContext @@ -53,10 +53,14 @@ func dispatchRunMounts(d *dispatchState, c *instructions.RunCommand, sources []* st = sources[i].state } var mountOpts []llb.MountOption + if mount.Type == instructions.MountTypeTmpfs { + st = llb.Scratch() + mountOpts = append(mountOpts, llb.Tmpfs()) + } if mount.ReadOnly { mountOpts = append(mountOpts, llb.Readonly) } - if mount.Type == "cache" { + if mount.Type == instructions.MountTypeCache { mountOpts = append(mountOpts, llb.AsPersistentCacheDir(opt.cacheIDNamespace+"/"+mount.CacheID)) } if src := path.Join("/", mount.Source); src != "/" { diff --git a/frontend/dockerfile/instructions/commands_runmount.go b/frontend/dockerfile/instructions/commands_runmount.go index 8cea2f69..71030fa7 100644 --- a/frontend/dockerfile/instructions/commands_runmount.go +++ b/frontend/dockerfile/instructions/commands_runmount.go @@ -10,6 +10,16 @@ import ( "github.com/pkg/errors" ) +const MountTypeBind = "bind" +const MountTypeCache = "cache" +const MountTypeTmpfs = "tmpfs" + +var allowedMountTypes = map[string]struct{}{ + MountTypeBind: {}, + MountTypeCache: {}, + MountTypeTmpfs: {}, +} + type mountsKeyT string var mountsKey = mountsKeyT("dockerfile/run/mounts") @@ -19,6 +29,11 @@ func init() { parseRunPostHooks = append(parseRunPostHooks, runMountPostHook) } +func isValidMountType(s string) bool { + _, ok := allowedMountTypes[s] + return ok +} + func runMountPreHook(cmd *RunCommand, req parseRequest) error { st := &mountState{} st.flag = req.flags.AddStrings("mount") @@ -76,7 +91,7 @@ func parseMount(value string) (*Mount, error) { return nil, errors.Wrap(err, "failed to parse csv mounts") } - m := &Mount{Type: "bind"} + m := &Mount{Type: MountTypeBind} roAuto := true @@ -104,11 +119,7 @@ func parseMount(value string) (*Mount, error) { value := parts[1] switch key { case "type": - allowedTypes := map[string]struct{}{ - "cache": {}, - "bind": {}, - } - if _, ok := allowedTypes[strings.ToLower(value)]; !ok { + if !isValidMountType(strings.ToLower(value)) { return nil, errors.Errorf("invalid mount type %q", value) } m.Type = strings.ToLower(value) @@ -139,7 +150,7 @@ func parseMount(value string) (*Mount, error) { } if roAuto { - if m.Type == "cache" { + if m.Type == MountTypeCache { m.ReadOnly = false } else { m.ReadOnly = true diff --git a/solver/llbsolver/ops/exec.go b/solver/llbsolver/ops/exec.go index 96fc7b55..ecd3e2cb 100644 --- a/solver/llbsolver/ops/exec.go +++ b/solver/llbsolver/ops/exec.go @@ -401,7 +401,7 @@ func (m *tmpfsMount) Mount() ([]mount.Mount, error) { } return []mount.Mount{{ Type: "tmpfs", - Source: "none", + Source: "tmpfs", Options: opt, }}, nil }