Merge pull request #319 from ijc/check-mount-source
Check that mounts have a Source when generating the OCI specdocker-18.09
commit
9f8547022b
|
@ -43,6 +43,7 @@ func TestClientIntegration(t *testing.T) {
|
|||
testWhiteoutParentDir,
|
||||
testDuplicateWhiteouts,
|
||||
testSchema1Image,
|
||||
testMountWithNoSource,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -705,6 +706,37 @@ func testSchema1Image(t *testing.T, sb integration.Sandbox) {
|
|||
checkAllReleasable(t, c, sb, true)
|
||||
}
|
||||
|
||||
// #319
|
||||
func testMountWithNoSource(t *testing.T, sb integration.Sandbox) {
|
||||
t.Parallel()
|
||||
c, err := New(sb.Address())
|
||||
require.NoError(t, err)
|
||||
defer c.Close()
|
||||
|
||||
busybox := llb.Image("docker.io/library/busybox:latest")
|
||||
st := llb.Scratch()
|
||||
|
||||
var nilState llb.State
|
||||
|
||||
// This should never actually be run, but we want to succeed
|
||||
// if it was, because we expect an error below, or a daemon
|
||||
// panic if the issue has regressed.
|
||||
run := busybox.Run(
|
||||
llb.Args([]string{"/bin/true"}),
|
||||
llb.AddMount("/nil", nilState, llb.SourcePath("/"), llb.Readonly))
|
||||
|
||||
st = run.AddMount("/mnt", st)
|
||||
|
||||
def, err := st.Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = c.Solve(context.TODO(), def, SolveOpt{}, nil)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "has no input")
|
||||
|
||||
checkAllReleasable(t, c, sb, true)
|
||||
}
|
||||
|
||||
func requiresLinux(t *testing.T) {
|
||||
if runtime.GOOS != "linux" {
|
||||
t.Skipf("unsupported GOOS: %s", runtime.GOOS)
|
||||
|
|
|
@ -50,6 +50,9 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou
|
|||
sm := &submounts{}
|
||||
|
||||
for _, m := range mounts {
|
||||
if m.Src == nil {
|
||||
return nil, nil, errors.Errorf("mount %s has no source", m.Dest)
|
||||
}
|
||||
mounts, err := m.Src.Mount(ctx, m.Readonly)
|
||||
if err != nil {
|
||||
sm.cleanup()
|
||||
|
|
|
@ -95,6 +95,11 @@ func (e *execOp) Run(ctx context.Context, inputs []solver.Ref) ([]solver.Ref, er
|
|||
mountable = active
|
||||
}
|
||||
}
|
||||
|
||||
if mountable == nil {
|
||||
return nil, errors.Errorf("mount %s has no input", m.Dest)
|
||||
}
|
||||
|
||||
if m.Dest == pb.RootMount {
|
||||
root = mountable
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue