You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/07/13 22:55:39 UTC
[1/4] mesos git commit: Supported relative container path in docker
containerizer.
Repository: mesos
Updated Branches:
refs/heads/master 0c8ee37c2 -> 453c3cc93
Supported relative container path in docker containerizer.
Review: https://reviews.apache.org/r/49961/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/35a2074b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/35a2074b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/35a2074b
Branch: refs/heads/master
Commit: 35a2074b39dc2e97d84b0f0f5f16f39218fb5bff
Parents: 0c8ee37
Author: Gilbert Song <so...@gmail.com>
Authored: Wed Jul 13 15:52:12 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Jul 13 15:52:12 2016 -0700
----------------------------------------------------------------------
src/docker/docker.cpp | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/35a2074b/src/docker/docker.cpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp
index e96b4b6..515842d 100755
--- a/src/docker/docker.cpp
+++ b/src/docker/docker.cpp
@@ -557,10 +557,24 @@ Future<Option<int>> Docker::run(
Option<string> volumeDriver;
foreach (const Volume& volume, containerInfo.volumes()) {
- string volumeConfig = volume.container_path();
+ // The 'container_path' can be either an absolute path or a
+ // relative path. If it is a relative path, it would be prefixed
+ // with the container sandbox directory.
+ string volumeConfig = strings::startsWith(volume.container_path(), "/")
+ ? volume.container_path()
+ : path::join(mappedDirectory, volume.container_path());
// TODO(gyliu513): Set `host_path` as source.
if (volume.has_host_path()) {
+ // If both 'host_path' and 'container_path' are relative paths,
+ // return a failure because the user can just directly access the
+ // volume in the sandbox.
+ if (!strings::startsWith(volume.host_path(), "/") &&
+ !strings::startsWith(volume.container_path(), "/")) {
+ return Failure(
+ "Both 'host_path' and 'container_path' of a volume are relative");
+ }
+
if (!strings::startsWith(volume.host_path(), "/") &&
!dockerInfo.has_volume_driver()) {
// When volume dirver is empty and host path is a relative path, mapping
[2/4] mesos git commit: Modified docker test mount absolute/relative
host path.
Posted by ji...@apache.org.
Modified docker test mount absolute/relative host path.
Review: https://reviews.apache.org/r/49997/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2b6f75c8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2b6f75c8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2b6f75c8
Branch: refs/heads/master
Commit: 2b6f75c80ecf80c4fec2d3f22f1aa00798e0f419
Parents: 35a2074
Author: Gilbert Song <so...@gmail.com>
Authored: Wed Jul 13 15:52:16 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Jul 13 15:52:16 2016 -0700
----------------------------------------------------------------------
src/tests/containerizer/docker_tests.cpp | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/2b6f75c8/src/tests/containerizer/docker_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/docker_tests.cpp b/src/tests/containerizer/docker_tests.cpp
index ab6dc3c..0429a31 100644
--- a/src/tests/containerizer/docker_tests.cpp
+++ b/src/tests/containerizer/docker_tests.cpp
@@ -466,9 +466,9 @@ TEST_F(DockerTest, ROOT_DOCKER_CancelPull)
}
-// This test verifies mounting in a relative path when running a
+// This test verifies mounting in a relative host path when running a
// docker container works.
-TEST_F(DockerTest, ROOT_DOCKER_MountRelative)
+TEST_F(DockerTest, ROOT_DOCKER_MountRelativeHostPath)
{
Owned<Docker> docker = Docker::create(
tests::flags.docker,
@@ -501,9 +501,9 @@ TEST_F(DockerTest, ROOT_DOCKER_MountRelative)
Future<Option<int>> run = docker->run(
containerInfo,
commandInfo,
- NAME_PREFIX + "-mount-relative-test",
+ NAME_PREFIX + "-mount-relative-host-path-test",
directory.get(),
- directory.get());
+ "/mnt/mesos/sandbox");
AWAIT_READY(run);
ASSERT_SOME(run.get());
@@ -512,9 +512,9 @@ TEST_F(DockerTest, ROOT_DOCKER_MountRelative)
}
-// This test verifies mounting in an absolute path when running a
+// This test verifies mounting in an absolute host path when running a
// docker container works.
-TEST_F(DockerTest, ROOT_DOCKER_MountAbsolute)
+TEST_F(DockerTest, ROOT_DOCKER_MountAbsoluteHostPath)
{
Owned<Docker> docker = Docker::create(
tests::flags.docker,
@@ -547,9 +547,9 @@ TEST_F(DockerTest, ROOT_DOCKER_MountAbsolute)
Future<Option<int>> run = docker->run(
containerInfo,
commandInfo,
- NAME_PREFIX + "-mount-absolute-test",
+ NAME_PREFIX + "-mount-absolute-host-path-test",
directory.get(),
- directory.get());
+ "/mnt/mesos/sandbox");
AWAIT_READY(run);
ASSERT_SOME(run.get());
[3/4] mesos git commit: Added docker test mount relative container
path.
Posted by ji...@apache.org.
Added docker test mount relative container path.
Review: https://reviews.apache.org/r/49998/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f7df37b7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f7df37b7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f7df37b7
Branch: refs/heads/master
Commit: f7df37b7c9e3e9c20899ce906655087c3270c47b
Parents: 2b6f75c
Author: Gilbert Song <so...@gmail.com>
Authored: Wed Jul 13 15:52:18 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Jul 13 15:52:18 2016 -0700
----------------------------------------------------------------------
src/tests/containerizer/docker_tests.cpp | 47 +++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/f7df37b7/src/tests/containerizer/docker_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/docker_tests.cpp b/src/tests/containerizer/docker_tests.cpp
index 0429a31..4108b57 100644
--- a/src/tests/containerizer/docker_tests.cpp
+++ b/src/tests/containerizer/docker_tests.cpp
@@ -558,6 +558,53 @@ TEST_F(DockerTest, ROOT_DOCKER_MountAbsoluteHostPath)
}
+// This test verifies mounting in an absolute host path to
+// a relative container path when running a docker container
+// works.
+TEST_F(DockerTest, ROOT_DOCKER_MountRelativeContainerPath)
+{
+ Owned<Docker> docker = Docker::create(
+ tests::flags.docker,
+ tests::flags.docker_socket,
+ false).get();
+
+ ContainerInfo containerInfo;
+ containerInfo.set_type(ContainerInfo::DOCKER);
+
+ Try<string> directory = environment->mkdtemp();
+ ASSERT_SOME(directory);
+
+ const string testFile = path::join(directory.get(), "test_file");
+ EXPECT_SOME(os::write(testFile, "data"));
+
+ Volume* volume = containerInfo.add_volumes();
+ volume->set_host_path(testFile);
+ volume->set_container_path("tmp/test_file");
+ volume->set_mode(Volume::RO);
+
+ ContainerInfo::DockerInfo dockerInfo;
+ dockerInfo.set_image("alpine");
+
+ containerInfo.mutable_docker()->CopyFrom(dockerInfo);
+
+ CommandInfo commandInfo;
+ commandInfo.set_shell(true);
+ commandInfo.set_value("ls /mnt/mesos/sandbox/tmp/test_file");
+
+ Future<Option<int>> run = docker->run(
+ containerInfo,
+ commandInfo,
+ NAME_PREFIX + "-mount-relative-container-path-test",
+ directory.get(),
+ "/mnt/mesos/sandbox");
+
+ AWAIT_READY(run);
+ ASSERT_SOME(run.get());
+ EXPECT_TRUE(WIFEXITED(run->get())) << run->get();
+ EXPECT_EQ(0, WEXITSTATUS(run->get())) << run->get();
+}
+
+
class DockerImageTest : public MesosTest {};
[4/4] mesos git commit: Added docker test relative host path and
relative container path.
Posted by ji...@apache.org.
Added docker test relative host path and relative container path.
Review: https://reviews.apache.org/r/49999/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/453c3cc9
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/453c3cc9
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/453c3cc9
Branch: refs/heads/master
Commit: 453c3cc939eb19adda25ff3be4483fe277adcc8b
Parents: f7df37b
Author: Gilbert Song <so...@gmail.com>
Authored: Wed Jul 13 15:52:21 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Jul 13 15:52:21 2016 -0700
----------------------------------------------------------------------
src/tests/containerizer/docker_tests.cpp | 43 +++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/453c3cc9/src/tests/containerizer/docker_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/docker_tests.cpp b/src/tests/containerizer/docker_tests.cpp
index 4108b57..7b73a49 100644
--- a/src/tests/containerizer/docker_tests.cpp
+++ b/src/tests/containerizer/docker_tests.cpp
@@ -605,6 +605,49 @@ TEST_F(DockerTest, ROOT_DOCKER_MountRelativeContainerPath)
}
+// This test verifies a docker container mounting relative host
+// path to a relative container path fails.
+TEST_F(DockerTest, ROOT_DOCKER_MountRelativeHostPathRelativeContainerPath)
+{
+ Owned<Docker> docker = Docker::create(
+ tests::flags.docker,
+ tests::flags.docker_socket,
+ false).get();
+
+ ContainerInfo containerInfo;
+ containerInfo.set_type(ContainerInfo::DOCKER);
+
+ Volume* volume = containerInfo.add_volumes();
+ volume->set_host_path("test_file");
+ volume->set_container_path("tmp/test_file");
+ volume->set_mode(Volume::RO);
+
+ ContainerInfo::DockerInfo dockerInfo;
+ dockerInfo.set_image("alpine");
+
+ containerInfo.mutable_docker()->CopyFrom(dockerInfo);
+
+ CommandInfo commandInfo;
+ commandInfo.set_shell(true);
+ commandInfo.set_value("ls /mnt/mesos/sandbox/tmp/test_file");
+
+ Try<string> directory = environment->mkdtemp();
+ ASSERT_SOME(directory);
+
+ const string testFile = path::join(directory.get(), "test_file");
+ EXPECT_SOME(os::write(testFile, "data"));
+
+ Future<Option<int>> run = docker->run(
+ containerInfo,
+ commandInfo,
+ NAME_PREFIX + "-mount-relative-host-path/container-path-test",
+ directory.get(),
+ "/mnt/mesos/sandbox");
+
+ ASSERT_TRUE(run.isFailed());
+}
+
+
class DockerImageTest : public MesosTest {};