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/01/04 18:28:46 UTC
[2/5] mesos git commit: Moved docker spec to the top level.
Moved docker spec to the top level.
Review: https://reviews.apache.org/r/41840
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/92fec0cb
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/92fec0cb
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/92fec0cb
Branch: refs/heads/master
Commit: 92fec0cb30e44b6bdc8d0113f3f62315a6f8ecb5
Parents: 570f78e
Author: Jie Yu <yu...@gmail.com>
Authored: Fri Jan 1 10:09:33 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Jan 4 09:26:23 2016 -0800
----------------------------------------------------------------------
src/Makefile.am | 22 ++--
src/docker/spec.cpp | 111 ++++++++++++++++
src/docker/spec.hpp | 64 ++++++++++
src/docker/v1.hpp | 23 ++++
src/docker/v1.proto | 68 ++++++++++
src/docker/v2.hpp | 23 ++++
src/docker/v2.proto | 70 ++++++++++
.../mesos/provisioner/docker/message.hpp | 2 -
.../provisioner/docker/registry_client.cpp | 12 +-
.../provisioner/docker/registry_client.hpp | 4 +-
.../provisioner/docker/registry_puller.cpp | 11 +-
.../mesos/provisioner/docker/spec.cpp | 127 -------------------
.../mesos/provisioner/docker/spec.hpp | 65 ----------
.../mesos/provisioner/docker/v1.proto | 70 ----------
.../mesos/provisioner/docker/v2.proto | 72 -----------
.../containerizer/provisioner_docker_tests.cpp | 48 +++----
16 files changed, 411 insertions(+), 381 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index b58d6b5..bdac044 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -202,6 +202,10 @@ CXX_PROTOS = \
../include/mesos/v1/scheduler/scheduler.pb.h
CXX_PROTOS += \
+ docker/v1.pb.cc \
+ docker/v1.pb.h \
+ docker/v2.pb.cc \
+ docker/v2.pb.h \
master/registry.pb.cc \
master/registry.pb.h \
messages/flags.pb.cc \
@@ -209,11 +213,7 @@ CXX_PROTOS += \
messages/messages.pb.cc \
messages/messages.pb.h \
slave/containerizer/mesos/provisioner/docker/message.pb.cc \
- slave/containerizer/mesos/provisioner/docker/message.pb.h \
- slave/containerizer/mesos/provisioner/docker/v1.pb.cc \
- slave/containerizer/mesos/provisioner/docker/v1.pb.h \
- slave/containerizer/mesos/provisioner/docker/v2.pb.cc \
- slave/containerizer/mesos/provisioner/docker/v2.pb.h
+ slave/containerizer/mesos/provisioner/docker/message.pb.h
CXX_LOG_PROTOS = \
messages/log.pb.cc \
@@ -533,12 +533,12 @@ nodist_libmesos_no_3rdparty_la_SOURCES = $(CXX_PROTOS)
libmesos_no_3rdparty_la_SOURCES = \
+ docker/v1.proto \
+ docker/v2.proto \
master/registry.proto \
messages/flags.proto \
messages/messages.proto \
- slave/containerizer/mesos/provisioner/docker/message.proto \
- slave/containerizer/mesos/provisioner/docker/v1.proto \
- slave/containerizer/mesos/provisioner/docker/v2.proto
+ slave/containerizer/mesos/provisioner/docker/message.proto
# TODO(tillt): Remove authentication/cram_md5/* which will enable us to
# lose the immediate cyrus-sasl2 dependency.
@@ -557,6 +557,7 @@ libmesos_no_3rdparty_la_SOURCES += \
common/type_utils.cpp \
common/values.cpp \
docker/docker.cpp \
+ docker/spec.cpp \
exec/exec.cpp \
files/files.cpp \
hdfs/hdfs.cpp \
@@ -629,7 +630,6 @@ libmesos_no_3rdparty_la_SOURCES += \
slave/containerizer/mesos/provisioner/docker/puller.cpp \
slave/containerizer/mesos/provisioner/docker/registry_client.cpp \
slave/containerizer/mesos/provisioner/docker/registry_puller.cpp \
- slave/containerizer/mesos/provisioner/docker/spec.cpp \
slave/containerizer/mesos/provisioner/docker/store.cpp \
slave/containerizer/mesos/provisioner/docker/token_manager.cpp \
slave/resource_estimators/noop.cpp \
@@ -666,6 +666,9 @@ libmesos_no_3rdparty_la_SOURCES += \
credentials/credentials.hpp \
docker/docker.hpp \
docker/executor.hpp \
+ docker/spec.hpp \
+ docker/v1.hpp \
+ docker/v2.hpp \
examples/test_anonymous_module.hpp \
examples/test_module.hpp \
examples/utils.hpp \
@@ -739,7 +742,6 @@ libmesos_no_3rdparty_la_SOURCES += \
slave/containerizer/mesos/provisioner/docker/puller.hpp \
slave/containerizer/mesos/provisioner/docker/registry_client.hpp \
slave/containerizer/mesos/provisioner/docker/registry_puller.hpp \
- slave/containerizer/mesos/provisioner/docker/spec.hpp \
slave/containerizer/mesos/provisioner/docker/store.hpp \
slave/containerizer/mesos/provisioner/docker/token_manager.hpp \
slave/qos_controllers/noop.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/docker/spec.cpp
----------------------------------------------------------------------
diff --git a/src/docker/spec.cpp b/src/docker/spec.cpp
new file mode 100644
index 0000000..6c1d4b6
--- /dev/null
+++ b/src/docker/spec.cpp
@@ -0,0 +1,111 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <stout/foreach.hpp>
+#include <stout/json.hpp>
+#include <stout/none.hpp>
+#include <stout/protobuf.hpp>
+#include <stout/strings.hpp>
+
+#include "docker/spec.hpp"
+
+using std::string;
+
+namespace docker {
+namespace spec {
+namespace v1 {
+
+Option<Error> validate(const ImageManifest& manifest)
+{
+ // TODO(gilbert): Add validations.
+ return None();
+}
+
+
+Try<ImageManifest> parse(const JSON::Object& json)
+{
+ Try<ImageManifest> manifest = protobuf::parse<ImageManifest>(json);
+ if (manifest.isError()) {
+ return Error("Protobuf parse failed: " + manifest.error());
+ }
+
+ Option<Error> error = validate(manifest.get());
+ if (error.isSome()) {
+ return Error("Docker v1 image manifest validation failed: " +
+ error.get().message);
+ }
+
+ return manifest.get();
+}
+
+} // namespace v1 {
+
+
+namespace v2 {
+
+Option<Error> validate(const ImageManifest& manifest)
+{
+ // Validate required fields are present,
+ // e.g., repeated fields that has to be >= 1.
+ if (manifest.fslayers_size() <= 0) {
+ return Error("'fsLayers' field size must be at least one");
+ }
+
+ if (manifest.history_size() <= 0) {
+ return Error("'history' field size must be at least one");
+ }
+
+ if (manifest.signatures_size() <= 0) {
+ return Error("'signatures' field size must be at least one");
+ }
+
+ // Verify that blobSum and v1Compatibility numbers are equal.
+ if (manifest.fslayers_size() != manifest.history_size()) {
+ return Error("The size of 'fsLayers' should be equal "
+ "to the size of 'history'");
+ }
+
+ // Verify 'fsLayers' field.
+ foreach (const ImageManifest::FsLayer& fslayer, manifest.fslayers()) {
+ const string& blobSum = fslayer.blobsum();
+ if (!strings::contains(blobSum, ":")) {
+ return Error("Incorrect 'blobSum' format: " + blobSum);
+ }
+ }
+
+ return None();
+}
+
+
+Try<ImageManifest> parse(const JSON::Object& json)
+{
+ Try<ImageManifest> manifest = protobuf::parse<ImageManifest>(json);
+ if (manifest.isError()) {
+ return Error("Protobuf parse failed: " + manifest.error());
+ }
+
+ Option<Error> error = validate(manifest.get());
+ if (error.isSome()) {
+ return Error("Docker v2 image manifest validation failed: " +
+ error.get().message);
+ }
+
+ return manifest.get();
+}
+
+} // namespace v2 {
+} // namespace spec {
+} // namespace docker {
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/docker/spec.hpp
----------------------------------------------------------------------
diff --git a/src/docker/spec.hpp b/src/docker/spec.hpp
new file mode 100644
index 0000000..74968f2
--- /dev/null
+++ b/src/docker/spec.hpp
@@ -0,0 +1,64 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __DOCKER_SPEC_HPP__
+#define __DOCKER_SPEC_HPP__
+
+#include <stout/error.hpp>
+#include <stout/json.hpp>
+#include <stout/option.hpp>
+
+#include "docker/v1.hpp"
+#include "docker/v2.hpp"
+
+namespace docker {
+namespace spec {
+namespace v1 {
+
+/**
+ * Validates if the specified docker v1 image manifest conforms to the
+ * Docker v1 spec. Returns the error if the validation fails.
+ */
+Option<Error> validate(const ImageManifest& manifest);
+
+
+/**
+ * Returns the docker v1 image manifest from the given JSON object.
+ */
+Try<ImageManifest> parse(const JSON::Object& json);
+
+} // namespace v1 {
+
+
+namespace v2 {
+
+/**
+ * Validates if the specified v2 image manifest conforms to the Docker
+ * v2 spec. Returns the error if the validation fails.
+ */
+Option<Error> validate(const ImageManifest& manifest);
+
+
+/**
+ * Returns the docker v1 image manifest from the given JSON object.
+ */
+Try<ImageManifest> parse(const JSON::Object& json);
+
+} // namespace v2 {
+} // namespace spec {
+} // namespace docker {
+
+#endif // __DOCKER_SPEC_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/docker/v1.hpp
----------------------------------------------------------------------
diff --git a/src/docker/v1.hpp b/src/docker/v1.hpp
new file mode 100644
index 0000000..b7ec35f
--- /dev/null
+++ b/src/docker/v1.hpp
@@ -0,0 +1,23 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __DOCKER_V1_HPP__
+#define __DOCKER_V1_HPP__
+
+// ONLY USEFUL AFTER RUNNING PROTOC.
+#include "docker/v1.pb.h"
+
+#endif // __DOCKER_V1_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/docker/v1.proto
----------------------------------------------------------------------
diff --git a/src/docker/v1.proto b/src/docker/v1.proto
new file mode 100644
index 0000000..fab3b08
--- /dev/null
+++ b/src/docker/v1.proto
@@ -0,0 +1,68 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package docker.spec.v1;
+
+/**
+ * Protobuf for the Docker v1 image manifest JSON schema:
+ * https://github.com/docker/docker/blob/master/image/spec/v1.md
+ */
+message ImageManifest {
+ // Following docker code to define and order protobuf fields.
+ // https://github.com/docker/docker/blob/master/image/image.go
+ optional string id = 1;
+ optional string parent = 2;
+
+ // This field is used to comment user added comment. It is not
+ // covered in docker v1 doc, but it is included in docker code.
+ optional string comment = 3;
+
+ optional string created = 4;
+
+ // Container is the id of the container used to commit. It is
+ // not covered in docker v1 doc, but included in docker code.
+ optional string container = 5;
+
+ // TODO(gilbert): Add other config fields.
+ // Currently necessary rumtime config fields only. Please see:
+ // https://github.com/docker/docker/blob/master/runconfig/config.go
+ message Config {
+ optional string Hostname = 1;
+ repeated string Entrypoint = 2;
+ repeated string Env = 3;
+ optional string User = 4;
+ repeated string Cmd = 5;
+ optional string WorkingDir = 6;
+ optional string Volumes = 7;
+
+ // Name of the image as it was passed by the operator.
+ optional string Image = 8;
+
+ // TODO(gilbert): Create a message including string-message
+ // pair to match ExposedPoarts' map (map[nat.Port]struct{}).
+ }
+
+ optional Config container_config = 6;
+
+ optional string docker_version = 7;
+ optional string author = 8;
+
+ optional Config config = 9;
+
+ optional string architecture = 10;
+ optional string os = 11;
+ optional uint32 Size = 12;
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/docker/v2.hpp
----------------------------------------------------------------------
diff --git a/src/docker/v2.hpp b/src/docker/v2.hpp
new file mode 100644
index 0000000..4b14969
--- /dev/null
+++ b/src/docker/v2.hpp
@@ -0,0 +1,23 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __DOCKER_V2_HPP__
+#define __DOCKER_V2_HPP__
+
+// ONLY USEFUL AFTER RUNNING PROTOC.
+#include "docker/v2.pb.h"
+
+#endif // __DOCKER_V2_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/docker/v2.proto
----------------------------------------------------------------------
diff --git a/src/docker/v2.proto b/src/docker/v2.proto
new file mode 100644
index 0000000..97bdf08
--- /dev/null
+++ b/src/docker/v2.proto
@@ -0,0 +1,70 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package docker.spec.v2;
+
+/**
+ * Protobuf for the Docker v2 image manifest JSON schema:
+ * https://github.com/docker/distribution/blob/master/docs/spec/manifest-v2-1.md
+ */
+message ImageManifest {
+ required string name = 1;
+ required string tag = 2;
+ required string architecture = 3;
+
+ message FsLayer {
+ required string blobSum = 1;
+ }
+
+ repeated FsLayer fsLayers = 4;
+
+ message History {
+ message V1Compatibility {
+ required string id = 1;
+ required string parent = 2;
+ }
+
+ required V1Compatibility v1Compatibility = 1;
+ }
+
+ repeated History history = 5;
+ required uint32 schemaVersion = 6;
+
+ message Signatures {
+
+ //JOSE (A JSON Web Signature).
+ message Header {
+
+ //JSON Web Key.
+ message Jwk {
+ required string crv = 1;
+ required string kid = 2;
+ required string kty = 3;
+ required string x = 4;
+ required string y = 5;
+ }
+
+ optional Jwk jwk = 1;
+ required string alg = 2;
+ }
+
+ required Header header = 1;
+ required string signature = 2;
+ required string protected = 3;
+ }
+
+ repeated Signatures signatures = 7;
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/slave/containerizer/mesos/provisioner/docker/message.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/message.hpp b/src/slave/containerizer/mesos/provisioner/docker/message.hpp
index 5c07143..162e4c6 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/message.hpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/message.hpp
@@ -21,8 +21,6 @@
// ONLY USEFUL AFTER RUNNING PROTOC.
#include "slave/containerizer/mesos/provisioner/docker/message.pb.h"
-#include "slave/containerizer/mesos/provisioner/docker/v1.pb.h"
-#include "slave/containerizer/mesos/provisioner/docker/v2.pb.h"
namespace mesos {
namespace internal {
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp b/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp
index 4e305ad..b74c760 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp
@@ -37,7 +37,6 @@
#include <stout/try.hpp>
#include "slave/containerizer/mesos/provisioner/docker/registry_client.hpp"
-#include "slave/containerizer/mesos/provisioner/docker/spec.hpp"
#include "slave/containerizer/mesos/provisioner/docker/token_manager.hpp"
using std::string;
@@ -49,6 +48,7 @@ using process::Owned;
using process::Process;
namespace http = process::http;
+namespace spec = docker::spec;
using http::Pipe;
@@ -67,7 +67,7 @@ public:
const http::URL& authenticationServer,
const Option<Credentials>& credentials);
- Future<v2::ImageManifest> getManifest(
+ Future<spec::v2::ImageManifest> getManifest(
const Image::Name& imageName);
Future<size_t> getBlob(
@@ -167,7 +167,7 @@ RegistryClient::~RegistryClient()
}
-Future<v2::ImageManifest> RegistryClient::getManifest(
+Future<spec::v2::ImageManifest> RegistryClient::getManifest(
const Image::Name& imageName)
{
return dispatch(
@@ -534,7 +534,7 @@ string RegistryClientProcess::getRepositoryPath(
}
-Future<v2::ImageManifest> RegistryClientProcess::getManifest(
+Future<spec::v2::ImageManifest> RegistryClientProcess::getManifest(
const Image::Name& imageName)
{
http::URL manifestURL(registryServer_);
@@ -543,11 +543,11 @@ Future<v2::ImageManifest> RegistryClientProcess::getManifest(
return doHttpGet(manifestURL, None(), false, true, None())
.then(defer(self(), [this] (
- const http::Response& response) -> Future<v2::ImageManifest> {
+ const http::Response& response) -> Future<spec::v2::ImageManifest> {
// TODO(jojy): We dont use the digest that is returned in header.
// This is a good place to validate the manifest.
- Try<v2::ImageManifest> manifest =
+ Try<spec::v2::ImageManifest> manifest =
spec::v2::parse(JSON::parse<JSON::Object>(response.body).get());
if (manifest.isError()) {
return Failure(
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp b/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp
index e73d4d7..bd6dace 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp
@@ -29,6 +29,8 @@
#include <process/http.hpp>
#include <process/process.hpp>
+#include "docker/spec.hpp"
+
#include "slave/containerizer/mesos/provisioner/docker/message.hpp"
namespace mesos {
@@ -79,7 +81,7 @@ public:
* @return Manifest on success.
* Failure on process failure.
*/
- process::Future<v2::ImageManifest> getManifest(
+ process::Future<::docker::spec::v2::ImageManifest> getManifest(
const Image::Name& imageName);
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/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 049d46c..bd2c836 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/registry_puller.cpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/registry_puller.cpp
@@ -28,6 +28,9 @@
#include "slave/containerizer/mesos/provisioner/docker/paths.hpp"
#include "slave/containerizer/mesos/provisioner/docker/registry_client.hpp"
+namespace http = process::http;
+namespace spec = docker::spec;
+
using std::list;
using std::pair;
using std::string;
@@ -40,8 +43,6 @@ using process::Process;
using process::Promise;
using process::Subprocess;
-namespace http = process::http;
-
namespace mesos {
namespace internal {
namespace slave {
@@ -71,7 +72,7 @@ private:
const string& id);
Future<list<pair<string, string>>> downloadLayers(
- const v2::ImageManifest& manifest,
+ const spec::v2::ImageManifest& manifest,
const Image::Name& imageName,
const Path& downloadDir);
@@ -230,7 +231,7 @@ Future<list<pair<string, string>>> RegistryPullerProcess::pull(
// TODO(jojy): Have one outgoing manifest request per image.
return registryClient_->getManifest(imageName)
.then(process::defer(self(), [this, directory, imageName](
- const v2::ImageManifest& manifest) {
+ const spec::v2::ImageManifest& manifest) {
return downloadLayers(manifest, imageName, directory);
}))
.then(process::defer(self(), [this, directory](
@@ -248,7 +249,7 @@ Future<list<pair<string, string>>> RegistryPullerProcess::pull(
Future<list<pair<string, string>>> RegistryPullerProcess::downloadLayers(
- const v2::ImageManifest& manifest,
+ const spec::v2::ImageManifest& manifest,
const Image::Name& imageName,
const Path& directory)
{
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/slave/containerizer/mesos/provisioner/docker/spec.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/spec.cpp b/src/slave/containerizer/mesos/provisioner/docker/spec.cpp
deleted file mode 100644
index 4695b9d..0000000
--- a/src/slave/containerizer/mesos/provisioner/docker/spec.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <stout/foreach.hpp>
-#include <stout/json.hpp>
-#include <stout/protobuf.hpp>
-#include <stout/strings.hpp>
-
-#include "slave/containerizer/mesos/provisioner/docker/spec.hpp"
-
-using std::string;
-
-namespace mesos {
-namespace internal {
-namespace slave {
-namespace docker {
-namespace spec {
-
-namespace v1 {
-
-// Validate if the specified v1 image manifest conforms to
-// the Docker v1 spec.
-Option<Error> validate(const docker::v1::ImageManifest& manifest)
-{
- // TODO(gilbert): Add constraints to validate manifest.
- return None();
-}
-
-
-Try<docker::v1::ImageManifest> parse(const JSON::Object& json)
-{
- Try<docker::v1::ImageManifest> manifest =
- protobuf::parse<docker::v1::ImageManifest>(json);
-
- if (manifest.isError()) {
- return Error("Protobuf parse failed: " + manifest.error());
- }
-
- Option<Error> error = validate(manifest.get());
- if (error.isSome()) {
- return Error("Docker v1 Image Manifest Validation failed: " +
- error.get().message);
- }
-
- return manifest.get();
-}
-
-} // namespace v1 {
-
-
-namespace v2 {
-
-// Validate if the specified v2 image manifest conforms to
-// the Docker v2 spec.
-Option<Error> validate(const docker::v2::ImageManifest& manifest)
-{
- // Validate required fields are present,
- // e.g., repeated fields that has to be >= 1.
- if (manifest.fslayers_size() <= 0) {
- return Error("'fsLayers' field size must be at least one");
- }
-
- if (manifest.history_size() <= 0) {
- return Error("'history' field size must be at least one");
- }
-
- if (manifest.signatures_size() <= 0) {
- return Error("'signatures' field size must be at least one");
- }
-
- // Verify that blobSum and v1Compatibility numbers are equal.
- if (manifest.fslayers_size() != manifest.history_size()) {
- return Error("There should be equal size of 'fsLayers' "
- "with corresponding 'history'");
- }
-
- // Verify 'fsLayers' field.
- foreach (const docker::v2::ImageManifest::FsLayer& fslayer,
- manifest.fslayers()) {
- const string& blobSum = fslayer.blobsum();
- if (!strings::contains(blobSum, ":")) {
- return Error("Incorrect 'blobSum' format: " + blobSum);
- }
- }
-
- return None();
-}
-
-
-Try<docker::v2::ImageManifest> parse(const JSON::Object& json)
-{
- Try<docker::v2::ImageManifest> manifest =
- protobuf::parse<docker::v2::ImageManifest>(json);
-
- if (manifest.isError()) {
- return Error("Protobuf parse failed: " + manifest.error());
- }
-
- Option<Error> error = validate(manifest.get());
- if (error.isSome()) {
- return Error("Docker v2 Image Manifest Validation failed: " +
- error.get().message);
- }
-
- return manifest.get();
-}
-
-} // namespace v2 {
-
-} // namespace spec {
-} // namespace docker {
-} // namespace slave {
-} // namespace internal {
-} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/slave/containerizer/mesos/provisioner/docker/spec.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/spec.hpp b/src/slave/containerizer/mesos/provisioner/docker/spec.hpp
deleted file mode 100644
index 1bd4ac1..0000000
--- a/src/slave/containerizer/mesos/provisioner/docker/spec.hpp
+++ /dev/null
@@ -1,65 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef __PROVISIONER_DOCKER_SPEC_HPP__
-#define __PROVISIONER_DOCKER_SPEC_HPP__
-
-#include <stout/error.hpp>
-#include <stout/json.hpp>
-#include <stout/option.hpp>
-
-#include <mesos/mesos.hpp>
-
-#include "slave/containerizer/mesos/provisioner/docker/message.hpp"
-
-namespace mesos {
-namespace internal {
-namespace slave {
-namespace docker {
-namespace spec {
-
-namespace v1 {
-
-// Validate if the specified v1 image manifest conforms to
-// the Docker v1 spec.
-Option<Error> validate(const docker::v1::ImageManifest& manifest);
-
-// Parse the v1::ImageManifest from the specified JSON object.
-Try<docker::v1::ImageManifest> parse(const JSON::Object& json);
-
-} // namespace v1 {
-
-
-namespace v2 {
-
-// Validate if the specified v2 image manifest conforms to
-// the Docker v2 spec.
-Option<Error> validate(const docker::v2::ImageManifest& manifest);
-
-// TODO(gilbert): Add validations here, e.g., Manifest, Blob, Layout, ImageID.
-
-// Parse the v2::ImageManifest from the specified JSON object.
-Try<docker::v2::ImageManifest> parse(const JSON::Object& json);
-
-} // namespace v2 {
-
-} // namespace spec {
-} // namespace docker {
-} // namespace slave {
-} // namespace internal {
-} // namespace mesos {
-
-#endif // __PROVISIONER_DOCKER_SPEC_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/slave/containerizer/mesos/provisioner/docker/v1.proto
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/v1.proto b/src/slave/containerizer/mesos/provisioner/docker/v1.proto
deleted file mode 100644
index 5aec78b..0000000
--- a/src/slave/containerizer/mesos/provisioner/docker/v1.proto
+++ /dev/null
@@ -1,70 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-import "mesos/mesos.proto";
-
-package mesos.internal.slave.docker.v1;
-
-/**
- * Protobuf for the Docker v1 image manifest JSON schema:
- * https://github.com/docker/docker/blob/master/image/spec/v1.md
- */
-message ImageManifest {
- // Following docker code to define and order protobuf fields.
- // https://github.com/docker/docker/blob/master/image/image.go
- optional string id = 1;
- optional string parent = 2;
-
- // This field is used to comment user added comment. It is not
- // covered in docker v1 doc, but it is included in docker code.
- optional string comment = 3;
-
- optional string created = 4;
-
- // Container is the id of the container used to commit. It is
- // not covered in docker v1 doc, but included in docker code.
- optional string container = 5;
-
- // TODO(gilbert): Add other config fields.
- // Currently necessary rumtime config fields only. Please see:
- // https://github.com/docker/docker/blob/master/runconfig/config.go
- message Config {
- optional string Hostname = 1;
- repeated string Entrypoint = 2;
- repeated string Env = 3;
- optional string User = 4;
- repeated string Cmd = 5;
- optional string WorkingDir = 6;
- optional string Volumes = 7;
-
- // Name of the image as it was passed by the operator.
- optional string Image = 8;
-
- // TODO(gilbert): Create a message including string-message
- // pair to match ExposedPoarts' map (map[nat.Port]struct{}).
- }
-
- optional Config container_config = 6;
-
- optional string docker_version = 7;
- optional string author = 8;
-
- optional Config config = 9;
-
- optional string architecture = 10;
- optional string os = 11;
- optional uint32 Size = 12;
-}
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/src/slave/containerizer/mesos/provisioner/docker/v2.proto
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/v2.proto b/src/slave/containerizer/mesos/provisioner/docker/v2.proto
deleted file mode 100644
index f9e5715..0000000
--- a/src/slave/containerizer/mesos/provisioner/docker/v2.proto
+++ /dev/null
@@ -1,72 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-import "mesos/mesos.proto";
-
-package mesos.internal.slave.docker.v2;
-
-/**
- * Protobuf for the Docker v2 image manifest JSON schema:
- * https://github.com/docker/distribution/blob/master/docs/spec/manifest-v2-1.md
- */
-message ImageManifest {
- required string name = 1;
- required string tag = 2;
- required string architecture = 3;
-
- message FsLayer {
- required string blobSum = 1;
- }
-
- repeated FsLayer fsLayers = 4;
-
- message History {
- message V1Compatibility {
- required string id = 1;
- required string parent = 2;
- }
-
- required V1Compatibility v1Compatibility = 1;
- }
-
- repeated History history = 5;
- required uint32 schemaVersion = 6;
-
- message Signatures {
-
- //JOSE (A JSON Web Signature).
- message Header {
-
- //JSON Web Key.
- message Jwk {
- required string crv = 1;
- required string kid = 2;
- required string kty = 3;
- required string x = 4;
- required string y = 5;
- }
-
- optional Jwk jwk = 1;
- required string alg = 2;
- }
-
- required Header header = 1;
- required string signature = 2;
- required string protected = 3;
- }
-
- repeated Signatures signatures = 7;
-}
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fec0cb/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 d51f342..2d1b2be 100644
--- a/src/tests/containerizer/provisioner_docker_tests.cpp
+++ b/src/tests/containerizer/provisioner_docker_tests.cpp
@@ -32,24 +32,30 @@
#include <process/clock.hpp>
#include <process/future.hpp>
#include <process/gmock.hpp>
+#include <process/io.hpp>
#include <process/owned.hpp>
#include <process/socket.hpp>
#include <process/subprocess.hpp>
#include <process/ssl/gtest.hpp>
+#include "docker/spec.hpp"
+
#include "slave/containerizer/mesos/provisioner/docker/metadata_manager.hpp"
#include "slave/containerizer/mesos/provisioner/docker/paths.hpp"
#include "slave/containerizer/mesos/provisioner/docker/puller.hpp"
#include "slave/containerizer/mesos/provisioner/docker/registry_client.hpp"
#include "slave/containerizer/mesos/provisioner/docker/registry_puller.hpp"
-#include "slave/containerizer/mesos/provisioner/docker/spec.hpp"
#include "slave/containerizer/mesos/provisioner/docker/store.hpp"
#include "slave/containerizer/mesos/provisioner/docker/token_manager.hpp"
#include "tests/mesos.hpp"
#include "tests/utils.hpp"
+namespace io = process::io;
+namespace slave = mesos::internal::slave;
+namespace spec = ::docker::spec;
+
using std::list;
using std::map;
using std::pair;
@@ -59,14 +65,20 @@ using std::vector;
using process::Clock;
using process::Future;
using process::Owned;
+using process::Promise;
+using process::Subprocess;
using process::network::Socket;
-using namespace process;
-using namespace mesos::internal::slave;
-using namespace mesos::internal::slave::docker;
-using namespace mesos::internal::slave::docker::paths;
-using namespace mesos::internal::slave::docker::registry;
+using slave::docker::parseImageName;
+using slave::docker::Puller;
+using slave::docker::RegistryPuller;
+
+using slave::docker::paths::getImageLayerRootfsPath;
+
+using slave::docker::registry::RegistryClient;
+using slave::docker::registry::Token;
+using slave::docker::registry::TokenManager;
namespace mesos {
namespace internal {
@@ -382,9 +394,7 @@ TEST_F(DockerSpecTest, SerializeV1DockerManifest)
Try<JSON::Object> json = JSON::parse<JSON::Object>(stringify(manifestJson));
ASSERT_SOME(json);
- Try<slave::docker::v1::ImageManifest> manifest =
- spec::v1::parse(json.get());
-
+ Try<spec::v1::ImageManifest> manifest = spec::v1::parse(json.get());
ASSERT_SOME(manifest);
EXPECT_EQ(
@@ -514,9 +524,7 @@ TEST_F(DockerSpecTest, SerializeV2DockerManifest)
Try<JSON::Object> json = JSON::parse<JSON::Object>(stringify(manifestJson));
ASSERT_SOME(json);
- Try<slave::docker::v2::ImageManifest> manifest =
- spec::v2::parse(json.get());
-
+ Try<spec::v2::ImageManifest> manifest = spec::v2::parse(json.get());
ASSERT_SOME(manifest);
EXPECT_EQ(manifest.get().name(), "dmcgowan/test-image");
@@ -562,9 +570,7 @@ TEST_F(DockerSpecTest, SerializeV2DockerInvalidManifest)
ASSERT_SOME(json);
- Try<slave::docker::v2::ImageManifest> manifest =
- spec::v2::parse(json.get());
-
+ Try<spec::v2::ImageManifest> manifest = spec::v2::parse(json.get());
EXPECT_ERROR(manifest);
}
@@ -601,9 +607,7 @@ TEST_F(DockerSpecTest, ValidationV2DockerManifestFsLayersNonEmpty)
Try<JSON::Object> json = JSON::parse<JSON::Object>(stringify(manifestJson));
ASSERT_SOME(json);
- Try<slave::docker::v2::ImageManifest> manifest =
- spec::v2::parse(json.get());
-
+ Try<spec::v2::ImageManifest> manifest = spec::v2::parse(json.get());
EXPECT_ERROR(manifest);
}
@@ -627,9 +631,7 @@ TEST_F(DockerSpecTest, ValidationV2DockerManifestSignaturesNonEmpty)
Try<JSON::Object> json = JSON::parse<JSON::Object>(stringify(manifestJson));
ASSERT_SOME(json);
- Try<slave::docker::v2::ImageManifest> manifest =
- spec::v2::parse(json.get());
-
+ Try<spec::v2::ImageManifest> manifest = spec::v2::parse(json.get());
EXPECT_ERROR(manifest);
}
@@ -799,7 +801,7 @@ TEST_F(RegistryClientTest, SimpleGetManifest)
ASSERT_SOME(registryClient);
- Future<v2::ImageManifest> manifestResponse =
+ Future<spec::v2::ImageManifest> manifestResponse =
registryClient.get()->getManifest(parseImageName("library/busybox"));
const string unauthResponseHeaders = "Www-Authenticate: Bearer"
@@ -1129,7 +1131,7 @@ TEST_F(RegistryClientTest, SimpleRegistryPuller)
Future<Socket> blobServerAcceptSock = blobServer.get().accept();
- Flags flags;
+ slave::Flags flags;
process::network::Address address = server.get().address().get();
const string url = "https://" + address.hostname().get() + ":" +
stringify(address.port);