You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ti...@apache.org on 2016/11/28 16:57:47 UTC
mesos git commit: Added temporary file environment passing towards
docker.
Repository: mesos
Updated Branches:
refs/heads/master dadb22bd6 -> 369103d8a
Added temporary file environment passing towards docker.
Review: https://reviews.apache.org/r/53877/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/369103d8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/369103d8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/369103d8
Branch: refs/heads/master
Commit: 369103d8ae024c22aa3c53f93a688afecbfec8a1
Parents: dadb22b
Author: Till Toenshoff <to...@me.com>
Authored: Mon Nov 28 17:57:14 2016 +0100
Committer: Till Toenshoff <to...@me.com>
Committed: Mon Nov 28 17:57:34 2016 +0100
----------------------------------------------------------------------
src/docker/docker.cpp | 55 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 46 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/369103d8/src/docker/docker.cpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp
index f03ea7f..b2a547d 100755
--- a/src/docker/docker.cpp
+++ b/src/docker/docker.cpp
@@ -532,10 +532,11 @@ Future<Option<int>> Docker::run(
}
}
+ string environmentVariables = "";
+
if (env.isSome()) {
foreachpair (const string& key, const string& value, env.get()) {
- argv.push_back("-e");
- argv.push_back(key + "=" + value);
+ environmentVariables += key + "=" + value + "\n";
}
}
@@ -546,14 +547,42 @@ Future<Option<int>> Docker::run(
// Skip to avoid duplicate environment variables.
continue;
}
- argv.push_back("-e");
- argv.push_back(variable.name() + "=" + variable.value());
+ environmentVariables += variable.name() + "=" + variable.value() + "\n";
+ }
+
+ environmentVariables += "MESOS_SANDBOX=" + mappedDirectory + "\n";
+ environmentVariables += "MESOS_CONTAINER_NAME=" + name + "\n";
+
+ Try<string> environmentFile_ = os::mktemp();
+ if (environmentFile_.isError()) {
+ return Failure("Failed to create temporary docker environment "
+ "file: " + environmentFile_.error());
+ }
+
+ const string& environmentFile = environmentFile_.get();
+
+ Try<int> fd = os::open(
+ environmentFile,
+ O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
+ S_IRUSR | S_IWUSR);
+
+ if (fd.isError()) {
+ return Failure(
+ "Failed to open file '" + environmentFile + "': " + fd.error());
}
- argv.push_back("-e");
- argv.push_back("MESOS_SANDBOX=" + mappedDirectory);
- argv.push_back("-e");
- argv.push_back("MESOS_CONTAINER_NAME=" + name);
+ Try<Nothing> write = os::write(fd.get(), environmentVariables);
+
+ os::close(fd.get());
+
+ if (write.isError()) {
+ return Failure(
+ "Failed to write docker environment file to '" + environmentFile +
+ "': " + write.error());
+ }
+
+ argv.push_back("--env-file");
+ argv.push_back(environmentFile);
Option<string> volumeDriver;
foreach (const Volume& volume, containerInfo.volumes()) {
@@ -830,7 +859,15 @@ Future<Option<int>> Docker::run(
}
s->status()
- .onDiscard(lambda::bind(&commandDiscarded, s.get(), cmd));
+ .onDiscard(lambda::bind(&commandDiscarded, s.get(), cmd))
+ .onAny([environmentFile]() {
+ Try<Nothing> rm = os::rm(environmentFile);
+
+ if (rm.isError()) {
+ LOG(WARNING) << "Failed to remove temporary docker environment file "
+ << "'" << environmentFile << "': " << rm.error();
+ }
+ });
// Ideally we could capture the stderr when docker itself fails,
// however due to the stderr redirection used here we cannot.