mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ji...@apache.org
Subject mesos git commit: Fixed a problem of parsing v1Compatibility in Docker v2 image manifest.
Date Tue, 05 Jan 2016 01:28:09 GMT
Repository: mesos
Updated Branches:
  refs/heads/master add0e5fef -> 294460739


Fixed a problem of parsing v1Compatibility in Docker v2 image manifest.

Review: https://reviews.apache.org/r/41861


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/29446073
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/29446073
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/29446073

Branch: refs/heads/master
Commit: 2944607395c626f3e7b3c90a194b793f26f51a65
Parents: add0e5f
Author: Jie Yu <yujie.jay@gmail.com>
Authored: Sat Jan 2 22:23:22 2016 -0800
Committer: Jie Yu <yujie.jay@gmail.com>
Committed: Mon Jan 4 17:27:30 2016 -0800

----------------------------------------------------------------------
 src/docker/spec.cpp                             | 19 +++++++
 src/docker/v2.proto                             | 12 +++--
 .../provisioner/docker/registry_puller.cpp      |  6 ++-
 src/tests/containerizer/docker_spec_tests.cpp   | 30 +++--------
 .../containerizer/provisioner_docker_tests.cpp  | 54 ++++++++++----------
 5 files changed, 66 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/29446073/src/docker/spec.cpp
----------------------------------------------------------------------
diff --git a/src/docker/spec.cpp b/src/docker/spec.cpp
index 6c1d4b6..0188078 100644
--- a/src/docker/spec.cpp
+++ b/src/docker/spec.cpp
@@ -97,6 +97,25 @@ Try<ImageManifest> parse(const JSON::Object& json)
     return Error("Protobuf parse failed: " + manifest.error());
   }
 
