Merge pull request #319 from ijc/check-mount-source

Check that mounts have a Source when generating the OCI spec
docker-18.09
Tõnis Tiigi 2018-03-22 08:53:28 -07:00 committed by GitHub
commit 9f8547022b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 0 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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 {