Apache Mesos
spec.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __MESOS_DOCKER_SPEC_HPP__
18 #define __MESOS_DOCKER_SPEC_HPP__
19 
20 #include <iostream>
21 #include <string>
22 
23 #include <stout/error.hpp>
24 #include <stout/json.hpp>
25 #include <stout/option.hpp>
26 #include <stout/try.hpp>
27 
28 // ONLY USEFUL AFTER RUNNING PROTOC.
29 #include <mesos/docker/spec.pb.h>
30 
31 #include <mesos/docker/v1.hpp>
32 #include <mesos/docker/v2.hpp>
33 
34 namespace docker {
35 namespace spec {
36 
37 // The prefix of whiteout files in a docker image.
38 constexpr char WHITEOUT_PREFIX[] = ".wh.";
39 
40 
41 // The prefix of opaque whiteout files in a docker image.
42 constexpr char WHITEOUT_OPAQUE_PREFIX[] = ".wh..wh..opq";
43 
44 
45 // Parse the docker image reference. Docker expects the image
46 // reference to be in the following format:
47 // [REGISTRY_HOST[:REGISTRY_PORT]/]REPOSITORY[:TAG|@TYPE:DIGEST]
48 //
49 // This format is inherently ambiguous when dealing with repository
50 // names that include forward slashes. To disambiguate, the docker
51 // code looks for '.', or ':', or 'localhost' to decide if the first
52 // component is a registry or a repository name. For more detail,
53 // drill into the implementation of docker pull.
54 //
55 // See docker implementation:
56 // https://github.com/docker/distribution/blob/master/reference/reference.go
57 Try<ImageReference> parseImageReference(const std::string& s);
58 
59 
60 std::ostream& operator<<(std::ostream& stream, const ImageReference& reference);
61 
62 
63 // Returns the port of a docker registry.
64 Result<int> getRegistryPort(const std::string& registry);
65 
66 
67 // Returns the scheme of a docker registry.
68 Try<std::string> getRegistryScheme(const std::string& registry);
69 
70 
71 // Returns the host of a docker registry.
72 std::string getRegistryHost(const std::string& registry);
73 
74 
75 // Returns the hashmap<registry_URL, spec::DockerConfigAuth> by
76 // parsing the docker config file from a JSON object.
78  const JSON::Object& _config);
79 
80 
81 // Returns the hashmap<registry_URL, spec::DockerConfigAuth> by
82 // parsing the docker config file from a string.
84 
85 
86 // Find the host from a docker config auth url.
87 std::string parseAuthUrl(const std::string& _url);
88 
89 
90 namespace v1 {
91 
92 // Validates if the specified docker v1 image manifest conforms to the
93 // Docker v1 spec. Returns the error if the validation fails.
94 Option<Error> validate(const ImageManifest& manifest);
95 
96 
97 // Returns the docker v1 image manifest from the given JSON object.
99 
100 
101 // Returns the docker v1 image manifest from the given string.
102 Try<ImageManifest> parse(const std::string& s);
103 
104 } // namespace v1 {
105 
106 
107 namespace v2 {
108 
109 // Validates if the specified v2 image manifest conforms to the Docker
110 // v2 spec. Returns the error if the validation fails.
111 Option<Error> validate(const ImageManifest& manifest);
112 
113 
114 // Returns the docker v2 image manifest from the given JSON object.
116 
117 
118 // Returns the docker v2 image manifest from the given string.
119 Try<ImageManifest> parse(const std::string& s);
120 
121 } // namespace v2 {
122 } // namespace spec {
123 } // namespace docker {
124 
125 #endif // __MESOS_DOCKER_SPEC_HPP__
std::string getRegistryHost(const std::string &registry)
std::string parseAuthUrl(const std::string &_url)
Try< ImageReference > parseImageReference(const std::string &s)
constexpr char WHITEOUT_PREFIX[]
Definition: spec.hpp:38
Definition: check.hpp:33
Try< hashmap< std::string, Config::Auth > > parseAuthConfig(const JSON::Object &_config)
std::ostream & operator<<(std::ostream &stream, const ImageReference &reference)
Option< Error > validate(const ImageManifest &manifest)
constexpr char WHITEOUT_OPAQUE_PREFIX[]
Definition: spec.hpp:42
URI manifest(const std::string &repository, const std::string &reference, const std::string &registry, const Option< std::string > &scheme=None(), const Option< int > &port=None())
Definition: docker.hpp:47
Result< int > getRegistryPort(const std::string &registry)
Definition: check.hpp:30
Definition: json.hpp:154
void json(JSON::ObjectWriter *writer, const Task &task)
Try< std::string > getRegistryScheme(const std::string &registry)
Try< ImageManifest > parse(const JSON::Object &json)
Definition: spec.hpp:34