+  for (int i = 0; i < manifest.get().history_size(); i++) {
+    Try<JSON::Object> v1Compatibility = JSON::parse<JSON::Object>(
+        manifest.get().history(i).v1compatibility());
+
+    if (v1Compatibility.isError()) {
+      return Error("Parsing v1Compatibility JSON failed: " +
+                   v1Compatibility.error());
+    }
+
+    Try<v1::ImageManifest> v1 = v1::parse(v1Compatibility.get());
+    if (v1.isError()) {
+      return Error("Parsing v1Compatibility protobuf failed: " + v1.error());
+    }
+
+    CHECK(!manifest.get().history(i).has_v1());
+
+    manifest->mutable_history(i)->mutable_v1()->CopyFrom(v1.get());
+  }
+
   Option<Error> error = validate(manifest.get());
   if (error.isSome()) {
     return Error("Docker v2 image manifest validation failed: " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/29446073/src/docker/v2.proto
----------------------------------------------------------------------
diff --git a/src/docker/v2.proto b/src/docker/v2.proto
index a1c3563..5d10bd3 100644
--- a/src/docker/v2.proto
+++ b/src/docker/v2.proto
@@ -16,6 +16,8 @@
 
 package docker.spec.v2;
 
+import "docker/v1.proto";
+
 /**
  * Protobuf for the Docker v2 image manifest JSON schema:
  * https://github.com/docker/distribution/blob/master/docs/spec/manifest-v2-1.md
@@ -32,12 +34,12 @@ message ImageManifest {
   repeated FsLayer fsLayers = 4;
 
   message History {
-    message V1Compatibility {
-      required string id = 1;
-      required string parent = 2;
-    }
+    required string v1Compatibility = 1;
 
-    required V1Compatibility v1Compatibility = 1;
+    // NOTE: This field does not exist in the Docker v2 image manifest
+    // specification. It is the parsed version of 'v1Compatibility'
+    // above (which is a raw JSON).
+    optional v1.ImageManifest v1 = 2;
   }
 
   repeated History history = 5;

http://git-wip-us.apache.org/repos/asf/mesos/blob/29446073/src/slave/containerizer/mesos/provisioner/docker/registry_puller.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/registry_puller.cpp b/src/slave/containerizer/mesos/provisioner/docker/registry_puller.cpp
index bd2c836..623c54e 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/registry_puller.cpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/registry_puller.cpp
@@ -255,12 +255,16 @@ Future<list<pair<string, string>>> RegistryPullerProcess::downloadLayers(
 {
   list<Future<pair<string, string>>> downloadFutures;
 
+  CHECK_EQ(manifest.fslayers_size(), manifest.history_size());
+
   for (int i = 0; i < manifest.fslayers_size(); i++) {
+    CHECK(manifest.history(i).has_v1());
+
     downloadFutures.push_back(
         downloadLayer(imageName,
                       directory,
                       manifest.fslayers(i).blobsum(),
-                      manifest.history(i).v1compatibility().id()));
+                      manifest.history(i).v1().id()));
   }
 
   // TODO(jojy): Delete downloaded files in the directory on discard and

http://git-wip-us.apache.org/repos/asf/mesos/blob/29446073/src/tests/containerizer/docker_spec_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/docker_spec_tests.cpp b/src/tests/containerizer/docker_spec_tests.cpp
index d4ec2cf..aa4faf9 100644
--- a/src/tests/containerizer/docker_spec_tests.cpp
+++ b/src/tests/containerizer/docker_spec_tests.cpp
@@ -167,28 +167,16 @@ TEST_F(DockerSpecTest, ParseV2ImageManifest)
         ],
         "history": [
           {
-            "v1Compatibility": {
-              "id": "2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea",
-              "parent": "cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff"
-            }
+            "v1Compatibility": "{\"id\": \"2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\",\"parent\":
\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\"}"
           },
           {
-            "v1Compatibility": {
-              "id": "2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea",
-              "parent": "cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff"
-            }
+            "v1Compatibility": "{\"id\": \"2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\",\"parent\":
\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\"}"
           },
           {
-            "v1Compatibility": {
-              "id": "2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea",
-              "parent": "cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff"
-            }
+            "v1Compatibility": "{\"id\": \"2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\",\"parent\":
\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\"}"
           },
           {
-            "v1Compatibility": {
-              "id": "2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea",
-              "parent": "cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff"
-            }
+            "v1Compatibility": "{\"id\": \"2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\",\"parent\":
\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\"}"
           }
         ],
         "schemaVersion": 1,
@@ -235,13 +223,11 @@ TEST_F(DockerSpecTest, ParseV2ImageManifest)
       manifest.get().fslayers(3).blobsum(),
       "sha256:2a7812e636235448785062100bb9103096aa6655a8f6bb9ac9b13fe8290f66df"); // NOLINT(whitespace/line_length)
 
-  EXPECT_EQ(
-      manifest.get().history(1).v1compatibility().id(),
-      "2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea");
+  EXPECT_EQ(manifest.get().history(1).v1().id(),
+          "2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea");
 
-  EXPECT_EQ(
-      manifest.get().history(2).v1compatibility().parent(),
-      "cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff");
+  EXPECT_EQ(manifest.get().history(2).v1().parent(),
+            "cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff");
 
   EXPECT_EQ(manifest.get().schemaversion(), 1u);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/29446073/src/tests/containerizer/provisioner_docker_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/provisioner_docker_tests.cpp b/src/tests/containerizer/provisioner_docker_tests.cpp
index 959540f..8635eee 100644
--- a/src/tests/containerizer/provisioner_docker_tests.cpp
+++ b/src/tests/containerizer/provisioner_docker_tests.cpp
@@ -542,30 +542,30 @@ TEST_F(RegistryClientTest, SimpleGetManifest)
     "   \"history\": ["
     "      {"
     "         \"v1Compatibility\": "
-    "           {"
-    "             \"id\": "
-    "\"1ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\","
-    "             \"parent\": "
-    "\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\""
-    "           }"
+    "           \"{"
+    "             \\\"id\\\": "
+    "\\\"1ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\\\","
+    "             \\\"parent\\\": "
+    "\\\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\\\""
+    "           }\""
     "      },"
     "      {"
     "         \"v1Compatibility\": "
-    "           {"
-    "             \"id\": "
-    "\"2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\","
-    "             \"parent\": "
-    "\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\""
-    "           }"
+    "           \"{"
+    "             \\\"id\\\": "
+    "\\\"2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\\\","
+    "             \\\"parent\\\": "
+    "\\\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\\\""
+    "           }\""
     "      },"
     "      {"
     "         \"v1Compatibility\": "
-    "           {"
-    "             \"id\": "
-    "\"3ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\","
-    "             \"parent\": "
-    "\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\""
-    "           }"
+    "           \"{"
+    "             \\\"id\\\": "
+    "\\\"3ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\\\","
+    "             \\\"parent\\\": "
+    "\\\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\\\""
+    "           }\""
     "      }"
     "   ],"
     "   \"signatures\": ["
@@ -604,15 +604,15 @@ TEST_F(RegistryClientTest, SimpleGetManifest)
   AWAIT_ASSERT_READY(manifestResponse);
 
   EXPECT_EQ(
-      manifestResponse.get().history(2).v1compatibility().id(),
+      manifestResponse.get().history(2).v1().id(),
       "1ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea");
 
   EXPECT_EQ(
-      manifestResponse.get().history(1).v1compatibility().id(),
+      manifestResponse.get().history(1).v1().id(),
       "2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea");
 
   EXPECT_EQ(
-      manifestResponse.get().history(0).v1compatibility().id(),
+      manifestResponse.get().history(0).v1().id(),
       "3ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea");
 }
 
@@ -879,12 +879,12 @@ TEST_F(RegistryClientTest, SimpleRegistryPuller)
     "   \"history\": ["
     "      {"
     "         \"v1Compatibility\": "
-    "           {"
-    "             \"id\": "
-    "\"1ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\","
-    "             \"parent\": "
-    "\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\""
-    "           }"
+    "           \"{"
+    "             \\\"id\\\": "
+    "\\\"1ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\\\","
+    "             \\\"parent\\\": "
+    "\\\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\\\""
+    "           }\""
     "      }"
     "   ],"
     "   \"signatures\": ["


Mime
View raw message