Browse code

Moby vendoring

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>

Flavio Crisciani authored on 2017/05/25 03:29:08
Showing 113 changed files
... ...
@@ -11,7 +11,7 @@ github.com/coreos/etcd 925d1d74cec8c3b169c52fd4b2dc234a35934fce
11 11
 github.com/coreos/go-systemd b4a58d95188dd092ae20072bac14cece0e67c388
12 12
 github.com/deckarep/golang-set ef32fa3046d9f249d399f98ebaf9be944430fd1d
13 13
 
14
-github.com/docker/docker 9c96768eae4b3a65147b47a55c850c103ab8972d
14
+github.com/docker/docker e18f50891a92786c43d467e012a2404edab416d3 https://github.com/fcrisciani/docker
15 15
 github.com/docker/go-connections 34b5052da6b11e27f5f2e357b38b571ddddd3928
16 16
 github.com/docker/go-events 2e7d352816128aa84f4d29b2a21d400133701a0d
17 17
 github.com/docker/go-units 8e2d4523730c73120e10d4652f36ad6010998f4e
... ...
@@ -19,11 +19,11 @@ github.com/docker/libkv 1d8431073ae03cdaedb198a89722f3aab6d418ef
19 19
 
20 20
 github.com/godbus/dbus 5f6efc7ef2759c81b7ba876593971bfce311eab3
21 21
 github.com/gogo/protobuf 8d70fb3182befc465c4a1eac8ad4d38ff49778e2
22
-github.com/golang/protobuf/proto f7137ae6b19afbfd61a94b746fda3b3fe0491874
22
+github.com/golang/protobuf f7137ae6b19afbfd61a94b746fda3b3fe0491874
23 23
 github.com/gorilla/context 215affda49addc4c8ef7e2534915df2c8c35c6cd
24 24
 github.com/gorilla/mux 8096f47503459bcc74d1f4c487b7e6e42e5746b5
25
-github.com/hashicorp/consul/api 954aec66231b79c161a4122b023fbcad13047f79
26
-github.com/hashicorp/go-msgpack/codec 71c2886f5a673a35f909803f38ece5810165097b
25
+github.com/hashicorp/consul 954aec66231b79c161a4122b023fbcad13047f79
26
+github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b
27 27
 github.com/hashicorp/go-multierror 2167c8ec40776024589f483a6b836489e47e1049
28 28
 github.com/hashicorp/memberlist v0.1.0
29 29
 github.com/sean-/seed e2103e2c35297fb7e17febb81e49b312087a2372
... ...
@@ -31,11 +31,13 @@ github.com/hashicorp/go-sockaddr acd314c5781ea706c710d9ea70069fd2e110d61d
31 31
 github.com/hashicorp/serf 598c54895cc5a7b1a24a398d635e8c0ea0959870
32 32
 github.com/mattn/go-shellwords 525bedee691b5a8df547cb5cf9f86b7fb1883e24
33 33
 github.com/miekg/dns d27455715200c7d3e321a1e5cadb27c9ee0b0f02
34
-github.com/opencontainers/runc/libcontainer ba1568de399395774ad84c2ace65937814c542ed
35
-github.com/samuel/go-zookeeper/zk d0e0d8e11f318e000a8cc434616d69e329edc374
34
+github.com/opencontainers/runc ba1568de399395774ad84c2ace65937814c542ed
35
+github.com/opencontainers/image-spec 56b55a17598362bd1bf78c9c307738335a2510eb
36
+github.com/opencontainers/go-digest eaa60544f31ccf3b0653b1a118b76d33418ff41b
37
+github.com/samuel/go-zookeeper d0e0d8e11f318e000a8cc434616d69e329edc374
36 38
 github.com/seccomp/libseccomp-golang 1b506fc7c24eec5a3693cdcbed40d9c226cfc6a1
37 39
 github.com/stretchr/testify dab07ac62d4905d3e48d17dc549c684ac3b7c15a
38
-github.com/syndtr/gocapability/capability 2c00daeb6c3b45114c80ac44119e7b8801fdd852
40
+github.com/syndtr/gocapability 2c00daeb6c3b45114c80ac44119e7b8801fdd852
39 41
 github.com/ugorji/go f1f1a805ed361a0e078bb537e4ea78cd37dcf065
40 42
 github.com/vishvananda/netlink 1e86b2bee5b6a7d377e4c02bb7f98209d6a7297c
41 43
 github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25
... ...
@@ -176,7 +176,7 @@
176 176
 
177 177
    END OF TERMS AND CONDITIONS
178 178
 
179
-   Copyright 2013-2016 Docker, Inc.
179
+   Copyright 2013-2017 Docker, Inc.
180 180
 
181 181
    Licensed under the Apache License, Version 2.0 (the "License");
182 182
    you may not use this file except in compliance with the License.
... ...
@@ -1,5 +1,5 @@
1 1
 Docker
2
-Copyright 2012-2016 Docker, Inc.
2
+Copyright 2012-2017 Docker, Inc.
3 3
 
4 4
 This product includes software developed at Docker, Inc. (https://www.docker.com).
5 5
 
... ...
@@ -1,270 +1,80 @@
1
-Docker: the container engine [![Release](https://img.shields.io/github/release/docker/docker.svg)](https://github.com/docker/docker/releases/latest)
2
-============================
1
+### Docker users, see [Moby and Docker](https://mobyproject.org/#moby-and-docker) to clarify the relationship between the projects
3 2
 
4
-Docker is an open source project to pack, ship and run any application
5
-as a lightweight container.
3
+### Docker maintainers and contributors, see [Transitioning to Moby](#transitioning-to-moby) for more details
6 4
 
7
-Docker containers are both *hardware-agnostic* and *platform-agnostic*.
8
-This means they can run anywhere, from your laptop to the largest
9
-cloud compute instance and everything in between - and they don't require
10
-you to use a particular language, framework or packaging system. That
11
-makes them great building blocks for deploying and scaling web apps,
12
-databases, and backend services without depending on a particular stack
13
-or provider.
5
+The Moby Project
6
+================
14 7
 
15
-Docker began as an open-source implementation of the deployment engine which
16
-powered [dotCloud](http://web.archive.org/web/20130530031104/https://www.dotcloud.com/),
17
-a popular Platform-as-a-Service. It benefits directly from the experience
18
-accumulated over several years of large-scale operation and support of hundreds
19
-of thousands of applications and databases.
8
+![Moby Project logo](docs/static_files/moby-project-logo.png "The Moby Project")
20 9
 
21
-![Docker logo](docs/static_files/docker-logo-compressed.png "Docker")
10
+Moby is an open-source project created by Docker to advance the software containerization movement.
11
+It provides a “Lego set” of dozens of components, the framework for assembling them into custom container-based systems, and a place for all container enthusiasts to experiment and exchange ideas.
22 12
 
23
-## Security Disclosure
13
+# Moby
24 14
 
25
-Security is very important to us. If you have any issue regarding security,
26
-please disclose the information responsibly by sending an email to
27
-security@docker.com and not by creating a GitHub issue.
15
+## Overview
28 16
 
29
-## Better than VMs
17
+At the core of Moby is a framework to assemble specialized container systems.
18
+It provides:
30 19
 
31
-A common method for distributing applications and sandboxing their
32
-execution is to use virtual machines, or VMs. Typical VM formats are
33
-VMware's vmdk, Oracle VirtualBox's vdi, and Amazon EC2's ami. In theory
34
-these formats should allow every developer to automatically package
35
-their application into a "machine" for easy distribution and deployment.
36
-In practice, that almost never happens, for a few reasons:
20
+- A library of containerized components for all vital aspects of a container system: OS, container runtime, orchestration, infrastructure management, networking, storage, security, build, image distribution, etc.
21
+- Tools to assemble the components into runnable artifacts for a variety of platforms and architectures: bare metal (both x86 and Arm); executables for Linux, Mac and Windows; VM images for popular cloud and virtualization providers.
22
+- A set of reference assemblies which can be used as-is, modified, or used as inspiration to create your own.
37 23
 
38
-  * *Size*: VMs are very large which makes them impractical to store
39
-     and transfer.
40
-  * *Performance*: running VMs consumes significant CPU and memory,
41
-    which makes them impractical in many scenarios, for example local
42
-    development of multi-tier applications, and large-scale deployment
43
-    of cpu and memory-intensive applications on large numbers of
44
-    machines.
45
-  * *Portability*: competing VM environments don't play well with each
46
-     other. Although conversion tools do exist, they are limited and
47
-     add even more overhead.
48
-  * *Hardware-centric*: VMs were designed with machine operators in
49
-    mind, not software developers. As a result, they offer very
50
-    limited tooling for what developers need most: building, testing
51
-    and running their software. For example, VMs offer no facilities
52
-    for application versioning, monitoring, configuration, logging or
53
-    service discovery.
24
+All Moby components are containers, so creating new components is as easy as building a new OCI-compatible container.
54 25
 
55
-By contrast, Docker relies on a different sandboxing method known as
56
-*containerization*. Unlike traditional virtualization, containerization
57
-takes place at the kernel level. Most modern operating system kernels
58
-now support the primitives necessary for containerization, including
59
-Linux with [openvz](https://openvz.org),
60
-[vserver](http://linux-vserver.org) and more recently
61
-[lxc](https://linuxcontainers.org/), Solaris with
62
-[zones](https://docs.oracle.com/cd/E26502_01/html/E29024/preface-1.html#scrolltoc),
63
-and FreeBSD with
64
-[Jails](https://www.freebsd.org/doc/handbook/jails.html).
26
+## Principles
65 27
 
66
-Docker builds on top of these low-level primitives to offer developers a
67
-portable format and runtime environment that solves all four problems.
68
-Docker containers are small (and their transfer can be optimized with
69
-layers), they have basically zero memory and cpu overhead, they are
70
-completely portable, and are designed from the ground up with an
71
-application-centric design.
28
+Moby is an open project guided by strong principles, but modular, flexible and without too strong an opinion on user experience, so it is open to the community to help set its direction.
29
+The guiding principles are:
72 30
 
73
-Perhaps best of all, because Docker operates at the OS level, it can still be
74
-run inside a VM!
31
+- Batteries included but swappable: Moby includes enough components to build fully featured container system, but its modular architecture ensures that most of the components can be swapped by different implementations.
32
+- Usable security: Moby will provide secure defaults without compromising usability.
33
+- Container centric: Moby is built with containers, for running containers.
75 34
 
76
-## Plays well with others
35
+With Moby, you should be able to describe all the components of your distributed application, from the high-level configuration files down to the kernel you would like to use and build and deploy it easily.
77 36
 
78
-Docker does not require you to buy into a particular programming
79
-language, framework, packaging system, or configuration language.
37
+Moby uses [containerd](https://github.com/containerd/containerd) as the default container runtime.
80 38
 
81
-Is your application a Unix process? Does it use files, tcp connections,
82
-environment variables, standard Unix streams and command-line arguments
83
-as inputs and outputs? Then Docker can run it.
39
+## Audience
84 40
 
85
-Can your application's build be expressed as a sequence of such
86
-commands? Then Docker can build it.
41
+Moby is recommended for anyone who wants to assemble a container-based system. This includes:
87 42
 
88
-## Escape dependency hell
43
+- Hackers who want to customize or patch their Docker build
44
+- System engineers or integrators building a container system
45
+- Infrastructure providers looking to adapt existing container systems to their environment
46
+- Container enthusiasts who want to experiment with the latest container tech
47
+- Open-source developers looking to test their project in a variety of different systems
48
+- Anyone curious about Docker internals and how it’s built
89 49
 
90
-A common problem for developers is the difficulty of managing all
91
-their application's dependencies in a simple and automated way.
50
+Moby is NOT recommended for:
92 51
 
93
-This is usually difficult for several reasons:
52
+- Application developers looking for an easy way to run their applications in containers. We recommend Docker CE instead.
53
+- Enterprise IT and development teams looking for a ready-to-use, commercially supported container platform. We recommend Docker EE instead.
54
+- Anyone curious about containers and looking for an easy way to learn. We recommend the docker.com website instead.
94 55
 
95
-  * *Cross-platform dependencies*. Modern applications often depend on
96
-    a combination of system libraries and binaries, language-specific
97
-    packages, framework-specific modules, internal components
98
-    developed for another project, etc. These dependencies live in
99
-    different "worlds" and require different tools - these tools
100
-    typically don't work well with each other, requiring awkward
101
-    custom integrations.
56
+# Transitioning to Moby
102 57
 
103
-  * *Conflicting dependencies*. Different applications may depend on
104
-    different versions of the same dependency. Packaging tools handle
105
-    these situations with various degrees of ease - but they all
106
-    handle them in different and incompatible ways, which again forces
107
-    the developer to do extra work.
58
+Docker is transitioning all of its open source collaborations to the Moby project going forward.
59
+During the transition, all open source activity should continue as usual.
108 60
 
109
-  * *Custom dependencies*. A developer may need to prepare a custom
110
-    version of their application's dependency. Some packaging systems
111
-    can handle custom versions of a dependency, others can't - and all
112
-    of them handle it differently.
61
+We are proposing the following list of changes:
113 62
 
63
+- splitting up the engine into more open components
64
+- removing the docker UI, SDK etc to keep them in the Docker org
65
+- clarifying that the project is not limited to the engine, but to the assembly of all the individual components of the Docker platform
66
+- open-source new tools & components which we currently use to assemble the Docker product, but could benefit the community
67
+- defining an open, community-centric governance inspired by the Fedora project (a very successful example of balancing the needs of the community with the constraints of the primary corporate sponsor)
114 68
 
115
-Docker solves the problem of dependency hell by giving the developer a simple
116
-way to express *all* their application's dependencies in one place, while
117
-streamlining the process of assembling them. If this makes you think of
118
-[XKCD 927](https://xkcd.com/927/), don't worry. Docker doesn't
119
-*replace* your favorite packaging systems. It simply orchestrates
120
-their use in a simple and repeatable way. How does it do that? With
121
-layers.
69
+-----
122 70
 
123
-Docker defines a build as running a sequence of Unix commands, one
124
-after the other, in the same container. Build commands modify the
125
-contents of the container (usually by installing new files on the
126
-filesystem), the next command modifies it some more, etc. Since each
127
-build command inherits the result of the previous commands, the
128
-*order* in which the commands are executed expresses *dependencies*.
129
-
130
-Here's a typical Docker build process:
131
-
132
-```bash
133
-FROM ubuntu:12.04
134
-RUN apt-get update && apt-get install -y python python-pip curl
135
-RUN curl -sSL https://github.com/shykes/helloflask/archive/master.tar.gz | tar -xzv
136
-RUN cd helloflask-master && pip install -r requirements.txt
137
-```
138
-
139
-Note that Docker doesn't care *how* dependencies are built - as long
140
-as they can be built by running a Unix command in a container.
141
-
142
-
143
-Getting started
144
-===============
145
-
146
-Docker can be installed either on your computer for building applications or
147
-on servers for running them. To get started, [check out the installation
148
-instructions in the
149
-documentation](https://docs.docker.com/engine/installation/).
150
-
151
-Usage examples
152
-==============
153
-
154
-Docker can be used to run short-lived commands, long-running daemons
155
-(app servers, databases, etc.), interactive shell sessions, etc.
156
-
157
-You can find a [list of real-world
158
-examples](https://docs.docker.com/engine/examples/) in the
159
-documentation.
160
-
161
-Under the hood
162
-
163
-Under the hood, Docker is built on the following components:
164
-
165
-* The
166
-  [cgroups](https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt)
167
-  and
168
-  [namespaces](http://man7.org/linux/man-pages/man7/namespaces.7.html)
169
-  capabilities of the Linux kernel
170
-* The [Go](https://golang.org) programming language
171
-* The [Docker Image Specification](https://github.com/docker/docker/blob/master/image/spec/v1.md)
172
-* The [Libcontainer Specification](https://github.com/opencontainers/runc/blob/master/libcontainer/SPEC.md)
173
-
174
-Contributing to Docker [![GoDoc](https://godoc.org/github.com/docker/docker?status.svg)](https://godoc.org/github.com/docker/docker)
175
-======================
176
-
177
-| **Master** (Linux) | **Experimental** (Linux) | **Windows** | **FreeBSD** |
178
-|------------------|----------------------|---------|---------|
179
-| [![Jenkins Build Status](https://jenkins.dockerproject.org/view/Docker/job/Docker%20Master/badge/icon)](https://jenkins.dockerproject.org/view/Docker/job/Docker%20Master/) | [![Jenkins Build Status](https://jenkins.dockerproject.org/view/Docker/job/Docker%20Master%20%28experimental%29/badge/icon)](https://jenkins.dockerproject.org/view/Docker/job/Docker%20Master%20%28experimental%29/) | [![Build Status](http://jenkins.dockerproject.org/job/Docker%20Master%20(windows)/badge/icon)](http://jenkins.dockerproject.org/job/Docker%20Master%20(windows)/) | [![Build Status](http://jenkins.dockerproject.org/job/Docker%20Master%20(freebsd)/badge/icon)](http://jenkins.dockerproject.org/job/Docker%20Master%20(freebsd)/) |
180
-
181
-Want to hack on Docker? Awesome! We have [instructions to help you get
182
-started contributing code or documentation](https://docs.docker.com/opensource/project/who-written-for/).
183
-
184
-These instructions are probably not perfect, please let us know if anything
185
-feels wrong or incomplete. Better yet, submit a PR and improve them yourself.
186
-
187
-Getting the development builds
188
-==============================
189
-
190
-Want to run Docker from a master build? You can download
191
-master builds at [master.dockerproject.org](https://master.dockerproject.org).
192
-They are updated with each commit merged into the master branch.
193
-
194
-Don't know how to use that super cool new feature in the master build? Check
195
-out the master docs at
196
-[docs.master.dockerproject.org](http://docs.master.dockerproject.org).
197
-
198
-How the project is run
199
-======================
200
-
201
-Docker is a very, very active project. If you want to learn more about how it is run,
202
-or want to get more involved, the best place to start is [the project directory](https://github.com/docker/docker/tree/master/project).
203
-
204
-We are always open to suggestions on process improvements, and are always looking for more maintainers.
205
-
206
-### Talking to other Docker users and contributors
207
-
208
-<table class="tg">
209
-  <col width="45%">
210
-  <col width="65%">
211
-  <tr>
212
-    <td>Internet&nbsp;Relay&nbsp;Chat&nbsp;(IRC)</td>
213
-    <td>
214
-      <p>
215
-        IRC is a direct line to our most knowledgeable Docker users; we have
216
-        both the  <code>#docker</code> and <code>#docker-dev</code> group on
217
-        <strong>irc.freenode.net</strong>.
218
-        IRC is a rich chat protocol but it can overwhelm new users. You can search
219
-        <a href="https://botbot.me/freenode/docker/#" target="_blank">our chat archives</a>.
220
-      </p>
221
-      Read our <a href="https://docs.docker.com/opensource/get-help/#/irc-quickstart" target="_blank">IRC quickstart guide</a> for an easy way to get started.
222
-    </td>
223
-  </tr>
224
-  <tr>
225
-    <td>Docker Community Forums</td>
226
-    <td>
227
-      The <a href="https://forums.docker.com/c/open-source-projects/de" target="_blank">Docker Engine</a>
228
-      group is for users of the Docker Engine project.
229
-    </td>
230
-  </tr>
231
-  <tr>
232
-    <td>Google Groups</td>
233
-    <td>
234
-      The <a href="https://groups.google.com/forum/#!forum/docker-dev"
235
-      target="_blank">docker-dev</a> group is for contributors and other people
236
-      contributing to the Docker project.  You can join this group without a
237
-      Google account by sending an email to <a
238
-      href="mailto:docker-dev+subscribe@googlegroups.com">docker-dev+subscribe@googlegroups.com</a>.
239
-      You'll receive a join-request message; simply reply to the message to
240
-      confirm your subscription.
241
-    </td>
242
-  </tr>
243
-  <tr>
244
-    <td>Twitter</td>
245
-    <td>
246
-      You can follow <a href="https://twitter.com/docker/" target="_blank">Docker's Twitter feed</a>
247
-      to get updates on our products. You can also tweet us questions or just
248
-      share blogs or stories.
249
-    </td>
250
-  </tr>
251
-  <tr>
252
-    <td>Stack Overflow</td>
253
-    <td>
254
-      Stack Overflow has over 7000 Docker questions listed. We regularly
255
-      monitor <a href="https://stackoverflow.com/search?tab=newest&q=docker" target="_blank">Docker questions</a>
256
-      and so do many other knowledgeable Docker users.
257
-    </td>
258
-  </tr>
259
-</table>
260
-
261
-### Legal
71
+Legal
72
+=====
262 73
 
263 74
 *Brought to you courtesy of our legal counsel. For more context,
264
-please see the [NOTICE](https://github.com/docker/docker/blob/master/NOTICE) document in this repo.*
75
+please see the [NOTICE](https://github.com/moby/moby/blob/master/NOTICE) document in this repo.*
265 76
 
266
-Use and transfer of Docker may be subject to certain restrictions by the
77
+Use and transfer of Moby may be subject to certain restrictions by the
267 78
 United States and other governments.
268 79
 
269 80
 It is your responsibility to ensure that your use and/or transfer does not
... ...
@@ -275,30 +85,6 @@ For more information, please see https://www.bis.doc.gov
275 275
 
276 276
 Licensing
277 277
 =========
278
-Docker is licensed under the Apache License, Version 2.0. See
279
-[LICENSE](https://github.com/docker/docker/blob/master/LICENSE) for the full
278
+Moby is licensed under the Apache License, Version 2.0. See
279
+[LICENSE](https://github.com/moby/moby/blob/master/LICENSE) for the full
280 280
 license text.
281
-
282
-Other Docker Related Projects
283
-=============================
284
-There are a number of projects under development that are based on Docker's
285
-core technology. These projects expand the tooling built around the
286
-Docker platform to broaden its application and utility.
287
-
288
-* [Docker Registry](https://github.com/docker/distribution): Registry
289
-server for Docker (hosting/delivery of repositories and images)
290
-* [Docker Machine](https://github.com/docker/machine): Machine management
291
-for a container-centric world
292
-* [Docker Swarm](https://github.com/docker/swarm): A Docker-native clustering
293
-system
294
-* [Docker Compose](https://github.com/docker/compose) (formerly Fig):
295
-Define and run multi-container apps
296
-* [Kitematic](https://github.com/docker/kitematic): The easiest way to use
297
-Docker on Mac and Windows
298
-
299
-If you know of another project underway that should be listed here, please help
300
-us keep this list up-to-date by submitting a PR.
301
-
302
-Awesome-Docker
303
-==============
304
-You can find more projects, tools and articles related to Docker on the [awesome-docker list](https://github.com/veggiemonk/awesome-docker). Add your project there.
... ...
@@ -14,8 +14,8 @@ It consists of various components in this repository:
14 14
 
15 15
 The API is defined by the [Swagger](http://swagger.io/specification/) definition in `api/swagger.yaml`. This definition can be used to:
16 16
 
17
-1. To automatically generate documentation.
18
-2. To automatically generate the Go server and client. (A work-in-progress.)
17
+1. Automatically generate documentation.
18
+2. Automatically generate the Go server and client. (A work-in-progress.)
19 19
 3. Provide a machine readable version of the API for introspecting what it can do, automatically generating clients for other languages, etc.
20 20
 
21 21
 ## Updating the API documentation
... ...
@@ -4,7 +4,6 @@ import (
4 4
 	"bufio"
5 5
 	"io"
6 6
 	"net"
7
-	"os"
8 7
 
9 8
 	"github.com/docker/docker/api/types/container"
10 9
 	"github.com/docker/docker/api/types/filters"
... ...
@@ -98,6 +97,7 @@ type ContainerStartOptions struct {
98 98
 // about files to copy into a container
99 99
 type CopyToContainerOptions struct {
100 100
 	AllowOverwriteDirWithFile bool
101
+	CopyUIDGID                bool
101 102
 }
102 103
 
103 104
 // EventsOptions holds parameters to filter events with.
... ...
@@ -160,9 +160,10 @@ type ImageBuildOptions struct {
160 160
 	ShmSize        int64
161 161
 	Dockerfile     string
162 162
 	Ulimits        []*units.Ulimit
163
-	// See the parsing of buildArgs in api/server/router/build/build_routes.go
164
-	// for an explaination of why BuildArgs needs to use *string instead of
165
-	// just a string
163
+	// BuildArgs needs to be a *string instead of just a string so that
164
+	// we can tell the difference between "" (empty string) and no value
165
+	// at all (nil). See the parsing of buildArgs in
166
+	// api/server/router/build/build_routes.go for even more info.
166 167
 	BuildArgs   map[string]*string
167 168
 	AuthConfigs map[string]AuthConfig
168 169
 	Context     io.Reader
... ...
@@ -175,6 +176,8 @@ type ImageBuildOptions struct {
175 175
 	// specified here do not need to have a valid parent chain to match cache.
176 176
 	CacheFrom   []string
177 177
 	SecurityOpt []string
178
+	ExtraHosts  []string // List of extra hosts
179
+	Target      string
178 180
 }
179 181
 
180 182
 // ImageBuildResponse holds information
... ...
@@ -192,8 +195,8 @@ type ImageCreateOptions struct {
192 192
 
193 193
 // ImageImportSource holds source information for ImageImport
194 194
 type ImageImportSource struct {
195
-	Source     io.Reader // Source is the data to send to the server to create this image from (mutually exclusive with SourceName)
196
-	SourceName string    // SourceName is the name of the image to pull (mutually exclusive with Source)
195
+	Source     io.Reader // Source is the data to send to the server to create this image from. You must set SourceName to "-" to leverage this.
196
+	SourceName string    // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
197 197
 }
198 198
 
199 199
 // ImageImportOptions holds information to import images from the client host.
... ...
@@ -256,18 +259,6 @@ type ResizeOptions struct {
256 256
 	Width  uint
257 257
 }
258 258
 
259
-// VersionResponse holds version information for the client and the server
260
-type VersionResponse struct {
261
-	Client *Version
262
-	Server *Version
263
-}
264
-
265
-// ServerOK returns true when the client could connect to the docker server
266
-// and parse the information received. It returns false otherwise.
267
-func (v VersionResponse) ServerOK() bool {
268
-	return v.Server != nil
269
-}
270
-
271 259
 // NodeListOptions holds parameters to list nodes with.
272 260
 type NodeListOptions struct {
273 261
 	Filters filters.Args
... ...
@@ -285,6 +276,12 @@ type ServiceCreateOptions struct {
285 285
 	//
286 286
 	// This field follows the format of the X-Registry-Auth header.
287 287
 	EncodedRegistryAuth string
288
+
289
+	// QueryRegistry indicates whether the service update requires
290
+	// contacting a registry. A registry may be contacted to retrieve
291
+	// the image digest and manifest, which in turn can be used to update
292
+	// platform or other information about the service.
293
+	QueryRegistry bool
288 294
 }
289 295
 
290 296
 // ServiceCreateResponse contains the information returned to a client
... ...
@@ -318,14 +315,32 @@ type ServiceUpdateOptions struct {
318 318
 	// credentials if they are not given in EncodedRegistryAuth. Valid
319 319
 	// values are "spec" and "previous-spec".
320 320
 	RegistryAuthFrom string
321
+
322
+	// Rollback indicates whether a server-side rollback should be
323
+	// performed. When this is set, the provided spec will be ignored.
324
+	// The valid values are "previous" and "none". An empty value is the
325
+	// same as "none".
326
+	Rollback string
327
+
328
+	// QueryRegistry indicates whether the service update requires
329
+	// contacting a registry. A registry may be contacted to retrieve
330
+	// the image digest and manifest, which in turn can be used to update
331
+	// platform or other information about the service.
332
+	QueryRegistry bool
321 333
 }
322 334
 
323
-// ServiceListOptions holds parameters to list  services with.
335
+// ServiceListOptions holds parameters to list services with.
324 336
 type ServiceListOptions struct {
325 337
 	Filters filters.Args
326 338
 }
327 339
 
328
-// TaskListOptions holds parameters to list  tasks with.
340
+// ServiceInspectOptions holds parameters related to the "service inspect"
341
+// operation.
342
+type ServiceInspectOptions struct {
343
+	InsertDefaults bool
344
+}
345
+
346
+// TaskListOptions holds parameters to list tasks with.
329 347
 type TaskListOptions struct {
330 348
 	Filters filters.Args
331 349
 }
... ...
@@ -356,15 +371,6 @@ type PluginInstallOptions struct {
356 356
 	Args                  []string
357 357
 }
358 358
 
359
-// SecretRequestOption is a type for requesting secrets
360
-type SecretRequestOption struct {
361
-	Source string
362
-	Target string
363
-	UID    string
364
-	GID    string
365
-	Mode   os.FileMode
366
-}
367
-
368 359
 // SwarmUnlockKeyResponse contains the response for Engine API:
369 360
 // GET /swarm/unlockkey
370 361
 type SwarmUnlockKeyResponse struct {
... ...
@@ -7,6 +7,12 @@ import (
7 7
 	"github.com/docker/go-connections/nat"
8 8
 )
9 9
 
10
+// MinimumDuration puts a minimum on user configured duration.
11
+// This is to prevent API error on time unit. For example, API may
12
+// set 3 as healthcheck interval with intention of 3 seconds, but
13
+// Docker interprets it as 3 nanoseconds.
14
+const MinimumDuration = 1 * time.Millisecond
15
+
10 16
 // HealthConfig holds configuration settings for the HEALTHCHECK feature.
11 17
 type HealthConfig struct {
12 18
 	// Test is the test to perform to check that the container is healthy.
... ...
@@ -19,8 +25,9 @@ type HealthConfig struct {
19 19
 	Test []string `json:",omitempty"`
20 20
 
21 21
 	// Zero means to inherit. Durations are expressed as integer nanoseconds.
22
-	Interval time.Duration `json:",omitempty"` // Interval is the time to wait between checks.
23
-	Timeout  time.Duration `json:",omitempty"` // Timeout is the time to wait before considering the check to have hung.
22
+	Interval    time.Duration `json:",omitempty"` // Interval is the time to wait between checks.
23
+	Timeout     time.Duration `json:",omitempty"` // Timeout is the time to wait before considering the check to have hung.
24
+	StartPeriod time.Duration `json:",omitempty"` // The start period for the container to initialize before the retries starts to count down.
24 25
 
25 26
 	// Retries is the number of consecutive failures needed to consider a container as unhealthy.
26 27
 	// Zero means inherit.
27 28
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+package container
1
+
2
+// ----------------------------------------------------------------------------
3
+// DO NOT EDIT THIS FILE
4
+// This file was generated by `swagger generate operation`
5
+//
6
+// See hack/generate-swagger-api.sh
7
+// ----------------------------------------------------------------------------
8
+
9
+// ContainerChangeResponseItem container change response item
10
+// swagger:model ContainerChangeResponseItem
11
+type ContainerChangeResponseItem struct {
12
+
13
+	// Kind of change
14
+	// Required: true
15
+	Kind uint8 `json:"Kind"`
16
+
17
+	// Path to file that has changed
18
+	// Required: true
19
+	Path string `json:"Path"`
20
+}
0 21
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+package container
1
+
2
+// ----------------------------------------------------------------------------
3
+// DO NOT EDIT THIS FILE
4
+// This file was generated by `swagger generate operation`
5
+//
6
+// See hack/generate-swagger-api.sh
7
+// ----------------------------------------------------------------------------
8
+
9
+// ContainerTopOKBody container top o k body
10
+// swagger:model ContainerTopOKBody
11
+type ContainerTopOKBody struct {
12
+
13
+	// Each process running in the container, where each is process is an array of values corresponding to the titles
14
+	// Required: true
15
+	Processes [][]string `json:"Processes"`
16
+
17
+	// The ps column titles
18
+	// Required: true
19
+	Titles []string `json:"Titles"`
20
+}
... ...
@@ -10,9 +10,6 @@ import (
10 10
 	"github.com/docker/go-units"
11 11
 )
12 12
 
13
-// NetworkMode represents the container network stack.
14
-type NetworkMode string
15
-
16 13
 // Isolation represents the isolation technology of a container. The supported
17 14
 // values are platform specific
18 15
 type Isolation string
... ...
@@ -66,6 +63,47 @@ func (n IpcMode) Container() string {
66 66
 	return ""
67 67
 }
68 68
 
69
+// NetworkMode represents the container network stack.
70
+type NetworkMode string
71
+
72
+// IsNone indicates whether container isn't using a network stack.
73
+func (n NetworkMode) IsNone() bool {
74
+	return n == "none"
75
+}
76
+
77
+// IsDefault indicates whether container uses the default network stack.
78
+func (n NetworkMode) IsDefault() bool {
79
+	return n == "default"
80
+}
81
+
82
+// IsPrivate indicates whether container uses its private network stack.
83
+func (n NetworkMode) IsPrivate() bool {
84
+	return !(n.IsHost() || n.IsContainer())
85
+}
86
+
87
+// IsContainer indicates whether container uses a container network stack.
88
+func (n NetworkMode) IsContainer() bool {
89
+	parts := strings.SplitN(string(n), ":", 2)
90
+	return len(parts) > 1 && parts[0] == "container"
91
+}
92
+
93
+// ConnectedContainer is the id of the container which network this container is connected to.
94
+func (n NetworkMode) ConnectedContainer() string {
95
+	parts := strings.SplitN(string(n), ":", 2)
96
+	if len(parts) > 1 {
97
+		return parts[1]
98
+	}
99
+	return ""
100
+}
101
+
102
+//UserDefined indicates user-created network
103
+func (n NetworkMode) UserDefined() string {
104
+	if n.IsUserDefined() {
105
+		return string(n)
106
+	}
107
+	return ""
108
+}
109
+
69 110
 // UsernsMode represents userns mode in the container.
70 111
 type UsernsMode string
71 112
 
... ...
@@ -223,6 +261,17 @@ func (rp *RestartPolicy) IsSame(tp *RestartPolicy) bool {
223 223
 	return rp.Name == tp.Name && rp.MaximumRetryCount == tp.MaximumRetryCount
224 224
 }
225 225
 
226
+// LogMode is a type to define the available modes for logging
227
+// These modes affect how logs are handled when log messages start piling up.
228
+type LogMode string
229
+
230
+// Available logging modes
231
+const (
232
+	LogModeUnset            = ""
233
+	LogModeBlocking LogMode = "blocking"
234
+	LogModeNonBlock LogMode = "non-blocking"
235
+)
236
+
226 237
 // LogConfig represents the logging configuration of the container.
227 238
 type LogConfig struct {
228 239
 	Type   string
... ...
@@ -251,6 +300,7 @@ type Resources struct {
251 251
 	CpusetCpus           string          // CpusetCpus 0-2, 0,1
252 252
 	CpusetMems           string          // CpusetMems 0-2, 0,1
253 253
 	Devices              []DeviceMapping // List of devices to map inside the container
254
+	DeviceCgroupRules    []string        // List of rule to be added to the device cgroup
254 255
 	DiskQuota            int64           // Disk limit (in bytes)
255 256
 	KernelMemory         int64           // Kernel memory limit (in bytes)
256 257
 	MemoryReservation    int64           // Memory soft limit (in bytes)
... ...
@@ -327,7 +377,4 @@ type HostConfig struct {
327 327
 
328 328
 	// Run a custom init inside the container, if null, use the daemon's configured settings
329 329
 	Init *bool `json:",omitempty"`
330
-
331
-	// Custom init path
332
-	InitPath string `json:",omitempty"`
333 330
 }
... ...
@@ -2,23 +2,11 @@
2 2
 
3 3
 package container
4 4
 
5
-import "strings"
6
-
7 5
 // IsValid indicates if an isolation technology is valid
8 6
 func (i Isolation) IsValid() bool {
9 7
 	return i.IsDefault()
10 8
 }
11 9
 
12
-// IsPrivate indicates whether container uses its private network stack.
13
-func (n NetworkMode) IsPrivate() bool {
14
-	return !(n.IsHost() || n.IsContainer())
15
-}
16
-
17
-// IsDefault indicates whether container uses the default network stack.
18
-func (n NetworkMode) IsDefault() bool {
19
-	return n == "default"
20
-}
21
-
22 10
 // NetworkName returns the name of the network stack.
23 11
 func (n NetworkMode) NetworkName() string {
24 12
 	if n.IsBridge() {
... ...
@@ -47,35 +35,7 @@ func (n NetworkMode) IsHost() bool {
47 47
 	return n == "host"
48 48
 }
49 49
 
50
-// IsContainer indicates whether container uses a container network stack.
51
-func (n NetworkMode) IsContainer() bool {
52
-	parts := strings.SplitN(string(n), ":", 2)
53
-	return len(parts) > 1 && parts[0] == "container"
54
-}
55
-
56
-// IsNone indicates whether container isn't using a network stack.
57
-func (n NetworkMode) IsNone() bool {
58
-	return n == "none"
59
-}
60
-
61
-// ConnectedContainer is the id of the container which network this container is connected to.
62
-func (n NetworkMode) ConnectedContainer() string {
63
-	parts := strings.SplitN(string(n), ":", 2)
64
-	if len(parts) > 1 {
65
-		return parts[1]
66
-	}
67
-	return ""
68
-}
69
-
70 50
 // IsUserDefined indicates user-created network
71 51
 func (n NetworkMode) IsUserDefined() bool {
72 52
 	return !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer()
73 53
 }
74
-
75
-//UserDefined indicates user-created network
76
-func (n NetworkMode) UserDefined() string {
77
-	if n.IsUserDefined() {
78
-		return string(n)
79
-	}
80
-	return ""
81
-}
... ...
@@ -4,22 +4,6 @@ import (
4 4
 	"strings"
5 5
 )
6 6
 
7
-// IsDefault indicates whether container uses the default network stack.
8
-func (n NetworkMode) IsDefault() bool {
9
-	return n == "default"
10
-}
11
-
12
-// IsNone indicates whether container isn't using a network stack.
13
-func (n NetworkMode) IsNone() bool {
14
-	return n == "none"
15
-}
16
-
17
-// IsContainer indicates whether container uses a container network stack.
18
-// Returns false as windows doesn't support this mode
19
-func (n NetworkMode) IsContainer() bool {
20
-	return false
21
-}
22
-
23 7
 // IsBridge indicates whether container uses the bridge network stack
24 8
 // in windows it is given the name NAT
25 9
 func (n NetworkMode) IsBridge() bool {
... ...
@@ -32,20 +16,9 @@ func (n NetworkMode) IsHost() bool {
32 32
 	return false
33 33
 }
34 34
 
35
-// IsPrivate indicates whether container uses its private network stack.
36
-func (n NetworkMode) IsPrivate() bool {
37
-	return !(n.IsHost() || n.IsContainer())
38
-}
39
-
40
-// ConnectedContainer is the id of the container which network this container is connected to.
41
-// Returns blank string on windows
42
-func (n NetworkMode) ConnectedContainer() string {
43
-	return ""
44
-}
45
-
46 35
 // IsUserDefined indicates user-created network
47 36
 func (n NetworkMode) IsUserDefined() bool {
48
-	return !n.IsDefault() && !n.IsNone() && !n.IsBridge()
37
+	return !n.IsDefault() && !n.IsNone() && !n.IsBridge() && !n.IsContainer()
49 38
 }
50 39
 
51 40
 // IsHyperV indicates the use of a Hyper-V partition for isolation
... ...
@@ -71,17 +44,11 @@ func (n NetworkMode) NetworkName() string {
71 71
 		return "nat"
72 72
 	} else if n.IsNone() {
73 73
 		return "none"
74
+	} else if n.IsContainer() {
75
+		return "container"
74 76
 	} else if n.IsUserDefined() {
75 77
 		return n.UserDefined()
76 78
 	}
77 79
 
78 80
 	return ""
79 81
 }
80
-
81
-//UserDefined indicates user-created network
82
-func (n NetworkMode) UserDefined() string {
83
-	if n.IsUserDefined() {
84
-		return string(n)
85
-	}
86
-	return ""
87
-}
88 82
new file mode 100644
... ...
@@ -0,0 +1,22 @@
0
+package container
1
+
2
+// WaitCondition is a type used to specify a container state for which
3
+// to wait.
4
+type WaitCondition string
5
+
6
+// Possible WaitCondition Values.
7
+//
8
+// WaitConditionNotRunning (default) is used to wait for any of the non-running
9
+// states: "created", "exited", "dead", "removing", or "removed".
10
+//
11
+// WaitConditionNextExit is used to wait for the next time the state changes
12
+// to a non-running state. If the state is currently "created" or "exited",
13
+// this would cause Wait() to block until either the container runs and exits
14
+// or is removed.
15
+//
16
+// WaitConditionRemoved is used to wait for the container to be removed.
17
+const (
18
+	WaitConditionNotRunning WaitCondition = "not-running"
19
+	WaitConditionNextExit   WaitCondition = "next-exit"
20
+	WaitConditionRemoved    WaitCondition = "removed"
21
+)
... ...
@@ -79,8 +79,8 @@ func ToParamWithVersion(version string, a Args) (string, error) {
79 79
 	}
80 80
 
81 81
 	// for daemons older than v1.10, filter must be of the form map[string][]string
82
-	buf := []byte{}
83
-	err := errors.New("")
82
+	var buf []byte
83
+	var err error
84 84
 	if version != "" && versions.LessThan(version, "1.22") {
85 85
 		buf, err = json.Marshal(convertArgsToSlice(a.fields))
86 86
 	} else {
87 87
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+package types
1
+
2
+// This file was generated by the swagger tool.
3
+// Editing this file might prove futile when you re-run the swagger generate command
4
+
5
+// GraphDriverData Information about a container's graph driver.
6
+// swagger:model GraphDriverData
7
+type GraphDriverData struct {
8
+
9
+	// data
10
+	// Required: true
11
+	Data map[string]string `json:"Data"`
12
+
13
+	// name
14
+	// Required: true
15
+	Name string `json:"Name"`
16
+}
0 17
new file mode 100644
... ...
@@ -0,0 +1,15 @@
0
+package types
1
+
2
+// This file was generated by the swagger tool.
3
+// Editing this file might prove futile when you re-run the swagger generate command
4
+
5
+// ImageDeleteResponseItem image delete response item
6
+// swagger:model ImageDeleteResponseItem
7
+type ImageDeleteResponseItem struct {
8
+
9
+	// The image ID of an image that was deleted
10
+	Deleted string `json:"Deleted,omitempty"`
11
+
12
+	// The image ID of an image that was untagged
13
+	Untagged string `json:"Untagged,omitempty"`
14
+}
... ...
@@ -23,9 +23,10 @@ type Mount struct {
23 23
 	// Source specifies the name of the mount. Depending on mount type, this
24 24
 	// may be a volume name or a host path, or even ignored.
25 25
 	// Source is not supported for tmpfs (must be an empty value)
26
-	Source   string `json:",omitempty"`
27
-	Target   string `json:",omitempty"`
28
-	ReadOnly bool   `json:",omitempty"`
26
+	Source      string      `json:",omitempty"`
27
+	Target      string      `json:",omitempty"`
28
+	ReadOnly    bool        `json:",omitempty"`
29
+	Consistency Consistency `json:",omitempty"`
29 30
 
30 31
 	BindOptions   *BindOptions   `json:",omitempty"`
31 32
 	VolumeOptions *VolumeOptions `json:",omitempty"`
... ...
@@ -60,6 +61,20 @@ var Propagations = []Propagation{
60 60
 	PropagationSlave,
61 61
 }
62 62
 
63
+// Consistency represents the consistency requirements of a mount.
64
+type Consistency string
65
+
66
+const (
67
+	// ConsistencyFull guarantees bind-mount-like consistency
68
+	ConsistencyFull Consistency = "consistent"
69
+	// ConsistencyCached mounts can cache read data and FS structure
70
+	ConsistencyCached Consistency = "cached"
71
+	// ConsistencyDelegated mounts can cache read and written data and structure
72
+	ConsistencyDelegated Consistency = "delegated"
73
+	// ConsistencyDefault provides "consistent" behavior unless overridden
74
+	ConsistencyDefault Consistency = "default"
75
+)
76
+
63 77
 // BindOptions defines options specific to mounts of type "bind".
64 78
 type BindOptions struct {
65 79
 	Propagation Propagation `json:",omitempty"`
... ...
@@ -83,7 +98,7 @@ type TmpfsOptions struct {
83 83
 	// Size sets the size of the tmpfs, in bytes.
84 84
 	//
85 85
 	// This will be converted to an operating system specific value
86
-	// depending on the host. For example, on linux, it will be convered to
86
+	// depending on the host. For example, on linux, it will be converted to
87 87
 	// use a 'k', 'm' or 'g' syntax. BSD, though not widely supported with
88 88
 	// docker, uses a straight byte value.
89 89
 	//
... ...
@@ -28,6 +28,14 @@ type EndpointIPAMConfig struct {
28 28
 	LinkLocalIPs []string `json:",omitempty"`
29 29
 }
30 30
 
31
+// Copy makes a copy of the endpoint ipam config
32
+func (cfg *EndpointIPAMConfig) Copy() *EndpointIPAMConfig {
33
+	cfgCopy := *cfg
34
+	cfgCopy.LinkLocalIPs = make([]string, 0, len(cfg.LinkLocalIPs))
35
+	cfgCopy.LinkLocalIPs = append(cfgCopy.LinkLocalIPs, cfg.LinkLocalIPs...)
36
+	return &cfgCopy
37
+}
38
+
31 39
 // PeerInfo represents one peer of an overlay network
32 40
 type PeerInfo struct {
33 41
 	Name string
... ...
@@ -50,6 +58,42 @@ type EndpointSettings struct {
50 50
 	GlobalIPv6Address   string
51 51
 	GlobalIPv6PrefixLen int
52 52
 	MacAddress          string
53
+	DriverOpts          map[string]string
54
+}
55
+
56
+// Task carries the information about one backend task
57
+type Task struct {
58
+	Name       string
59
+	EndpointID string
60
+	EndpointIP string
61
+	Info       map[string]string
62
+}
63
+
64
+// ServiceInfo represents service parameters with the list of service's tasks
65
+type ServiceInfo struct {
66
+	VIP          string
67
+	Ports        []string
68
+	LocalLBIndex int
69
+	Tasks        []Task
70
+}
71
+
72
+// Copy makes a deep copy of `EndpointSettings`
73
+func (es *EndpointSettings) Copy() *EndpointSettings {
74
+	epCopy := *es
75
+	if es.IPAMConfig != nil {
76
+		epCopy.IPAMConfig = es.IPAMConfig.Copy()
77
+	}
78
+
79
+	if es.Links != nil {
80
+		links := make([]string, 0, len(es.Links))
81
+		epCopy.Links = append(links, es.Links...)
82
+	}
83
+
84
+	if es.Aliases != nil {
85
+		aliases := make([]string, 0, len(es.Aliases))
86
+		epCopy.Aliases = append(aliases, es.Aliases...)
87
+	}
88
+	return &epCopy
53 89
 }
54 90
 
55 91
 // NetworkingConfig represents the container's networking configuration for each of its interfaces
... ...
@@ -57,3 +101,8 @@ type EndpointSettings struct {
57 57
 type NetworkingConfig struct {
58 58
 	EndpointsConfig map[string]*EndpointSettings // Endpoint configs for each connecting network
59 59
 }
60
+
61
+// ConfigReference specifies the source which provides a network's configuration
62
+type ConfigReference struct {
63
+	Network string
64
+}
... ...
@@ -22,6 +22,9 @@ type Plugin struct {
22 22
 	// Required: true
23 23
 	Name string `json:"Name"`
24 24
 
25
+	// plugin remote reference used to push/pull the plugin
26
+	PluginReference string `json:"PluginReference,omitempty"`
27
+
25 28
 	// settings
26 29
 	// Required: true
27 30
 	Settings PluginSettings `json:"Settings"`
... ...
@@ -39,6 +42,9 @@ type PluginConfig struct {
39 39
 	// Required: true
40 40
 	Description string `json:"Description"`
41 41
 
42
+	// Docker Version used to create the plugin
43
+	DockerVersion string `json:"DockerVersion,omitempty"`
44
+
42 45
 	// documentation
43 46
 	// Required: true
44 47
 	Documentation string `json:"Documentation"`
... ...
@@ -55,6 +61,10 @@ type PluginConfig struct {
55 55
 	// Required: true
56 56
 	Interface PluginConfigInterface `json:"Interface"`
57 57
 
58
+	// ipc host
59
+	// Required: true
60
+	IpcHost bool `json:"IpcHost"`
61
+
58 62
 	// linux
59 63
 	// Required: true
60 64
 	Linux PluginConfigLinux `json:"Linux"`
... ...
@@ -67,6 +77,10 @@ type PluginConfig struct {
67 67
 	// Required: true
68 68
 	Network PluginConfigNetwork `json:"Network"`
69 69
 
70
+	// pid host
71
+	// Required: true
72
+	PidHost bool `json:"PidHost"`
73
+
70 74
 	// propagated mount
71 75
 	// Required: true
72 76
 	PropagatedMount string `json:"PropagatedMount"`
... ...
@@ -120,13 +134,13 @@ type PluginConfigInterface struct {
120 120
 // swagger:model PluginConfigLinux
121 121
 type PluginConfigLinux struct {
122 122
 
123
-	// capabilities
123
+	// allow all devices
124 124
 	// Required: true
125
-	Capabilities []string `json:"Capabilities"`
125
+	AllowAllDevices bool `json:"AllowAllDevices"`
126 126
 
127
-	// device creation
127
+	// capabilities
128 128
 	// Required: true
129
-	DeviceCreation bool `json:"DeviceCreation"`
129
+	Capabilities []string `json:"Capabilities"`
130 130
 
131 131
 	// devices
132 132
 	// Required: true
... ...
@@ -3,6 +3,7 @@ package types
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"fmt"
6
+	"sort"
6 7
 )
7 8
 
8 9
 // PluginsListResponse contains the response for the Engine API
... ...
@@ -62,3 +63,17 @@ type PluginPrivilege struct {
62 62
 
63 63
 // PluginPrivileges is a list of PluginPrivilege
64 64
 type PluginPrivileges []PluginPrivilege
65
+
66
+func (s PluginPrivileges) Len() int {
67
+	return len(s)
68
+}
69
+
70
+func (s PluginPrivileges) Less(i, j int) bool {
71
+	return s[i].Name < s[j].Name
72
+}
73
+
74
+func (s PluginPrivileges) Swap(i, j int) {
75
+	sort.Strings(s[i].Value)
76
+	sort.Strings(s[j].Value)
77
+	s[i], s[j] = s[j], s[i]
78
+}
... ...
@@ -3,13 +3,17 @@ package registry
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"net"
6
+
7
+	"github.com/opencontainers/image-spec/specs-go/v1"
6 8
 )
7 9
 
8 10
 // ServiceConfig stores daemon registry services configuration.
9 11
 type ServiceConfig struct {
10
-	InsecureRegistryCIDRs []*NetIPNet           `json:"InsecureRegistryCIDRs"`
11
-	IndexConfigs          map[string]*IndexInfo `json:"IndexConfigs"`
12
-	Mirrors               []string
12
+	AllowNondistributableArtifactsCIDRs     []*NetIPNet
13
+	AllowNondistributableArtifactsHostnames []string
14
+	InsecureRegistryCIDRs                   []*NetIPNet           `json:"InsecureRegistryCIDRs"`
15
+	IndexConfigs                            map[string]*IndexInfo `json:"IndexConfigs"`
16
+	Mirrors                                 []string
13 17
 }
14 18
 
15 19
 // NetIPNet is the net.IPNet type, which can be marshalled and
... ...
@@ -102,3 +106,14 @@ type SearchResults struct {
102 102
 	// Results is a slice containing the actual results for the search
103 103
 	Results []SearchResult `json:"results"`
104 104
 }
105
+
106
+// DistributionInspect describes the result obtained from contacting the
107
+// registry to retrieve image metadata
108
+type DistributionInspect struct {
109
+	// Descriptor contains information about the manifest, including
110
+	// the content addressable digest
111
+	Descriptor v1.Descriptor
112
+	// Platforms contains the list of platforms supported by the image,
113
+	// obtained by parsing the manifest
114
+	Platforms []v1.Platform
115
+}
... ...
@@ -47,6 +47,9 @@ type CPUStats struct {
47 47
 	// System Usage. Linux only.
48 48
 	SystemUsage uint64 `json:"system_cpu_usage,omitempty"`
49 49
 
50
+	// Online CPUs. Linux only.
51
+	OnlineCPUs uint32 `json:"online_cpus,omitempty"`
52
+
50 53
 	// Throttling Data. Linux only.
51 54
 	ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
52 55
 }
... ...
@@ -17,7 +17,7 @@ type Meta struct {
17 17
 // Annotations represents how to describe an object.
18 18
 type Annotations struct {
19 19
 	Name   string            `json:",omitempty"`
20
-	Labels map[string]string `json:",omitempty"`
20
+	Labels map[string]string `json:"Labels"`
21 21
 }
22 22
 
23 23
 // Driver represents a driver (network, logging).
... ...
@@ -25,3 +25,16 @@ type Driver struct {
25 25
 	Name    string            `json:",omitempty"`
26 26
 	Options map[string]string `json:",omitempty"`
27 27
 }
28
+
29
+// TLSInfo represents the TLS information about what CA certificate is trusted,
30
+// and who the issuer for a TLS certificate is
31
+type TLSInfo struct {
32
+	// TrustRoot is the trusted CA root certificate in PEM format
33
+	TrustRoot string `json:",omitempty"`
34
+
35
+	// CertIssuer is the raw subject bytes of the issuer
36
+	CertIssuerSubject []byte `json:",omitempty"`
37
+
38
+	// CertIssuerPublicKey is the raw public key bytes of the issuer
39
+	CertIssuerPublicKey []byte `json:",omitempty"`
40
+}
28 41
new file mode 100644
... ...
@@ -0,0 +1,31 @@
0
+package swarm
1
+
2
+import "os"
3
+
4
+// Config represents a config.
5
+type Config struct {
6
+	ID string
7
+	Meta
8
+	Spec ConfigSpec
9
+}
10
+
11
+// ConfigSpec represents a config specification from a config in swarm
12
+type ConfigSpec struct {
13
+	Annotations
14
+	Data []byte `json:",omitempty"`
15
+}
16
+
17
+// ConfigReferenceFileTarget is a file target in a config reference
18
+type ConfigReferenceFileTarget struct {
19
+	Name string
20
+	UID  string
21
+	GID  string
22
+	Mode os.FileMode
23
+}
24
+
25
+// ConfigReference is a reference to a config in swarm
26
+type ConfigReference struct {
27
+	File       *ConfigReferenceFileTarget
28
+	ConfigID   string
29
+	ConfigName string
30
+}
... ...
@@ -21,6 +21,28 @@ type DNSConfig struct {
21 21
 	Options []string `json:",omitempty"`
22 22
 }
23 23
 
24
+// SELinuxContext contains the SELinux labels of the container.
25
+type SELinuxContext struct {
26
+	Disable bool
27
+
28
+	User  string
29
+	Role  string
30
+	Type  string
31
+	Level string
32
+}
33
+
34
+// CredentialSpec for managed service account (Windows only)
35
+type CredentialSpec struct {
36
+	File     string
37
+	Registry string
38
+}
39
+
40
+// Privileges defines the security options for the container.
41
+type Privileges struct {
42
+	CredentialSpec *CredentialSpec
43
+	SELinuxContext *SELinuxContext
44
+}
45
+
24 46
 // ContainerSpec represents the spec of a container.
25 47
 type ContainerSpec struct {
26 48
 	Image           string                  `json:",omitempty"`
... ...
@@ -32,8 +54,11 @@ type ContainerSpec struct {
32 32
 	Dir             string                  `json:",omitempty"`
33 33
 	User            string                  `json:",omitempty"`
34 34
 	Groups          []string                `json:",omitempty"`
35
+	Privileges      *Privileges             `json:",omitempty"`
36
+	StopSignal      string                  `json:",omitempty"`
35 37
 	TTY             bool                    `json:",omitempty"`
36 38
 	OpenStdin       bool                    `json:",omitempty"`
39
+	ReadOnly        bool                    `json:",omitempty"`
37 40
 	Mounts          []mount.Mount           `json:",omitempty"`
38 41
 	StopGracePeriod *time.Duration          `json:",omitempty"`
39 42
 	Healthcheck     *container.HealthConfig `json:",omitempty"`
... ...
@@ -43,4 +68,5 @@ type ContainerSpec struct {
43 43
 	Hosts     []string           `json:",omitempty"`
44 44
 	DNSConfig *DNSConfig         `json:",omitempty"`
45 45
 	Secrets   []*SecretReference `json:",omitempty"`
46
+	Configs   []*ConfigReference `json:",omitempty"`
46 47
 }
... ...
@@ -1,5 +1,9 @@
1 1
 package swarm
2 2
 
3
+import (
4
+	"github.com/docker/docker/api/types/network"
5
+)
6
+
3 7
 // Endpoint represents an endpoint.
4 8
 type Endpoint struct {
5 9
 	Spec       EndpointSpec        `json:",omitempty"`
... ...
@@ -78,17 +82,21 @@ type Network struct {
78 78
 // NetworkSpec represents the spec of a network.
79 79
 type NetworkSpec struct {
80 80
 	Annotations
81
-	DriverConfiguration *Driver      `json:",omitempty"`
82
-	IPv6Enabled         bool         `json:",omitempty"`
83
-	Internal            bool         `json:",omitempty"`
84
-	Attachable          bool         `json:",omitempty"`
85
-	IPAMOptions         *IPAMOptions `json:",omitempty"`
81
+	DriverConfiguration *Driver                  `json:",omitempty"`
82
+	IPv6Enabled         bool                     `json:",omitempty"`
83
+	Internal            bool                     `json:",omitempty"`
84
+	Attachable          bool                     `json:",omitempty"`
85
+	Ingress             bool                     `json:",omitempty"`
86
+	IPAMOptions         *IPAMOptions             `json:",omitempty"`
87
+	ConfigFrom          *network.ConfigReference `json:",omitempty"`
88
+	Scope               string                   `json:",omitempty"`
86 89
 }
87 90
 
88 91
 // NetworkAttachmentConfig represents the configuration of a network attachment.
89 92
 type NetworkAttachmentConfig struct {
90
-	Target  string   `json:",omitempty"`
91
-	Aliases []string `json:",omitempty"`
93
+	Target     string            `json:",omitempty"`
94
+	Aliases    []string          `json:",omitempty"`
95
+	DriverOpts map[string]string `json:",omitempty"`
92 96
 }
93 97
 
94 98
 // NetworkAttachment represents a network attachment.
... ...
@@ -52,6 +52,7 @@ type NodeDescription struct {
52 52
 	Platform  Platform          `json:",omitempty"`
53 53
 	Resources Resources         `json:",omitempty"`
54 54
 	Engine    EngineDescription `json:",omitempty"`
55
+	TLSInfo   TLSInfo           `json:",omitempty"`
55 56
 }
56 57
 
57 58
 // Platform represents the platform (Arch/OS).
58 59
new file mode 100644
... ...
@@ -0,0 +1,19 @@
0
+package swarm
1
+
2
+// RuntimeType is the type of runtime used for the TaskSpec
3
+type RuntimeType string
4
+
5
+// RuntimeURL is the proto type url
6
+type RuntimeURL string
7
+
8
+const (
9
+	// RuntimeContainer is the container based runtime
10
+	RuntimeContainer RuntimeType = "container"
11
+	// RuntimePlugin is the plugin based runtime
12
+	RuntimePlugin RuntimeType = "plugin"
13
+
14
+	// RuntimeURLContainer is the proto url for the container type
15
+	RuntimeURLContainer RuntimeURL = "types.docker.com/RuntimeContainer"
16
+	// RuntimeURLPlugin is the proto url for the plugin type
17
+	RuntimeURLPlugin RuntimeURL = "types.docker.com/RuntimePlugin"
18
+)
... ...
@@ -18,9 +18,10 @@ type ServiceSpec struct {
18 18
 
19 19
 	// TaskTemplate defines how the service should construct new tasks when
20 20
 	// orchestrating this service.
21
-	TaskTemplate TaskSpec      `json:",omitempty"`
22
-	Mode         ServiceMode   `json:",omitempty"`
23
-	UpdateConfig *UpdateConfig `json:",omitempty"`
21
+	TaskTemplate   TaskSpec      `json:",omitempty"`
22
+	Mode           ServiceMode   `json:",omitempty"`
23
+	UpdateConfig   *UpdateConfig `json:",omitempty"`
24
+	RollbackConfig *UpdateConfig `json:",omitempty"`
24 25
 
25 26
 	// Networks field in ServiceSpec is deprecated. The
26 27
 	// same field in TaskSpec should be used instead.
... ...
@@ -45,6 +46,12 @@ const (
45 45
 	UpdateStatePaused UpdateState = "paused"
46 46
 	// UpdateStateCompleted is the completed state.
47 47
 	UpdateStateCompleted UpdateState = "completed"
48
+	// UpdateStateRollbackStarted is the state with a rollback in progress.
49
+	UpdateStateRollbackStarted UpdateState = "rollback_started"
50
+	// UpdateStateRollbackPaused is the state with a rollback in progress.
51
+	UpdateStateRollbackPaused UpdateState = "rollback_paused"
52
+	// UpdateStateRollbackCompleted is the state with a rollback in progress.
53
+	UpdateStateRollbackCompleted UpdateState = "rollback_completed"
48 54
 )
49 55
 
50 56
 // UpdateStatus reports the status of a service update.
... ...
@@ -68,6 +75,13 @@ const (
68 68
 	UpdateFailureActionPause = "pause"
69 69
 	// UpdateFailureActionContinue CONTINUE
70 70
 	UpdateFailureActionContinue = "continue"
71
+	// UpdateFailureActionRollback ROLLBACK
72
+	UpdateFailureActionRollback = "rollback"
73
+
74
+	// UpdateOrderStopFirst STOP_FIRST
75
+	UpdateOrderStopFirst = "stop-first"
76
+	// UpdateOrderStartFirst START_FIRST
77
+	UpdateOrderStartFirst = "start-first"
71 78
 )
72 79
 
73 80
 // UpdateConfig represents the update configuration.
... ...
@@ -102,4 +116,9 @@ type UpdateConfig struct {
102 102
 	// If the failure action is PAUSE, no more tasks will be updated until
103 103
 	// another update is started.
104 104
 	MaxFailureRatio float32
105
+
106
+	// Order indicates the order of operations when rolling out an updated
107
+	// task. Either the old task is shut down before the new task is
108
+	// started, or the new task is started before the old task is shut down.
109
+	Order string
105 110
 }
... ...
@@ -7,7 +7,9 @@ import "time"
7 7
 type ClusterInfo struct {
8 8
 	ID string
9 9
 	Meta
10
-	Spec Spec
10
+	Spec                   Spec
11
+	TLSInfo                TLSInfo
12
+	RootRotationInProgress bool
11 13
 }
12 14
 
13 15
 // Swarm represents a swarm.
... ...
@@ -107,6 +109,16 @@ type CAConfig struct {
107 107
 	// ExternalCAs is a list of CAs to which a manager node will make
108 108
 	// certificate signing requests for node certificates.
109 109
 	ExternalCAs []*ExternalCA `json:",omitempty"`
110
+
111
+	// SigningCACert and SigningCAKey specify the desired signing root CA and
112
+	// root CA key for the swarm.  When inspecting the cluster, the key will
113
+	// be redacted.
114
+	SigningCACert string `json:",omitempty"`
115
+	SigningCAKey  string `json:",omitempty"`
116
+
117
+	// If this value changes, and there is no specified signing cert and key,
118
+	// then the swarm is forced to generate a new root certificate ane key.
119
+	ForceRotate uint64 `json:",omitempty"`
110 120
 }
111 121
 
112 122
 // ExternalCAProtocol represents type of external CA.
... ...
@@ -126,23 +138,31 @@ type ExternalCA struct {
126 126
 	// Options is a set of additional key/value pairs whose interpretation
127 127
 	// depends on the specified CA type.
128 128
 	Options map[string]string `json:",omitempty"`
129
+
130
+	// CACert specifies which root CA is used by this external CA.  This certificate must
131
+	// be in PEM format.
132
+	CACert string
129 133
 }
130 134
 
131 135
 // InitRequest is the request used to init a swarm.
132 136
 type InitRequest struct {
133 137
 	ListenAddr       string
134 138
 	AdvertiseAddr    string
139
+	DataPathAddr     string
135 140
 	ForceNewCluster  bool
136 141
 	Spec             Spec
137 142
 	AutoLockManagers bool
143
+	Availability     NodeAvailability
138 144
 }
139 145
 
140 146
 // JoinRequest is the request used to join a swarm.
141 147
 type JoinRequest struct {
142 148
 	ListenAddr    string
143 149
 	AdvertiseAddr string
150
+	DataPathAddr  string
144 151
 	RemoteAddrs   []string
145 152
 	JoinToken     string // accept by secret
153
+	Availability  NodeAvailability
146 154
 }
147 155
 
148 156
 // UnlockRequest is the request used to unlock a swarm.
... ...
@@ -177,10 +197,10 @@ type Info struct {
177 177
 	Error            string
178 178
 
179 179
 	RemoteManagers []Peer
180
-	Nodes          int
181
-	Managers       int
180
+	Nodes          int `json:",omitempty"`
181
+	Managers       int `json:",omitempty"`
182 182
 
183
-	Cluster ClusterInfo
183
+	Cluster *ClusterInfo `json:",omitempty"`
184 184
 }
185 185
 
186 186
 // Peer represents a peer.
... ...
@@ -65,6 +65,8 @@ type TaskSpec struct {
65 65
 	// ForceUpdate is a counter that triggers an update even if no relevant
66 66
 	// parameters have been changed.
67 67
 	ForceUpdate uint64
68
+
69
+	Runtime RuntimeType `json:",omitempty"`
68 70
 }
69 71
 
70 72
 // Resources represents resources (CPU/Memory).
... ...
@@ -81,7 +83,26 @@ type ResourceRequirements struct {
81 81
 
82 82
 // Placement represents orchestration parameters.
83 83
 type Placement struct {
84
-	Constraints []string `json:",omitempty"`
84
+	Constraints []string              `json:",omitempty"`
85
+	Preferences []PlacementPreference `json:",omitempty"`
86
+
87
+	// Platforms stores all the platforms that the image can run on.
88
+	// This field is used in the platform filter for scheduling. If empty,
89
+	// then the platform filter is off, meaning there are no scheduling restrictions.
90
+	Platforms []Platform `json:",omitempty"`
91
+}
92
+
93
+// PlacementPreference provides a way to make the scheduler aware of factors
94
+// such as topology.
95
+type PlacementPreference struct {
96
+	Spread *SpreadOver
97
+}
98
+
99
+// SpreadOver is a scheduling preference that instructs the scheduler to spread
100
+// tasks evenly over groups of nodes identified by labels.
101
+type SpreadOver struct {
102
+	// label descriptor, such as engine.labels.az
103
+	SpreadDescriptor string
85 104
 }
86 105
 
87 106
 // RestartPolicy represents the restart policy.
... ...
@@ -17,38 +17,6 @@ import (
17 17
 	"github.com/docker/go-connections/nat"
18 18
 )
19 19
 
20
-// ContainerChange contains response of Engine API:
21
-// GET "/containers/{name:.*}/changes"
22
-type ContainerChange struct {
23
-	Kind int
24
-	Path string
25
-}
26
-
27
-// ImageHistory contains response of Engine API:
28
-// GET "/images/{name:.*}/history"
29
-type ImageHistory struct {
30
-	ID        string `json:"Id"`
31
-	Created   int64
32
-	CreatedBy string
33
-	Tags      []string
34
-	Size      int64
35
-	Comment   string
36
-}
37
-
38
-// ImageDelete contains response of Engine API:
39
-// DELETE "/images/{name:.*}"
40
-type ImageDelete struct {
41
-	Untagged string `json:",omitempty"`
42
-	Deleted  string `json:",omitempty"`
43
-}
44
-
45
-// GraphDriverData returns Image's graph driver config info
46
-// when calling inspect command
47
-type GraphDriverData struct {
48
-	Name string
49
-	Data map[string]string
50
-}
51
-
52 20
 // RootFS returns Image's RootFS description including the layer IDs.
53 21
 type RootFS struct {
54 22
 	Type      string
... ...
@@ -125,17 +93,11 @@ type ContainerStats struct {
125 125
 	OSType string        `json:"ostype"`
126 126
 }
127 127
 
128
-// ContainerProcessList contains response of Engine API:
129
-// GET "/containers/{name:.*}/top"
130
-type ContainerProcessList struct {
131
-	Processes [][]string
132
-	Titles    []string
133
-}
134
-
135 128
 // Ping contains response of Engine API:
136 129
 // GET "/_ping"
137 130
 type Ping struct {
138 131
 	APIVersion   string
132
+	OSType       string
139 133
 	Experimental bool
140 134
 }
141 135
 
... ...
@@ -276,6 +238,8 @@ type PluginsInfo struct {
276 276
 	Network []string
277 277
 	// List of Authorization plugins registered
278 278
 	Authorization []string
279
+	// List of Log plugins registered
280
+	Log []string
279 281
 }
280 282
 
281 283
 // ExecStartCheck is a temp struct used by execStart
... ...
@@ -313,7 +277,7 @@ type Health struct {
313 313
 // ContainerState stores container's running state
314 314
 // it's part of ContainerJSONBase and will return by "inspect" command
315 315
 type ContainerState struct {
316
-	Status     string
316
+	Status     string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead"
317 317
 	Running    bool
318 318
 	Paused     bool
319 319
 	Restarting bool
... ...
@@ -429,19 +393,23 @@ type MountPoint struct {
429 429
 
430 430
 // NetworkResource is the body of the "get network" http response message
431 431
 type NetworkResource struct {
432
-	Name       string                      // Name is the requested name of the network
433
-	ID         string                      `json:"Id"` // ID uniquely identifies a network on a single machine
434
-	Created    time.Time                   // Created is the time the network created
435
-	Scope      string                      // Scope describes the level at which the network exists (e.g. `global` for cluster-wide or `local` for machine level)
436
-	Driver     string                      // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
437
-	EnableIPv6 bool                        // EnableIPv6 represents whether to enable IPv6
438
-	IPAM       network.IPAM                // IPAM is the network's IP Address Management
439
-	Internal   bool                        // Internal represents if the network is used internal only
440
-	Attachable bool                        // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
441
-	Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
442
-	Options    map[string]string           // Options holds the network specific options to use for when creating the network
443
-	Labels     map[string]string           // Labels holds metadata specific to the network being created
444
-	Peers      []network.PeerInfo          `json:",omitempty"` // List of peer nodes for an overlay network
432
+	Name       string                         // Name is the requested name of the network
433
+	ID         string                         `json:"Id"` // ID uniquely identifies a network on a single machine
434
+	Created    time.Time                      // Created is the time the network created
435
+	Scope      string                         // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
436
+	Driver     string                         // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
437
+	EnableIPv6 bool                           // EnableIPv6 represents whether to enable IPv6
438
+	IPAM       network.IPAM                   // IPAM is the network's IP Address Management
439
+	Internal   bool                           // Internal represents if the network is used internal only
440
+	Attachable bool                           // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
441
+	Ingress    bool                           // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
442
+	ConfigFrom network.ConfigReference        // ConfigFrom specifies the source which will provide the configuration for this network.
443
+	ConfigOnly bool                           // ConfigOnly networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
444
+	Containers map[string]EndpointResource    // Containers contains endpoints belonging to the network
445
+	Options    map[string]string              // Options holds the network specific options to use for when creating the network
446
+	Labels     map[string]string              // Labels holds metadata specific to the network being created
447
+	Peers      []network.PeerInfo             `json:",omitempty"` // List of peer nodes for an overlay network
448
+	Services   map[string]network.ServiceInfo `json:",omitempty"`
445 449
 }
446 450
 
447 451
 // EndpointResource contains network resources allocated and used for a container in a network
... ...
@@ -455,12 +423,23 @@ type EndpointResource struct {
455 455
 
456 456
 // NetworkCreate is the expected body of the "create network" http request message
457 457
 type NetworkCreate struct {
458
+	// Check for networks with duplicate names.
459
+	// Network is primarily keyed based on a random ID and not on the name.
460
+	// Network name is strictly a user-friendly alias to the network
461
+	// which is uniquely identified using ID.
462
+	// And there is no guaranteed way to check for duplicates.
463
+	// Option CheckDuplicate is there to provide a best effort checking of any networks
464
+	// which has the same name but it is not guaranteed to catch all name collisions.
458 465
 	CheckDuplicate bool
459 466
 	Driver         string
467
+	Scope          string
460 468
 	EnableIPv6     bool
461 469
 	IPAM           *network.IPAM
462 470
 	Internal       bool
463 471
 	Attachable     bool
472
+	Ingress        bool
473
+	ConfigOnly     bool
474
+	ConfigFrom     *network.ConfigReference
464 475
 	Options        map[string]string
465 476
 	Labels         map[string]string
466 477
 }
... ...
@@ -526,7 +505,7 @@ type VolumesPruneReport struct {
526 526
 // ImagesPruneReport contains the response for Engine API:
527 527
 // POST "/images/prune"
528 528
 type ImagesPruneReport struct {
529
-	ImagesDeleted  []ImageDelete
529
+	ImagesDeleted  []ImageDeleteResponseItem
530 530
 	SpaceReclaimed uint64
531 531
 }
532 532
 
... ...
@@ -548,6 +527,18 @@ type SecretListOptions struct {
548 548
 	Filters filters.Args
549 549
 }
550 550
 
551
+// ConfigCreateResponse contains the information returned to a client
552
+// on the creation of a new config.
553
+type ConfigCreateResponse struct {
554
+	// ID is the id of the created config.
555
+	ID string
556
+}
557
+
558
+// ConfigListOptions holds parameters to list configs
559
+type ConfigListOptions struct {
560
+	Filters filters.Args
561
+}
562
+
551 563
 // PushResult contains the tag, manifest digest, and manifest size from the
552 564
 // push. It's used to signal this information to the trust code in the client
553 565
 // so it can sign the manifest if necessary.
... ...
@@ -556,3 +547,8 @@ type PushResult struct {
556 556
 	Digest string
557 557
 	Size   int
558 558
 }
559
+
560
+// BuildResult contains the image id of a successful build
561
+type BuildResult struct {
562
+	ID string
563
+}
559 564
new file mode 100644
... ...
@@ -0,0 +1,36 @@
0
+package provider
1
+
2
+import (
3
+	"github.com/docker/docker/api/types/network"
4
+	"golang.org/x/net/context"
5
+)
6
+
7
+const (
8
+	// ClusterEventSocketChange control socket changed
9
+	ClusterEventSocketChange = iota
10
+	// ClusterEventNodeReady cluster node in ready state
11
+	ClusterEventNodeReady
12
+	// ClusterEventNodeLeave node is leaving the cluster
13
+	ClusterEventNodeLeave
14
+	// ClusterEventNetworkKeysAvailable network keys correctly configured in the networking layer
15
+	ClusterEventNetworkKeysAvailable
16
+)
17
+
18
+// ClusterConfigEventType type of the event produced by the cluster
19
+type ClusterConfigEventType uint8
20
+
21
+// Cluster provides clustering config details
22
+type Cluster interface {
23
+	IsManager() bool
24
+	IsAgent() bool
25
+	GetLocalAddress() string
26
+	GetListenAddress() string
27
+	GetAdvertiseAddress() string
28
+	GetDataPathAddress() string
29
+	GetRemoteAddressList() []string
30
+	ListenClusterEvents() <-chan ClusterConfigEventType
31
+	AttachNetwork(string, string, []string) (*network.NetworkingConfig, error)
32
+	DetachNetwork(string, string) error
33
+	UpdateAttachment(string, string, *network.NetworkingConfig) error
34
+	WaitForDetachment(context.Context, string, string, string, string) error
35
+}
0 36
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+package provider
1
+
2
+import "github.com/docker/docker/api/types"
3
+
4
+// NetworkCreateRequest is a request when creating a network.
5
+type NetworkCreateRequest struct {
6
+	ID string
7
+	types.NetworkCreateRequest
8
+}
9
+
10
+// NetworkCreateResponse is a response when creating a network.
11
+type NetworkCreateResponse struct {
12
+	ID string `json:"Id"`
13
+}
14
+
15
+// VirtualAddress represents a virtual address.
16
+type VirtualAddress struct {
17
+	IPv4 string
18
+	IPv6 string
19
+}
20
+
21
+// PortConfig represents a port configuration.
22
+type PortConfig struct {
23
+	Name          string
24
+	Protocol      int32
25
+	TargetPort    uint32
26
+	PublishedPort uint32
27
+}
28
+
29
+// ServiceConfig represents a service configuration.
30
+type ServiceConfig struct {
31
+	ID               string
32
+	Name             string
33
+	Aliases          map[string][]string
34
+	VirtualAddresses map[string]*VirtualAddress
35
+	ExposedPorts     []*PortConfig
36
+}
0 37
new file mode 100644
... ...
@@ -0,0 +1,68 @@
0
+## About
1
+
2
+This directory contains a collection of scripts used to build and manage this
3
+repository. If there are any issues regarding the intention of a particular
4
+script (or even part of a certain script), please reach out to us.
5
+It may help us either refine our current scripts, or add on new ones
6
+that are appropriate for a given use case.
7
+
8
+## DinD (dind.sh)
9
+
10
+DinD is a wrapper script which allows Docker to be run inside a Docker
11
+container. DinD requires the container to
12
+be run with privileged mode enabled.
13
+
14
+## Generate Authors (generate-authors.sh)
15
+
16
+Generates AUTHORS; a file with all the names and corresponding emails of
17
+individual contributors. AUTHORS can be found in the home directory of
18
+this repository.
19
+
20
+## Install (install.sh)
21
+
22
+Executable install script for installing Docker. If updates to this are
23
+desired, please use hack/release.sh during a normal release. The following
24
+one-liner may be used for script hotfixes:
25
+
26
+- `aws s3 cp --acl public-read hack/install.sh s3://get.docker.com/index`
27
+
28
+## Make
29
+
30
+There are two make files, each with different extensions. Neither are supposed
31
+to be called directly; only invoke `make`. Both scripts run inside a Docker
32
+container.
33
+
34
+### make.ps1
35
+
36
+- The Windows native build script that uses PowerShell semantics; it is limited
37
+unlike `hack\make.sh` since it does not provide support for the full set of
38
+operations provided by the Linux counterpart, `make.sh`. However, `make.ps1`
39
+does provide support for local Windows development and Windows to Windows CI.
40
+More information is found within `make.ps1` by the author, @jhowardmsft
41
+
42
+### make.sh
43
+
44
+- Referenced via `make test` when running tests on a local machine,
45
+or directly referenced when running tests inside a Docker development container.  
46
+- When running on a local machine, `make test` to run all tests found in
47
+`test`, `test-unit`, `test-integration-cli`, and `test-docker-py` on
48
+your local machine. The default timeout is set in `make.sh` to 60 minutes
49
+(`${TIMEOUT:=60m}`), since it currently takes up to an hour to run
50
+all of the tests.
51
+- When running inside a Docker development container, `hack/make.sh` does
52
+not have a single target that runs all the tests. You need to provide a
53
+single command line with multiple targets that performs the same thing.
54
+An example referenced from [Run targets inside a development container](https://docs.docker.com/opensource/project/test-and-docs/#run-targets-inside-a-development-container): `root@5f8630b873fe:/go/src/github.com/moby/moby# hack/make.sh dynbinary binary cross test-unit test-integration-cli test-docker-py`
55
+- For more information related to testing outside the scope of this README,
56
+refer to
57
+[Run tests and test documentation](https://docs.docker.com/opensource/project/test-and-docs/)
58
+
59
+## Release (release.sh)
60
+
61
+Releases any bundles built by `make` on a public AWS S3 bucket.
62
+For information regarding configuration, please view `release.sh`.
63
+
64
+## Vendor (vendor.sh)
65
+
66
+A shell script that is a wrapper around Vndr. For information on how to use
67
+this, please refer to [vndr's README](https://github.com/LK4D4/vndr/blob/master/README.md)
0 68
new file mode 100644
... ...
@@ -0,0 +1,69 @@
0
+# Integration Testing on Swarm
1
+
2
+IT on Swarm allows you to execute integration test in parallel across a Docker Swarm cluster
3
+
4
+## Architecture
5
+
6
+### Master service
7
+
8
+  - Works as a funker caller
9
+  - Calls a worker funker (`-worker-service`) with a chunk of `-check.f` filter strings (passed as a file via `-input` flag, typically `/mnt/input`)
10
+
11
+### Worker service
12
+
13
+  - Works as a funker callee
14
+  - Executes an equivalent of `TESTFLAGS=-check.f TestFoo|TestBar|TestBaz ... make test-integration-cli` using the bind-mounted API socket (`docker.sock`)
15
+
16
+### Client
17
+
18
+  - Controls master and workers via `docker stack`
19
+  - No need to have a local daemon
20
+
21
+Typically, the master and workers are supposed to be running on a cloud environment,
22
+while the client is supposed to be running on a laptop, e.g. Docker for Mac/Windows.
23
+
24
+## Requirement
25
+
26
+  - Docker daemon 1.13 or later
27
+  - Private registry for distributed execution with multiple nodes
28
+
29
+## Usage
30
+
31
+### Step 1: Prepare images
32
+
33
+    $ make build-integration-cli-on-swarm
34
+
35
+Following environment variables are known to work in this step:
36
+
37
+ - `BUILDFLAGS`
38
+ - `DOCKER_INCREMENTAL_BINARY`
39
+
40
+Note: during the transition into Moby Project, you might need to create a symbolic link `$GOPATH/src/github.com/docker/docker` to `$GOPATH/src/github.com/moby/moby`. 
41
+
42
+### Step 2: Execute tests
43
+
44
+    $ ./hack/integration-cli-on-swarm/integration-cli-on-swarm -replicas 40 -push-worker-image YOUR_REGISTRY.EXAMPLE.COM/integration-cli-worker:latest 
45
+
46
+Following environment variables are known to work in this step:
47
+
48
+ - `DOCKER_GRAPHDRIVER`
49
+ - `DOCKER_EXPERIMENTAL`
50
+
51
+#### Flags
52
+
53
+Basic flags:
54
+
55
+ - `-replicas N`: the number of worker service replicas. i.e. degree of parallelism.
56
+ - `-chunks N`: the number of chunks. By default, `chunks` == `replicas`.
57
+ - `-push-worker-image REGISTRY/IMAGE:TAG`: push the worker image to the registry. Note that if you have only single node and hence you do not need a private registry, you do not need to specify `-push-worker-image`.
58
+
59
+Experimental flags for mitigating makespan nonuniformity:
60
+
61
+ - `-shuffle`: Shuffle the test filter strings
62
+
63
+Flags for debugging IT on Swarm itself:
64
+
65
+ - `-rand-seed N`: the random seed. This flag is useful for deterministic replaying. By default(0), the timestamp is used.
66
+ - `-filters-file FILE`: the file contains `-check.f` strings. By default, the file is automatically generated.
67
+ - `-dry-run`: skip the actual workload
68
+ - `keep-executor`: do not auto-remove executor containers, which is used for running privileged programs on Swarm
0 69
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+# dependencies specific to worker (i.e. github.com/docker/docker/...) are not vendored here
1
+github.com/bfirsh/funker-go eaa0a2e06f30e72c9a0b7f858951e581e26ef773
0 2
deleted file mode 100644
... ...
@@ -1,171 +0,0 @@
1
-package opts
2
-
3
-import (
4
-	"encoding/csv"
5
-	"fmt"
6
-	"os"
7
-	"strconv"
8
-	"strings"
9
-
10
-	mounttypes "github.com/docker/docker/api/types/mount"
11
-	"github.com/docker/go-units"
12
-)
13
-
14
-// MountOpt is a Value type for parsing mounts
15
-type MountOpt struct {
16
-	values []mounttypes.Mount
17
-}
18
-
19
-// Set a new mount value
20
-func (m *MountOpt) Set(value string) error {
21
-	csvReader := csv.NewReader(strings.NewReader(value))
22
-	fields, err := csvReader.Read()
23
-	if err != nil {
24
-		return err
25
-	}
26
-
27
-	mount := mounttypes.Mount{}
28
-
29
-	volumeOptions := func() *mounttypes.VolumeOptions {
30
-		if mount.VolumeOptions == nil {
31
-			mount.VolumeOptions = &mounttypes.VolumeOptions{
32
-				Labels: make(map[string]string),
33
-			}
34
-		}
35
-		if mount.VolumeOptions.DriverConfig == nil {
36
-			mount.VolumeOptions.DriverConfig = &mounttypes.Driver{}
37
-		}
38
-		return mount.VolumeOptions
39
-	}
40
-
41
-	bindOptions := func() *mounttypes.BindOptions {
42
-		if mount.BindOptions == nil {
43
-			mount.BindOptions = new(mounttypes.BindOptions)
44
-		}
45
-		return mount.BindOptions
46
-	}
47
-
48
-	tmpfsOptions := func() *mounttypes.TmpfsOptions {
49
-		if mount.TmpfsOptions == nil {
50
-			mount.TmpfsOptions = new(mounttypes.TmpfsOptions)
51
-		}
52
-		return mount.TmpfsOptions
53
-	}
54
-
55
-	setValueOnMap := func(target map[string]string, value string) {
56
-		parts := strings.SplitN(value, "=", 2)
57
-		if len(parts) == 1 {
58
-			target[value] = ""
59
-		} else {
60
-			target[parts[0]] = parts[1]
61
-		}
62
-	}
63
-
64
-	mount.Type = mounttypes.TypeVolume // default to volume mounts
65
-	// Set writable as the default
66
-	for _, field := range fields {
67
-		parts := strings.SplitN(field, "=", 2)
68
-		key := strings.ToLower(parts[0])
69
-
70
-		if len(parts) == 1 {
71
-			switch key {
72
-			case "readonly", "ro":
73
-				mount.ReadOnly = true
74
-				continue
75
-			case "volume-nocopy":
76
-				volumeOptions().NoCopy = true
77
-				continue
78
-			}
79
-		}
80
-
81
-		if len(parts) != 2 {
82
-			return fmt.Errorf("invalid field '%s' must be a key=value pair", field)
83
-		}
84
-
85
-		value := parts[1]
86
-		switch key {
87
-		case "type":
88
-			mount.Type = mounttypes.Type(strings.ToLower(value))
89
-		case "source", "src":
90
-			mount.Source = value
91
-		case "target", "dst", "destination":
92
-			mount.Target = value
93
-		case "readonly", "ro":
94
-			mount.ReadOnly, err = strconv.ParseBool(value)
95
-			if err != nil {
96
-				return fmt.Errorf("invalid value for %s: %s", key, value)
97
-			}
98
-		case "bind-propagation":
99
-			bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value))
100
-		case "volume-nocopy":
101
-			volumeOptions().NoCopy, err = strconv.ParseBool(value)
102
-			if err != nil {
103
-				return fmt.Errorf("invalid value for populate: %s", value)
104
-			}
105
-		case "volume-label":
106
-			setValueOnMap(volumeOptions().Labels, value)
107
-		case "volume-driver":
108
-			volumeOptions().DriverConfig.Name = value
109
-		case "volume-opt":
110
-			if volumeOptions().DriverConfig.Options == nil {
111
-				volumeOptions().DriverConfig.Options = make(map[string]string)
112
-			}
113
-			setValueOnMap(volumeOptions().DriverConfig.Options, value)
114
-		case "tmpfs-size":
115
-			sizeBytes, err := units.RAMInBytes(value)
116
-			if err != nil {
117
-				return fmt.Errorf("invalid value for %s: %s", key, value)
118
-			}
119
-			tmpfsOptions().SizeBytes = sizeBytes
120
-		case "tmpfs-mode":
121
-			ui64, err := strconv.ParseUint(value, 8, 32)
122
-			if err != nil {
123
-				return fmt.Errorf("invalid value for %s: %s", key, value)
124
-			}
125
-			tmpfsOptions().Mode = os.FileMode(ui64)
126
-		default:
127
-			return fmt.Errorf("unexpected key '%s' in '%s'", key, field)
128
-		}
129
-	}
130
-
131
-	if mount.Type == "" {
132
-		return fmt.Errorf("type is required")
133
-	}
134
-
135
-	if mount.Target == "" {
136
-		return fmt.Errorf("target is required")
137
-	}
138
-
139
-	if mount.VolumeOptions != nil && mount.Type != mounttypes.TypeVolume {
140
-		return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mount.Type)
141
-	}
142
-	if mount.BindOptions != nil && mount.Type != mounttypes.TypeBind {
143
-		return fmt.Errorf("cannot mix 'bind-*' options with mount type '%s'", mount.Type)
144
-	}
145
-	if mount.TmpfsOptions != nil && mount.Type != mounttypes.TypeTmpfs {
146
-		return fmt.Errorf("cannot mix 'tmpfs-*' options with mount type '%s'", mount.Type)
147
-	}
148
-
149
-	m.values = append(m.values, mount)
150
-	return nil
151
-}
152
-
153
-// Type returns the type of this option
154
-func (m *MountOpt) Type() string {
155
-	return "mount"
156
-}
157
-
158
-// String returns a string repr of this option
159
-func (m *MountOpt) String() string {
160
-	mounts := []string{}
161
-	for _, mount := range m.values {
162
-		repr := fmt.Sprintf("%s %s %s", mount.Type, mount.Source, mount.Target)
163
-		mounts = append(mounts, repr)
164
-	}
165
-	return strings.Join(mounts, ", ")
166
-}
167
-
168
-// Value returns the mounts
169
-func (m *MountOpt) Value() []mounttypes.Mount {
170
-	return m.values
171
-}
... ...
@@ -2,13 +2,12 @@ package opts
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"math/big"
6 5
 	"net"
7 6
 	"path"
8 7
 	"regexp"
9 8
 	"strings"
10 9
 
11
-	"github.com/docker/docker/api/types/filters"
10
+	units "github.com/docker/go-units"
12 11
 )
13 12
 
14 13
 var (
... ...
@@ -37,7 +36,10 @@ func NewListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts {
37 37
 }
38 38
 
39 39
 func (opts *ListOpts) String() string {
40
-	return fmt.Sprintf("%v", []string((*opts.values)))
40
+	if len(*opts.values) == 0 {
41
+		return ""
42
+	}
43
+	return fmt.Sprintf("%v", *opts.values)
41 44
 }
42 45
 
43 46
 // Set validates if needed the input value and adds it to the
... ...
@@ -232,15 +234,6 @@ func ValidateIPAddress(val string) (string, error) {
232 232
 	return "", fmt.Errorf("%s is not an ip address", val)
233 233
 }
234 234
 
235
-// ValidateMACAddress validates a MAC address.
236
-func ValidateMACAddress(val string) (string, error) {
237
-	_, err := net.ParseMAC(strings.TrimSpace(val))
238
-	if err != nil {
239
-		return "", err
240
-	}
241
-	return val, nil
242
-}
243
-
244 235
 // ValidateDNSSearch validates domain for resolvconf search configuration.
245 236
 // A zero length domain is represented by a dot (.).
246 237
 func ValidateDNSSearch(val string) (string, error) {
... ...
@@ -270,111 +263,6 @@ func ValidateLabel(val string) (string, error) {
270 270
 	return val, nil
271 271
 }
272 272
 
273
-// ValidateSysctl validates a sysctl and returns it.
274
-func ValidateSysctl(val string) (string, error) {
275
-	validSysctlMap := map[string]bool{
276
-		"kernel.msgmax":          true,
277
-		"kernel.msgmnb":          true,
278
-		"kernel.msgmni":          true,
279
-		"kernel.sem":             true,
280
-		"kernel.shmall":          true,
281
-		"kernel.shmmax":          true,
282
-		"kernel.shmmni":          true,
283
-		"kernel.shm_rmid_forced": true,
284
-	}
285
-	validSysctlPrefixes := []string{
286
-		"net.",
287
-		"fs.mqueue.",
288
-	}
289
-	arr := strings.Split(val, "=")
290
-	if len(arr) < 2 {
291
-		return "", fmt.Errorf("sysctl '%s' is not whitelisted", val)
292
-	}
293
-	if validSysctlMap[arr[0]] {
294
-		return val, nil
295
-	}
296
-
297
-	for _, vp := range validSysctlPrefixes {
298
-		if strings.HasPrefix(arr[0], vp) {
299
-			return val, nil
300
-		}
301
-	}
302
-	return "", fmt.Errorf("sysctl '%s' is not whitelisted", val)
303
-}
304
-
305
-// FilterOpt is a flag type for validating filters
306
-type FilterOpt struct {
307
-	filter filters.Args
308
-}
309
-
310
-// NewFilterOpt returns a new FilterOpt
311
-func NewFilterOpt() FilterOpt {
312
-	return FilterOpt{filter: filters.NewArgs()}
313
-}
314
-
315
-func (o *FilterOpt) String() string {
316
-	repr, err := filters.ToParam(o.filter)
317
-	if err != nil {
318
-		return "invalid filters"
319
-	}
320
-	return repr
321
-}
322
-
323
-// Set sets the value of the opt by parsing the command line value
324
-func (o *FilterOpt) Set(value string) error {
325
-	var err error
326
-	o.filter, err = filters.ParseFlag(value, o.filter)
327
-	return err
328
-}
329
-
330
-// Type returns the option type
331
-func (o *FilterOpt) Type() string {
332
-	return "filter"
333
-}
334
-
335
-// Value returns the value of this option
336
-func (o *FilterOpt) Value() filters.Args {
337
-	return o.filter
338
-}
339
-
340
-// NanoCPUs is a type for fixed point fractional number.
341
-type NanoCPUs int64
342
-
343
-// String returns the string format of the number
344
-func (c *NanoCPUs) String() string {
345
-	return big.NewRat(c.Value(), 1e9).FloatString(3)
346
-}
347
-
348
-// Set sets the value of the NanoCPU by passing a string
349
-func (c *NanoCPUs) Set(value string) error {
350
-	cpus, err := ParseCPUs(value)
351
-	*c = NanoCPUs(cpus)
352
-	return err
353
-}
354
-
355
-// Type returns the type
356
-func (c *NanoCPUs) Type() string {
357
-	return "decimal"
358
-}
359
-
360
-// Value returns the value in int64
361
-func (c *NanoCPUs) Value() int64 {
362
-	return int64(*c)
363
-}
364
-
365
-// ParseCPUs takes a string ratio and returns an integer value of nano cpus
366
-func ParseCPUs(value string) (int64, error) {
367
-	cpu, ok := new(big.Rat).SetString(value)
368
-	if !ok {
369
-		return 0, fmt.Errorf("failed to parse %v as a rational number", value)
370
-	}
371
-	nano := cpu.Mul(cpu, big.NewRat(1e9, 1))
372
-	if !nano.IsInt() {
373
-		return 0, fmt.Errorf("value is too precise")
374
-	}
375
-	return nano.Num().Int64(), nil
376
-}
377
-
378 273
 // ParseLink parses and validates the specified string as a link format (name:alias)
379 274
 func ParseLink(val string) (string, string, error) {
380 275
 	if val == "" {
... ...
@@ -397,8 +285,43 @@ func ParseLink(val string) (string, string, error) {
397 397
 	return arr[0], arr[1], nil
398 398
 }
399 399
 
400
-// ValidateLink validates that the specified string has a valid link format (containerName:alias).
401
-func ValidateLink(val string) (string, error) {
402
-	_, _, err := ParseLink(val)
403
-	return val, err
400
+// MemBytes is a type for human readable memory bytes (like 128M, 2g, etc)
401
+type MemBytes int64
402
+
403
+// String returns the string format of the human readable memory bytes
404
+func (m *MemBytes) String() string {
405
+	// NOTE: In spf13/pflag/flag.go, "0" is considered as "zero value" while "0 B" is not.
406
+	// We return "0" in case value is 0 here so that the default value is hidden.
407
+	// (Sometimes "default 0 B" is actually misleading)
408
+	if m.Value() != 0 {
409
+		return units.BytesSize(float64(m.Value()))
410
+	}
411
+	return "0"
412
+}
413
+
414
+// Set sets the value of the MemBytes by passing a string
415
+func (m *MemBytes) Set(value string) error {
416
+	val, err := units.RAMInBytes(value)
417
+	*m = MemBytes(val)
418
+	return err
419
+}
420
+
421
+// Type returns the type
422
+func (m *MemBytes) Type() string {
423
+	return "bytes"
424
+}
425
+
426
+// Value returns the value in int64
427
+func (m *MemBytes) Value() int64 {
428
+	return int64(*m)
429
+}
430
+
431
+// UnmarshalJSON is the customized unmarshaler for MemBytes
432
+func (m *MemBytes) UnmarshalJSON(s []byte) error {
433
+	if len(s) <= 2 || s[0] != '"' || s[len(s)-1] != '"' {
434
+		return fmt.Errorf("invalid size: %q", s)
435
+	}
436
+	val, err := units.RAMInBytes(string(s[1 : len(s)-1]))
437
+	*m = MemBytes(val)
438
+	return err
404 439
 }
405 440
deleted file mode 100644
... ...
@@ -1,146 +0,0 @@
1
-package opts
2
-
3
-import (
4
-	"encoding/csv"
5
-	"fmt"
6
-	"regexp"
7
-	"strconv"
8
-	"strings"
9
-
10
-	"github.com/docker/docker/api/types/swarm"
11
-	"github.com/docker/go-connections/nat"
12
-)
13
-
14
-const (
15
-	portOptTargetPort    = "target"
16
-	portOptPublishedPort = "published"
17
-	portOptProtocol      = "protocol"
18
-	portOptMode          = "mode"
19
-)
20
-
21
-// PortOpt represents a port config in swarm mode.
22
-type PortOpt struct {
23
-	ports []swarm.PortConfig
24
-}
25
-
26
-// Set a new port value
27
-func (p *PortOpt) Set(value string) error {
28
-	longSyntax, err := regexp.MatchString(`\w+=\w+(,\w+=\w+)*`, value)
29
-	if err != nil {
30
-		return err
31
-	}
32
-	if longSyntax {
33
-		csvReader := csv.NewReader(strings.NewReader(value))
34
-		fields, err := csvReader.Read()
35
-		if err != nil {
36
-			return err
37
-		}
38
-
39
-		pConfig := swarm.PortConfig{}
40
-		for _, field := range fields {
41
-			parts := strings.SplitN(field, "=", 2)
42
-			if len(parts) != 2 {
43
-				return fmt.Errorf("invalid field %s", field)
44
-			}
45
-
46
-			key := strings.ToLower(parts[0])
47
-			value := strings.ToLower(parts[1])
48
-
49
-			switch key {
50
-			case portOptProtocol:
51
-				if value != string(swarm.PortConfigProtocolTCP) && value != string(swarm.PortConfigProtocolUDP) {
52
-					return fmt.Errorf("invalid protocol value %s", value)
53
-				}
54
-
55
-				pConfig.Protocol = swarm.PortConfigProtocol(value)
56
-			case portOptMode:
57
-				if value != string(swarm.PortConfigPublishModeIngress) && value != string(swarm.PortConfigPublishModeHost) {
58
-					return fmt.Errorf("invalid publish mode value %s", value)
59
-				}
60
-
61
-				pConfig.PublishMode = swarm.PortConfigPublishMode(value)
62
-			case portOptTargetPort:
63
-				tPort, err := strconv.ParseUint(value, 10, 16)
64
-				if err != nil {
65
-					return err
66
-				}
67
-
68
-				pConfig.TargetPort = uint32(tPort)
69
-			case portOptPublishedPort:
70
-				pPort, err := strconv.ParseUint(value, 10, 16)
71
-				if err != nil {
72
-					return err
73
-				}
74
-
75
-				pConfig.PublishedPort = uint32(pPort)
76
-			default:
77
-				return fmt.Errorf("invalid field key %s", key)
78
-			}
79
-		}
80
-
81
-		if pConfig.TargetPort == 0 {
82
-			return fmt.Errorf("missing mandatory field %q", portOptTargetPort)
83
-		}
84
-
85
-		if pConfig.PublishMode == "" {
86
-			pConfig.PublishMode = swarm.PortConfigPublishModeIngress
87
-		}
88
-
89
-		if pConfig.Protocol == "" {
90
-			pConfig.Protocol = swarm.PortConfigProtocolTCP
91
-		}
92
-
93
-		p.ports = append(p.ports, pConfig)
94
-	} else {
95
-		// short syntax
96
-		portConfigs := []swarm.PortConfig{}
97
-		// We can ignore errors because the format was already validated by ValidatePort
98
-		ports, portBindings, _ := nat.ParsePortSpecs([]string{value})
99
-
100
-		for port := range ports {
101
-			portConfigs = append(portConfigs, ConvertPortToPortConfig(port, portBindings)...)
102
-		}
103
-		p.ports = append(p.ports, portConfigs...)
104
-	}
105
-	return nil
106
-}
107
-
108
-// Type returns the type of this option
109
-func (p *PortOpt) Type() string {
110
-	return "port"
111
-}
112
-
113
-// String returns a string repr of this option
114
-func (p *PortOpt) String() string {
115
-	ports := []string{}
116
-	for _, port := range p.ports {
117
-		repr := fmt.Sprintf("%v:%v/%s/%s", port.PublishedPort, port.TargetPort, port.Protocol, port.PublishMode)
118
-		ports = append(ports, repr)
119
-	}
120
-	return strings.Join(ports, ", ")
121
-}
122
-
123
-// Value returns the ports
124
-func (p *PortOpt) Value() []swarm.PortConfig {
125
-	return p.ports
126
-}
127
-
128
-// ConvertPortToPortConfig converts ports to the swarm type
129
-func ConvertPortToPortConfig(
130
-	port nat.Port,
131
-	portBindings map[nat.Port][]nat.PortBinding,
132
-) []swarm.PortConfig {
133
-	ports := []swarm.PortConfig{}
134
-
135
-	for _, binding := range portBindings[port] {
136
-		hostPort, _ := strconv.ParseUint(binding.HostPort, 10, 16)
137
-		ports = append(ports, swarm.PortConfig{
138
-			//TODO Name: ?
139
-			Protocol:      swarm.PortConfigProtocol(strings.ToLower(port.Proto())),
140
-			TargetPort:    uint32(port.Int()),
141
-			PublishedPort: uint32(hostPort),
142
-			PublishMode:   swarm.PortConfigPublishModeIngress,
143
-		})
144
-	}
145
-	return ports
146
-}
147 1
deleted file mode 100644
... ...
@@ -1,107 +0,0 @@
1
-package opts
2
-
3
-import (
4
-	"encoding/csv"
5
-	"fmt"
6
-	"os"
7
-	"path/filepath"
8
-	"strconv"
9
-	"strings"
10
-
11
-	"github.com/docker/docker/api/types"
12
-)
13
-
14
-// SecretOpt is a Value type for parsing secrets
15
-type SecretOpt struct {
16
-	values []*types.SecretRequestOption
17
-}
18
-
19
-// Set a new secret value
20
-func (o *SecretOpt) Set(value string) error {
21
-	csvReader := csv.NewReader(strings.NewReader(value))
22
-	fields, err := csvReader.Read()
23
-	if err != nil {
24
-		return err
25
-	}
26
-
27
-	options := &types.SecretRequestOption{
28
-		Source: "",
29
-		Target: "",
30
-		UID:    "0",
31
-		GID:    "0",
32
-		Mode:   0444,
33
-	}
34
-
35
-	// support a simple syntax of --secret foo
36
-	if len(fields) == 1 {
37
-		options.Source = fields[0]
38
-		options.Target = fields[0]
39
-		o.values = append(o.values, options)
40
-		return nil
41
-	}
42
-
43
-	for _, field := range fields {
44
-		parts := strings.SplitN(field, "=", 2)
45
-		key := strings.ToLower(parts[0])
46
-
47
-		if len(parts) != 2 {
48
-			return fmt.Errorf("invalid field '%s' must be a key=value pair", field)
49
-		}
50
-
51
-		value := parts[1]
52
-		switch key {
53
-		case "source":
54
-			options.Source = value
55
-		case "target":
56
-			tDir, _ := filepath.Split(value)
57
-			if tDir != "" {
58
-				return fmt.Errorf("target must not be a path")
59
-			}
60
-			options.Target = value
61
-		case "uid":
62
-			options.UID = value
63
-		case "gid":
64
-			options.GID = value
65
-		case "mode":
66
-			m, err := strconv.ParseUint(value, 0, 32)
67
-			if err != nil {
68
-				return fmt.Errorf("invalid mode specified: %v", err)
69
-			}
70
-
71
-			options.Mode = os.FileMode(m)
72
-		default:
73
-			if len(fields) == 1 && value == "" {
74
-
75
-			} else {
76
-				return fmt.Errorf("invalid field in secret request: %s", key)
77
-			}
78
-		}
79
-	}
80
-
81
-	if options.Source == "" {
82
-		return fmt.Errorf("source is required")
83
-	}
84
-
85
-	o.values = append(o.values, options)
86
-	return nil
87
-}
88
-
89
-// Type returns the type of this option
90
-func (o *SecretOpt) Type() string {
91
-	return "secret"
92
-}
93
-
94
-// String returns a string repr of this option
95
-func (o *SecretOpt) String() string {
96
-	secrets := []string{}
97
-	for _, secret := range o.values {
98
-		repr := fmt.Sprintf("%s -> %s", secret.Source, secret.Target)
99
-		secrets = append(secrets, repr)
100
-	}
101
-	return strings.Join(secrets, ", ")
102
-}
103
-
104
-// Value returns the secret requests
105
-func (o *SecretOpt) Value() []*types.SecretRequestOption {
106
-	return o.values
107
-}
108 1
deleted file mode 100644
... ...
@@ -1,111 +0,0 @@
1
-package opts
2
-
3
-import (
4
-	"fmt"
5
-	"strconv"
6
-	"strings"
7
-
8
-	"github.com/docker/docker/api/types/blkiodev"
9
-	"github.com/docker/go-units"
10
-)
11
-
12
-// ValidatorThrottleFctType defines a validator function that returns a validated struct and/or an error.
13
-type ValidatorThrottleFctType func(val string) (*blkiodev.ThrottleDevice, error)
14
-
15
-// ValidateThrottleBpsDevice validates that the specified string has a valid device-rate format.
16
-func ValidateThrottleBpsDevice(val string) (*blkiodev.ThrottleDevice, error) {
17
-	split := strings.SplitN(val, ":", 2)
18
-	if len(split) != 2 {
19
-		return nil, fmt.Errorf("bad format: %s", val)
20
-	}
21
-	if !strings.HasPrefix(split[0], "/dev/") {
22
-		return nil, fmt.Errorf("bad format for device path: %s", val)
23
-	}
24
-	rate, err := units.RAMInBytes(split[1])
25
-	if err != nil {
26
-		return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val)
27
-	}
28
-	if rate < 0 {
29
-		return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val)
30
-	}
31
-
32
-	return &blkiodev.ThrottleDevice{
33
-		Path: split[0],
34
-		Rate: uint64(rate),
35
-	}, nil
36
-}
37
-
38
-// ValidateThrottleIOpsDevice validates that the specified string has a valid device-rate format.
39
-func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, error) {
40
-	split := strings.SplitN(val, ":", 2)
41
-	if len(split) != 2 {
42
-		return nil, fmt.Errorf("bad format: %s", val)
43
-	}
44
-	if !strings.HasPrefix(split[0], "/dev/") {
45
-		return nil, fmt.Errorf("bad format for device path: %s", val)
46
-	}
47
-	rate, err := strconv.ParseUint(split[1], 10, 64)
48
-	if err != nil {
49
-		return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
50
-	}
51
-	if rate < 0 {
52
-		return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
53
-	}
54
-
55
-	return &blkiodev.ThrottleDevice{
56
-		Path: split[0],
57
-		Rate: uint64(rate),
58
-	}, nil
59
-}
60
-
61
-// ThrottledeviceOpt defines a map of ThrottleDevices
62
-type ThrottledeviceOpt struct {
63
-	values    []*blkiodev.ThrottleDevice
64
-	validator ValidatorThrottleFctType
65
-}
66
-
67
-// NewThrottledeviceOpt creates a new ThrottledeviceOpt
68
-func NewThrottledeviceOpt(validator ValidatorThrottleFctType) ThrottledeviceOpt {
69
-	values := []*blkiodev.ThrottleDevice{}
70
-	return ThrottledeviceOpt{
71
-		values:    values,
72
-		validator: validator,
73
-	}
74
-}
75
-
76
-// Set validates a ThrottleDevice and sets its name as a key in ThrottledeviceOpt
77
-func (opt *ThrottledeviceOpt) Set(val string) error {
78
-	var value *blkiodev.ThrottleDevice
79
-	if opt.validator != nil {
80
-		v, err := opt.validator(val)
81
-		if err != nil {
82
-			return err
83
-		}
84
-		value = v
85
-	}
86
-	(opt.values) = append((opt.values), value)
87
-	return nil
88
-}
89
-
90
-// String returns ThrottledeviceOpt values as a string.
91
-func (opt *ThrottledeviceOpt) String() string {
92
-	var out []string
93
-	for _, v := range opt.values {
94
-		out = append(out, v.String())
95
-	}
96
-
97
-	return fmt.Sprintf("%v", out)
98
-}
99
-
100
-// GetList returns a slice of pointers to ThrottleDevices.
101
-func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice {
102
-	var throttledevice []*blkiodev.ThrottleDevice
103
-	throttledevice = append(throttledevice, opt.values...)
104
-
105
-	return throttledevice
106
-}
107
-
108
-// Type returns the option type
109
-func (opt *ThrottledeviceOpt) Type() string {
110
-	return "list"
111
-}
112 1
deleted file mode 100644
... ...
@@ -1,89 +0,0 @@
1
-package opts
2
-
3
-import (
4
-	"fmt"
5
-	"strconv"
6
-	"strings"
7
-
8
-	"github.com/docker/docker/api/types/blkiodev"
9
-)
10
-
11
-// ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error.
12
-type ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error)
13
-
14
-// ValidateWeightDevice validates that the specified string has a valid device-weight format.
15
-func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error) {
16
-	split := strings.SplitN(val, ":", 2)
17
-	if len(split) != 2 {
18
-		return nil, fmt.Errorf("bad format: %s", val)
19
-	}
20
-	if !strings.HasPrefix(split[0], "/dev/") {
21
-		return nil, fmt.Errorf("bad format for device path: %s", val)
22
-	}
23
-	weight, err := strconv.ParseUint(split[1], 10, 0)
24
-	if err != nil {
25
-		return nil, fmt.Errorf("invalid weight for device: %s", val)
26
-	}
27
-	if weight > 0 && (weight < 10 || weight > 1000) {
28
-		return nil, fmt.Errorf("invalid weight for device: %s", val)
29
-	}
30
-
31
-	return &blkiodev.WeightDevice{
32
-		Path:   split[0],
33
-		Weight: uint16(weight),
34
-	}, nil
35
-}
36
-
37
-// WeightdeviceOpt defines a map of WeightDevices
38
-type WeightdeviceOpt struct {
39
-	values    []*blkiodev.WeightDevice
40
-	validator ValidatorWeightFctType
41
-}
42
-
43
-// NewWeightdeviceOpt creates a new WeightdeviceOpt
44
-func NewWeightdeviceOpt(validator ValidatorWeightFctType) WeightdeviceOpt {
45
-	values := []*blkiodev.WeightDevice{}
46
-	return WeightdeviceOpt{
47
-		values:    values,
48
-		validator: validator,
49
-	}
50
-}
51
-
52
-// Set validates a WeightDevice and sets its name as a key in WeightdeviceOpt
53
-func (opt *WeightdeviceOpt) Set(val string) error {
54
-	var value *blkiodev.WeightDevice
55
-	if opt.validator != nil {
56
-		v, err := opt.validator(val)
57
-		if err != nil {
58
-			return err
59
-		}
60
-		value = v
61
-	}
62
-	(opt.values) = append((opt.values), value)
63
-	return nil
64
-}
65
-
66
-// String returns WeightdeviceOpt values as a string.
67
-func (opt *WeightdeviceOpt) String() string {
68
-	var out []string
69
-	for _, v := range opt.values {
70
-		out = append(out, v.String())
71
-	}
72
-
73
-	return fmt.Sprintf("%v", out)
74
-}
75
-
76
-// GetList returns a slice of pointers to WeightDevices.
77
-func (opt *WeightdeviceOpt) GetList() []*blkiodev.WeightDevice {
78
-	var weightdevice []*blkiodev.WeightDevice
79
-	for _, v := range opt.values {
80
-		weightdevice = append(weightdevice, v)
81
-	}
82
-
83
-	return weightdevice
84
-}
85
-
86
-// Type returns the option type
87
-func (opt *WeightdeviceOpt) Type() string {
88
-	return "list"
89
-}
90 1
deleted file mode 100644
... ...
@@ -1,22 +0,0 @@
1
-package ioutils
2
-
3
-import (
4
-	"fmt"
5
-	"io"
6
-)
7
-
8
-// FprintfIfNotEmpty prints the string value if it's not empty
9
-func FprintfIfNotEmpty(w io.Writer, format, value string) (int, error) {
10
-	if value != "" {
11
-		return fmt.Fprintf(w, format, value)
12
-	}
13
-	return 0, nil
14
-}
15
-
16
-// FprintfIfTrue prints the boolean value if it's true
17
-func FprintfIfTrue(w io.Writer, format string, ok bool) (int, error) {
18
-	if ok {
19
-		return fmt.Fprintf(w, format, ok)
20
-	}
21
-	return 0, nil
22
-}
... ...
@@ -152,7 +152,8 @@ func (r *multiReadSeeker) getOffsetToReader(rdr io.ReadSeeker) (int64, error) {
152 152
 
153 153
 func (r *multiReadSeeker) Read(b []byte) (int, error) {
154 154
 	if r.pos == nil {
155
-		r.pos = &pos{0, 0}
155
+		// make sure all readers are at 0
156
+		r.Seek(0, os.SEEK_SET)
156 157
 	}
157 158
 
158 159
 	bLen := int64(len(b))
... ...
@@ -45,4 +45,5 @@ const (
45 45
 	RELATIME    = 0
46 46
 	REMOUNT     = 0
47 47
 	STRICTATIME = 0
48
+	mntDetach   = 0
48 49
 )
... ...
@@ -82,4 +82,6 @@ const (
82 82
 	// it possible for the kernel to default to relatime or noatime but still
83 83
 	// allow userspace to override it.
84 84
 	STRICTATIME = syscall.MS_STRICTATIME
85
+
86
+	mntDetach = syscall.MNT_DETACH
85 87
 )
... ...
@@ -27,4 +27,5 @@ const (
27 27
 	STRICTATIME = 0
28 28
 	SYNCHRONOUS = 0
29 29
 	RDONLY      = 0
30
+	mntDetach   = 0
30 31
 )
... ...
@@ -1,7 +1,8 @@
1 1
 package mount
2 2
 
3 3
 import (
4
-	"time"
4
+	"sort"
5
+	"strings"
5 6
 )
6 7
 
7 8
 // GetMounts retrieves a list of mounts for the current running process.
... ...
@@ -46,29 +47,40 @@ func Mount(device, target, mType, options string) error {
46 46
 // flags.go for supported option flags.
47 47
 func ForceMount(device, target, mType, options string) error {
48 48
 	flag, data := parseOptions(options)
49
-	if err := mount(device, target, mType, uintptr(flag), data); err != nil {
50
-		return err
51
-	}
52
-	return nil
49
+	return mount(device, target, mType, uintptr(flag), data)
53 50
 }
54 51
 
55
-// Unmount will unmount the target filesystem, so long as it is mounted.
52
+// Unmount lazily unmounts a filesystem on supported platforms, otherwise
53
+// does a normal unmount.
56 54
 func Unmount(target string) error {
57 55
 	if mounted, err := Mounted(target); err != nil || !mounted {
58 56
 		return err
59 57
 	}
60
-	return ForceUnmount(target)
58
+	return unmount(target, mntDetach)
61 59
 }
62 60
 
63
-// ForceUnmount will force an unmount of the target filesystem, regardless if
64
-// it is mounted or not.
65
-func ForceUnmount(target string) (err error) {
66
-	// Simple retry logic for unmount
67
-	for i := 0; i < 10; i++ {
68
-		if err = unmount(target, 0); err == nil {
69
-			return nil
61
+// RecursiveUnmount unmounts the target and all mounts underneath, starting with
62
+// the deepsest mount first.
63
+func RecursiveUnmount(target string) error {
64
+	mounts, err := GetMounts()
65
+	if err != nil {
66
+		return err
67
+	}
68
+
69
+	// Make the deepest mount be first
70
+	sort.Sort(sort.Reverse(byMountpoint(mounts)))
71
+
72
+	for i, m := range mounts {
73
+		if !strings.HasPrefix(m.Mountpoint, target) {
74
+			continue
75
+		}
76
+		if err := Unmount(m.Mountpoint); err != nil && i == len(mounts)-1 {
77
+			if mounted, err := Mounted(m.Mountpoint); err != nil || mounted {
78
+				return err
79
+			}
80
+			// Ignore errors for submounts and continue trying to unmount others
81
+			// The final unmount should fail if there ane any submounts remaining
70 82
 		}
71
-		time.Sleep(100 * time.Millisecond)
72 83
 	}
73
-	return
84
+	return nil
74 85
 }
... ...
@@ -4,15 +4,50 @@ import (
4 4
 	"syscall"
5 5
 )
6 6
 
7
-func mount(device, target, mType string, flag uintptr, data string) error {
8
-	if err := syscall.Mount(device, target, mType, flag, data); err != nil {
9
-		return err
7
+const (
8
+	// ptypes is the set propagation types.
9
+	ptypes = syscall.MS_SHARED | syscall.MS_PRIVATE | syscall.MS_SLAVE | syscall.MS_UNBINDABLE
10
+
11
+	// pflags is the full set valid flags for a change propagation call.
12
+	pflags = ptypes | syscall.MS_REC | syscall.MS_SILENT
13
+
14
+	// broflags is the combination of bind and read only
15
+	broflags = syscall.MS_BIND | syscall.MS_RDONLY
16
+)
17
+
18
+// isremount returns true if either device name or flags identify a remount request, false otherwise.
19
+func isremount(device string, flags uintptr) bool {
20
+	switch {
21
+	// We treat device "" and "none" as a remount request to provide compatibility with
22
+	// requests that don't explicitly set MS_REMOUNT such as those manipulating bind mounts.
23
+	case flags&syscall.MS_REMOUNT != 0, device == "", device == "none":
24
+		return true
25
+	default:
26
+		return false
27
+	}
28
+}
29
+
30
+func mount(device, target, mType string, flags uintptr, data string) error {
31
+	oflags := flags &^ ptypes
32
+	if !isremount(device, flags) {
33
+		// Initial call applying all non-propagation flags.
34
+		if err := syscall.Mount(device, target, mType, oflags, data); err != nil {
35
+			return err
36
+		}
10 37
 	}
11 38
 
12
-	// If we have a bind mount or remount, remount...
13
-	if flag&syscall.MS_BIND == syscall.MS_BIND && flag&syscall.MS_RDONLY == syscall.MS_RDONLY {
14
-		return syscall.Mount(device, target, mType, flag|syscall.MS_REMOUNT, data)
39
+	if flags&ptypes != 0 {
40
+		// Change the propagation type.
41
+		if err := syscall.Mount("", target, "", flags&pflags, ""); err != nil {
42
+			return err
43
+		}
15 44
 	}
45
+
46
+	if oflags&broflags == broflags {
47
+		// Remount the bind to apply read only.
48
+		return syscall.Mount("", target, "", oflags|syscall.MS_REMOUNT, "")
49
+	}
50
+
16 51
 	return nil
17 52
 }
18 53
 
... ...
@@ -38,3 +38,17 @@ type Info struct {
38 38
 	// VfsOpts represents per super block options.
39 39
 	VfsOpts string
40 40
 }
41
+
42
+type byMountpoint []*Info
43
+
44
+func (by byMountpoint) Len() int {
45
+	return len(by)
46
+}
47
+
48
+func (by byMountpoint) Less(i, j int) bool {
49
+	return by[i].Mountpoint < by[j].Mountpoint
50
+}
51
+
52
+func (by byMountpoint) Swap(i, j int) {
53
+	by[i], by[j] = by[j], by[i]
54
+}
... ...
@@ -1,4 +1,4 @@
1
-// +build linux freebsd solaris
1
+// +build linux freebsd solaris openbsd
2 2
 
3 3
 // Package kernel provides helper function to get, parse and compare kernel
4 4
 // versions for different platforms.
... ...
@@ -78,12 +78,6 @@ type Plugin struct {
78 78
 	handlersRun bool
79 79
 }
80 80
 
81
-// BasePath returns the path to which all paths returned by the plugin are relative to.
82
-// For v1 plugins, this always returns the host's root directory.
83
-func (p *Plugin) BasePath() string {
84
-	return "/"
85
-}
86
-
87 81
 // Name returns the name of the plugin.
88 82
 func (p *Plugin) Name() string {
89 83
 	return p.name
... ...
@@ -175,7 +169,7 @@ func (p *Plugin) activateWithLock() error {
175 175
 
176 176
 func (p *Plugin) waitActive() error {
177 177
 	p.activateWait.L.Lock()
178
-	for !p.activated() {
178
+	for !p.activated() && p.activateErr == nil {
179 179
 		p.activateWait.Wait()
180 180
 	}
181 181
 	p.activateWait.L.Unlock()
182 182
new file mode 100644
... ...
@@ -0,0 +1,9 @@
0
+// +build !windows
1
+
2
+package plugins
3
+
4
+// BasePath returns the path to which all paths returned by the plugin are relative to.
5
+// For v1 plugins, this always returns the host's root directory.
6
+func (p *Plugin) BasePath() string {
7
+	return "/"
8
+}
0 9
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+package plugins
1
+
2
+// BasePath returns the path to which all paths returned by the plugin are relative to.
3
+// For Windows v1 plugins, this returns an empty string, since the plugin is already aware
4
+// of the absolute path of the mount.
5
+func (p *Plugin) BasePath() string {
6
+	return ""
7
+}
... ...
@@ -176,7 +176,7 @@
176 176
 
177 177
    END OF TERMS AND CONDITIONS
178 178
 
179
-   Copyright 2014-2016 Docker, Inc.
179
+   Copyright 2014-2017 Docker, Inc.
180 180
 
181 181
    Licensed under the Apache License, Version 2.0 (the "License");
182 182
    you may not use this file except in compliance with the License.
... ...
@@ -1,4 +1,4 @@
1
-Copyright (c) 2014-2016 The Docker & Go Authors. All rights reserved.
1
+Copyright (c) 2014-2017 The Docker & Go Authors. All rights reserved.
2 2
 
3 3
 Redistribution and use in source and binary forms, with or without
4 4
 modification, are permitted provided that the following conditions are
... ...
@@ -3,6 +3,7 @@
3 3
 package system
4 4
 
5 5
 import (
6
+	"io/ioutil"
6 7
 	"os"
7 8
 	"path/filepath"
8 9
 )
... ...
@@ -24,7 +25,7 @@ func IsAbs(path string) bool {
24 24
 	return filepath.IsAbs(path)
25 25
 }
26 26
 
27
-// The functions below here are wrappers for the equivalents in the os package.
27
+// The functions below here are wrappers for the equivalents in the os and ioutils packages.
28 28
 // They are passthrough on Unix platforms, and only relevant on Windows.
29 29
 
30 30
 // CreateSequential creates the named file with mode 0666 (before umask), truncating
... ...
@@ -52,3 +53,16 @@ func OpenSequential(name string) (*os.File, error) {
52 52
 func OpenFileSequential(name string, flag int, perm os.FileMode) (*os.File, error) {
53 53
 	return os.OpenFile(name, flag, perm)
54 54
 }
55
+
56
+// TempFileSequential creates a new temporary file in the directory dir
57
+// with a name beginning with prefix, opens the file for reading
58
+// and writing, and returns the resulting *os.File.
59
+// If dir is the empty string, TempFile uses the default directory
60
+// for temporary files (see os.TempDir).
61
+// Multiple programs calling TempFile simultaneously
62
+// will not choose the same file. The caller can use f.Name()
63
+// to find the pathname of the file. It is the caller's responsibility
64
+// to remove the file when no longer needed.
65
+func TempFileSequential(dir, prefix string) (f *os.File, err error) {
66
+	return ioutil.TempFile(dir, prefix)
67
+}
... ...
@@ -6,8 +6,11 @@ import (
6 6
 	"os"
7 7
 	"path/filepath"
8 8
 	"regexp"
9
+	"strconv"
9 10
 	"strings"
11
+	"sync"
10 12
 	"syscall"
13
+	"time"
11 14
 	"unsafe"
12 15
 
13 16
 	winio "github.com/Microsoft/go-winio"
... ...
@@ -234,3 +237,55 @@ func syscallOpenSequential(path string, mode int, _ uint32) (fd syscall.Handle,
234 234
 	h, e := syscall.CreateFile(pathp, access, sharemode, sa, createmode, fileFlagSequentialScan, 0)
235 235
 	return h, e
236 236
 }
237
+
238
+// Helpers for TempFileSequential
239
+var rand uint32
240
+var randmu sync.Mutex
241
+
242
+func reseed() uint32 {
243
+	return uint32(time.Now().UnixNano() + int64(os.Getpid()))
244
+}
245
+func nextSuffix() string {
246
+	randmu.Lock()
247
+	r := rand
248
+	if r == 0 {
249
+		r = reseed()
250
+	}
251
+	r = r*1664525 + 1013904223 // constants from Numerical Recipes
252
+	rand = r
253
+	randmu.Unlock()
254
+	return strconv.Itoa(int(1e9 + r%1e9))[1:]
255
+}
256
+
257
+// TempFileSequential is a copy of ioutil.TempFile, modified to use sequential
258
+// file access. Below is the original comment from golang:
259
+// TempFile creates a new temporary file in the directory dir
260
+// with a name beginning with prefix, opens the file for reading
261
+// and writing, and returns the resulting *os.File.
262
+// If dir is the empty string, TempFile uses the default directory
263
+// for temporary files (see os.TempDir).
264
+// Multiple programs calling TempFile simultaneously
265
+// will not choose the same file. The caller can use f.Name()
266
+// to find the pathname of the file. It is the caller's responsibility
267
+// to remove the file when no longer needed.
268
+func TempFileSequential(dir, prefix string) (f *os.File, err error) {
269
+	if dir == "" {
270
+		dir = os.TempDir()
271
+	}
272
+
273
+	nconflict := 0
274
+	for i := 0; i < 10000; i++ {
275
+		name := filepath.Join(dir, prefix+nextSuffix())
276
+		f, err = OpenFileSequential(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
277
+		if os.IsExist(err) {
278
+			if nconflict++; nconflict > 10 {
279
+				randmu.Lock()
280
+				rand = reseed()
281
+				randmu.Unlock()
282
+			}
283
+			continue
284
+		}
285
+		break
286
+	}
287
+	return
288
+}
237 289
deleted file mode 100644
... ...
@@ -1,19 +0,0 @@
1
-// +build !windows
2
-
3
-package system
4
-
5
-import (
6
-	"syscall"
7
-)
8
-
9
-// Lstat takes a path to a file and returns
10
-// a system.StatT type pertaining to that file.
11
-//
12
-// Throws an error if the file does not exist
13
-func Lstat(path string) (*StatT, error) {
14
-	s := &syscall.Stat_t{}
15
-	if err := syscall.Lstat(path, s); err != nil {
16
-		return nil, err
17
-	}
18
-	return fromStatT(s)
19
-}
20 1
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+// +build !windows
1
+
2
+package system
3
+
4
+import "syscall"
5
+
6
+// Lstat takes a path to a file and returns
7
+// a system.StatT type pertaining to that file.
8
+//
9
+// Throws an error if the file does not exist
10
+func Lstat(path string) (*StatT, error) {
11
+	s := &syscall.Stat_t{}
12
+	if err := syscall.Lstat(path, s); err != nil {
13
+		return nil, err
14
+	}
15
+	return fromStatT(s)
16
+}
... ...
@@ -1,25 +1,14 @@
1
-// +build windows
2
-
3 1
 package system
4 2
 
5
-import (
6
-	"os"
7
-)
3
+import "os"
8 4
 
9 5
 // Lstat calls os.Lstat to get a fileinfo interface back.
10 6
 // This is then copied into our own locally defined structure.
11
-// Note the Linux version uses fromStatT to do the copy back,
12
-// but that not strictly necessary when already in an OS specific module.
13 7
 func Lstat(path string) (*StatT, error) {
14 8
 	fi, err := os.Lstat(path)
15 9
 	if err != nil {
16 10
 		return nil, err
17 11
 	}
18 12
 
19
-	return &StatT{
20
-		name:    fi.Name(),
21
-		size:    fi.Size(),
22
-		mode:    fi.Mode(),
23
-		modTime: fi.ModTime(),
24
-		isDir:   fi.IsDir()}, nil
13
+	return fromStatT(&fi)
25 14
 }
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"unsafe"
8 8
 )
9 9
 
10
+// #cgo CFLAGS: -std=c99
10 11
 // #cgo LDFLAGS: -lkstat
11 12
 // #include <unistd.h>
12 13
 // #include <stdlib.h>
13 14
deleted file mode 100644
... ...
@@ -1,20 +0,0 @@
1
-package system
2
-
3
-// IsProcessAlive returns true if process with a given pid is running.
4
-func IsProcessAlive(pid int) bool {
5
-	// TODO Windows containerd. Not sure this is needed
6
-	//	p, err := os.FindProcess(pid)
7
-	//	if err == nil {
8
-	//		return true
9
-	//	}
10
-	return false
11
-}
12
-
13
-// KillProcess force-stops a process.
14
-func KillProcess(pid int) {
15
-	// TODO Windows containerd. Not sure this is needed
16
-	//	p, err := os.FindProcess(pid)
17
-	//	if err == nil {
18
-	//		p.Kill()
19
-	//	}
20
-}
21 1
new file mode 100644
... ...
@@ -0,0 +1,80 @@
0
+package system
1
+
2
+import (
3
+	"os"
4
+	"syscall"
5
+	"time"
6
+
7
+	"github.com/docker/docker/pkg/mount"
8
+	"github.com/pkg/errors"
9
+)
10
+
11
+// EnsureRemoveAll wraps `os.RemoveAll` to check for specific errors that can
12
+// often be remedied.
13
+// Only use `EnsureRemoveAll` if you really want to make every effort to remove
14
+// a directory.
15
+//
16
+// Because of the way `os.Remove` (and by extension `os.RemoveAll`) works, there
17
+// can be a race between reading directory entries and then actually attempting
18
+// to remove everything in the directory.
19
+// These types of errors do not need to be returned since it's ok for the dir to
20
+// be gone we can just retry the remove operation.
21
+//
22
+// This should not return a `os.ErrNotExist` kind of error under any cirucmstances
23
+func EnsureRemoveAll(dir string) error {
24
+	notExistErr := make(map[string]bool)
25
+
26
+	// track retries
27
+	exitOnErr := make(map[string]int)
28
+	maxRetry := 5
29
+
30
+	// Attempt to unmount anything beneath this dir first
31
+	mount.RecursiveUnmount(dir)
32
+
33
+	for {
34
+		err := os.RemoveAll(dir)
35
+		if err == nil {
36
+			return err
37
+		}
38
+
39
+		pe, ok := err.(*os.PathError)
40
+		if !ok {
41
+			return err
42
+		}
43
+
44
+		if os.IsNotExist(err) {
45
+			if notExistErr[pe.Path] {
46
+				return err
47
+			}
48
+			notExistErr[pe.Path] = true
49
+
50
+			// There is a race where some subdir can be removed but after the parent
51
+			//   dir entries have been read.
52
+			// So the path could be from `os.Remove(subdir)`
53
+			// If the reported non-existent path is not the passed in `dir` we
54
+			// should just retry, but otherwise return with no error.
55
+			if pe.Path == dir {
56
+				return nil
57
+			}
58
+			continue
59
+		}
60
+
61
+		if pe.Err != syscall.EBUSY {
62
+			return err
63
+		}
64
+
65
+		if mounted, _ := mount.Mounted(pe.Path); mounted {
66
+			if e := mount.Unmount(pe.Path); e != nil {
67
+				if mounted, _ := mount.Mounted(pe.Path); mounted {
68
+					return errors.Wrapf(e, "error while removing %s", dir)
69
+				}
70
+			}
71
+		}
72
+
73
+		if exitOnErr[pe.Path] == maxRetry {
74
+			return err
75
+		}
76
+		exitOnErr[pe.Path]++
77
+		time.Sleep(100 * time.Millisecond)
78
+	}
79
+}
0 80
deleted file mode 100644
... ...
@@ -1,53 +0,0 @@
1
-// +build !windows
2
-
3
-package system
4
-
5
-import (
6
-	"syscall"
7
-)
8
-
9
-// StatT type contains status of a file. It contains metadata
10
-// like permission, owner, group, size, etc about a file.
11
-type StatT struct {
12
-	mode uint32
13
-	uid  uint32
14
-	gid  uint32
15
-	rdev uint64
16
-	size int64
17
-	mtim syscall.Timespec
18
-}
19
-
20
-// Mode returns file's permission mode.
21
-func (s StatT) Mode() uint32 {
22
-	return s.mode
23
-}
24
-
25
-// UID returns file's user id of owner.
26
-func (s StatT) UID() uint32 {
27
-	return s.uid
28
-}
29
-
30
-// GID returns file's group id of owner.
31
-func (s StatT) GID() uint32 {
32
-	return s.gid
33
-}
34
-
35
-// Rdev returns file's device ID (if it's special file).
36
-func (s StatT) Rdev() uint64 {
37
-	return s.rdev
38
-}
39
-
40
-// Size returns file's size.
41
-func (s StatT) Size() int64 {
42
-	return s.size
43
-}
44
-
45
-// Mtim returns file's last modification time.
46
-func (s StatT) Mtim() syscall.Timespec {
47
-	return s.mtim
48
-}
49
-
50
-// GetLastModification returns file's last modification time.
51
-func (s StatT) GetLastModification() syscall.Timespec {
52
-	return s.Mtim()
53
-}
... ...
@@ -1,10 +1,8 @@
1 1
 package system
2 2
 
3
-import (
4
-	"syscall"
5
-)
3
+import "syscall"
6 4
 
7
-// fromStatT creates a system.StatT type from a syscall.Stat_t type
5
+// fromStatT converts a syscall.Stat_t type to a system.Stat_t type
8 6
 func fromStatT(s *syscall.Stat_t) (*StatT, error) {
9 7
 	return &StatT{size: s.Size,
10 8
 		mode: uint32(s.Mode),
... ...
@@ -13,20 +11,3 @@ func fromStatT(s *syscall.Stat_t) (*StatT, error) {
13 13
 		rdev: uint64(s.Rdev),
14 14
 		mtim: s.Mtimespec}, nil
15 15
 }
16
-
17
-// FromStatT loads a system.StatT from a syscall.Stat_t.
18
-func FromStatT(s *syscall.Stat_t) (*StatT, error) {
19
-	return fromStatT(s)
20
-}
21
-
22
-// Stat takes a path to a file and returns
23
-// a system.StatT type pertaining to that file.
24
-//
25
-// Throws an error if the file does not exist
26
-func Stat(path string) (*StatT, error) {
27
-	s := &syscall.Stat_t{}
28
-	if err := syscall.Stat(path, s); err != nil {
29
-		return nil, err
30
-	}
31
-	return fromStatT(s)
32
-}
... ...
@@ -1,8 +1,6 @@
1 1
 package system
2 2
 
3
-import (
4
-	"syscall"
5
-)
3
+import "syscall"
6 4
 
7 5
 // fromStatT converts a syscall.Stat_t type to a system.Stat_t type
8 6
 func fromStatT(s *syscall.Stat_t) (*StatT, error) {
... ...
@@ -13,15 +11,3 @@ func fromStatT(s *syscall.Stat_t) (*StatT, error) {
13 13
 		rdev: uint64(s.Rdev),
14 14
 		mtim: s.Mtimespec}, nil
15 15
 }
16
-
17
-// Stat takes a path to a file and returns
18
-// a system.Stat_t type pertaining to that file.
19
-//
20
-// Throws an error if the file does not exist
21
-func Stat(path string) (*StatT, error) {
22
-	s := &syscall.Stat_t{}
23
-	if err := syscall.Stat(path, s); err != nil {
24
-		return nil, err
25
-	}
26
-	return fromStatT(s)
27
-}
... ...
@@ -1,33 +1,19 @@
1 1
 package system
2 2
 
3
-import (
4
-	"syscall"
5
-)
3
+import "syscall"
6 4
 
7 5
 // fromStatT converts a syscall.Stat_t type to a system.Stat_t type
8 6
 func fromStatT(s *syscall.Stat_t) (*StatT, error) {
9 7
 	return &StatT{size: s.Size,
10
-		mode: s.Mode,
8
+		mode: uint32(s.Mode),
11 9
 		uid:  s.Uid,
12 10
 		gid:  s.Gid,
13
-		rdev: s.Rdev,
11
+		rdev: uint64(s.Rdev),
14 12
 		mtim: s.Mtim}, nil
15 13
 }
16 14
 
17
-// FromStatT exists only on linux, and loads a system.StatT from a
18
-// syscal.Stat_t.
15
+// FromStatT converts a syscall.Stat_t type to a system.Stat_t type
16
+// This is exposed on Linux as pkg/archive/changes uses it.
19 17
 func FromStatT(s *syscall.Stat_t) (*StatT, error) {
20 18
 	return fromStatT(s)
21 19
 }
22
-
23
-// Stat takes a path to a file and returns
24
-// a system.StatT type pertaining to that file.
25
-//
26
-// Throws an error if the file does not exist
27
-func Stat(path string) (*StatT, error) {
28
-	s := &syscall.Stat_t{}
29
-	if err := syscall.Stat(path, s); err != nil {
30
-		return nil, err
31
-	}
32
-	return fromStatT(s)
33
-}
... ...
@@ -1,10 +1,8 @@
1 1
 package system
2 2
 
3
-import (
4
-	"syscall"
5
-)
3
+import "syscall"
6 4
 
7
-// fromStatT creates a system.StatT type from a syscall.Stat_t type
5
+// fromStatT converts a syscall.Stat_t type to a system.Stat_t type
8 6
 func fromStatT(s *syscall.Stat_t) (*StatT, error) {
9 7
 	return &StatT{size: s.Size,
10 8
 		mode: uint32(s.Mode),
... ...
@@ -1,12 +1,8 @@
1
-// +build solaris
2
-
3 1
 package system
4 2
 
5
-import (
6
-	"syscall"
7
-)
3
+import "syscall"
8 4
 
9
-// fromStatT creates a system.StatT type from a syscall.Stat_t type
5
+// fromStatT converts a syscall.Stat_t type to a system.Stat_t type
10 6
 func fromStatT(s *syscall.Stat_t) (*StatT, error) {
11 7
 	return &StatT{size: s.Size,
12 8
 		mode: uint32(s.Mode),
... ...
@@ -15,20 +11,3 @@ func fromStatT(s *syscall.Stat_t) (*StatT, error) {
15 15
 		rdev: uint64(s.Rdev),
16 16
 		mtim: s.Mtim}, nil
17 17
 }
18
-
19
-// FromStatT loads a system.StatT from a syscal.Stat_t.
20
-func FromStatT(s *syscall.Stat_t) (*StatT, error) {
21
-	return fromStatT(s)
22
-}
23
-
24
-// Stat takes a path to a file and returns
25
-// a system.StatT type pertaining to that file.
26
-//
27
-// Throws an error if the file does not exist
28
-func Stat(path string) (*StatT, error) {
29
-	s := &syscall.Stat_t{}
30
-	if err := syscall.Stat(path, s); err != nil {
31
-		return nil, err
32
-	}
33
-	return fromStatT(s)
34
-}
35 18
new file mode 100644
... ...
@@ -0,0 +1,58 @@
0
+// +build !windows
1
+
2
+package system
3
+
4
+import "syscall"
5
+
6
+// StatT type contains status of a file. It contains metadata
7
+// like permission, owner, group, size, etc about a file.
8
+type StatT struct {
9
+	mode uint32
10
+	uid  uint32
11
+	gid  uint32
12
+	rdev uint64
13
+	size int64
14
+	mtim syscall.Timespec
15
+}
16
+
17
+// Mode returns file's permission mode.
18
+func (s StatT) Mode() uint32 {
19
+	return s.mode
20
+}
21
+
22
+// UID returns file's user id of owner.
23
+func (s StatT) UID() uint32 {
24
+	return s.uid
25
+}
26
+
27
+// GID returns file's group id of owner.
28
+func (s StatT) GID() uint32 {
29
+	return s.gid
30
+}
31
+
32
+// Rdev returns file's device ID (if it's special file).
33
+func (s StatT) Rdev() uint64 {
34
+	return s.rdev
35
+}
36
+
37
+// Size returns file's size.
38
+func (s StatT) Size() int64 {
39
+	return s.size
40
+}
41
+
42
+// Mtim returns file's last modification time.
43
+func (s StatT) Mtim() syscall.Timespec {
44
+	return s.mtim
45
+}
46
+
47
+// Stat takes a path to a file and returns
48
+// a system.StatT type pertaining to that file.
49
+//
50
+// Throws an error if the file does not exist
51
+func Stat(path string) (*StatT, error) {
52
+	s := &syscall.Stat_t{}
53
+	if err := syscall.Stat(path, s); err != nil {
54
+		return nil, err
55
+	}
56
+	return fromStatT(s)
57
+}
0 58
deleted file mode 100644
... ...
@@ -1,17 +0,0 @@
1
-// +build !linux,!windows,!freebsd,!solaris,!openbsd,!darwin
2
-
3
-package system
4
-
5
-import (
6
-	"syscall"
7
-)
8
-
9
-// fromStatT creates a system.StatT type from a syscall.Stat_t type
10
-func fromStatT(s *syscall.Stat_t) (*StatT, error) {
11
-	return &StatT{size: s.Size,
12
-		mode: uint32(s.Mode),
13
-		uid:  s.Uid,
14
-		gid:  s.Gid,
15
-		rdev: uint64(s.Rdev),
16
-		mtim: s.Mtimespec}, nil
17
-}
... ...
@@ -1,5 +1,3 @@
1
-// +build windows
2
-
3 1
 package system
4 2
 
5 3
 import (
... ...
@@ -8,18 +6,11 @@ import (
8 8
 )
9 9
 
10 10
 // StatT type contains status of a file. It contains metadata
11
-// like name, permission, size, etc about a file.
11
+// like permission, size, etc about a file.
12 12
 type StatT struct {
13
-	name    string
14
-	size    int64
15
-	mode    os.FileMode
16
-	modTime time.Time
17
-	isDir   bool
18
-}
19
-
20
-// Name returns file's name.
21
-func (s StatT) Name() string {
22
-	return s.name
13
+	mode os.FileMode
14
+	size int64
15
+	mtim time.Time
23 16
 }
24 17
 
25 18
 // Size returns file's size.
... ...
@@ -29,15 +20,30 @@ func (s StatT) Size() int64 {
29 29
 
30 30
 // Mode returns file's permission mode.
31 31
 func (s StatT) Mode() os.FileMode {
32
-	return s.mode
32
+	return os.FileMode(s.mode)
33
+}
34
+
35
+// Mtim returns file's last modification time.
36
+func (s StatT) Mtim() time.Time {
37
+	return time.Time(s.mtim)
33 38
 }
34 39
 
35
-// ModTime returns file's last modification time.
36
-func (s StatT) ModTime() time.Time {
37
-	return s.modTime
40
+// Stat takes a path to a file and returns
41
+// a system.StatT type pertaining to that file.
42
+//
43
+// Throws an error if the file does not exist
44
+func Stat(path string) (*StatT, error) {
45
+	fi, err := os.Stat(path)
46
+	if err != nil {
47
+		return nil, err
48
+	}
49
+	return fromStatT(&fi)
38 50
 }
39 51
 
40
-// IsDir returns whether file is actually a directory.
41
-func (s StatT) IsDir() bool {
42
-	return s.isDir
52
+// fromStatT converts a os.FileInfo type to a system.StatT type
53
+func fromStatT(fi *os.FileInfo) (*StatT, error) {
54
+	return &StatT{
55
+		size: (*fi).Size(),
56
+		mode: (*fi).Mode(),
57
+		mtim: (*fi).ModTime()}, nil
43 58
 }
44 59
new file mode 100644
... ...
@@ -0,0 +1,74 @@
0
+package term
1
+
2
+import (
3
+	"io"
4
+)
5
+
6
+// EscapeError is special error which returned by a TTY proxy reader's Read()
7
+// method in case its detach escape sequence is read.
8
+type EscapeError struct{}
9
+
10
+func (EscapeError) Error() string {
11
+	return "read escape sequence"
12
+}
13
+
14
+// escapeProxy is used only for attaches with a TTY. It is used to proxy
15
+// stdin keypresses from the underlying reader and look for the passed in
16
+// escape key sequence to signal a detach.
17
+type escapeProxy struct {
18
+	escapeKeys   []byte
19
+	escapeKeyPos int
20
+	r            io.Reader
21
+}
22
+
23
+// NewEscapeProxy returns a new TTY proxy reader which wraps the given reader
24
+// and detects when the specified escape keys are read, in which case the Read
25
+// method will return an error of type EscapeError.
26
+func NewEscapeProxy(r io.Reader, escapeKeys []byte) io.Reader {
27
+	return &escapeProxy{
28
+		escapeKeys: escapeKeys,
29
+		r:          r,
30
+	}
31
+}
32
+
33
+func (r *escapeProxy) Read(buf []byte) (int, error) {
34
+	nr, err := r.r.Read(buf)
35
+
36
+	preserve := func() {
37
+		// this preserves the original key presses in the passed in buffer
38
+		nr += r.escapeKeyPos
39
+		preserve := make([]byte, 0, r.escapeKeyPos+len(buf))
40
+		preserve = append(preserve, r.escapeKeys[:r.escapeKeyPos]...)
41
+		preserve = append(preserve, buf...)
42
+		r.escapeKeyPos = 0
43
+		copy(buf[0:nr], preserve)
44
+	}
45
+
46
+	if nr != 1 || err != nil {
47
+		if r.escapeKeyPos > 0 {
48
+			preserve()
49
+		}
50
+		return nr, err
51
+	}
52
+
53
+	if buf[0] != r.escapeKeys[r.escapeKeyPos] {
54
+		if r.escapeKeyPos > 0 {
55
+			preserve()
56
+		}
57
+		return nr, nil
58
+	}
59
+
60
+	if r.escapeKeyPos == len(r.escapeKeys)-1 {
61
+		return 0, EscapeError{}
62
+	}
63
+
64
+	// Looks like we've got an escape key, but we need to match again on the next
65
+	// read.
66
+	// Store the current escape key we found so we can look for the next one on
67
+	// the next read.
68
+	// Since this is an escape key, make sure we don't let the caller read it
69
+	// If later on we find that this is not the escape sequence, we'll add the
70
+	// keys back
71
+	r.escapeKeyPos++
72
+	return nr - r.escapeKeyPos, nil
73
+}
0 74
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+// +build !windows
1
+// +build !solaris !cgo
2
+
3
+package term
4
+
5
+import (
6
+	"syscall"
7
+	"unsafe"
8
+
9
+	"golang.org/x/sys/unix"
10
+)
11
+
12
+func tcget(fd uintptr, p *Termios) syscall.Errno {
13
+	_, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(p)))
14
+	return err
15
+}
16
+
17
+func tcset(fd uintptr, p *Termios) syscall.Errno {
18
+	_, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(p)))
19
+	return err
20
+}
0 21
deleted file mode 100644
... ...
@@ -1,50 +0,0 @@
1
-// +build linux,cgo
2
-
3
-package term
4
-
5
-import (
6
-	"syscall"
7
-	"unsafe"
8
-)
9
-
10
-// #include <termios.h>
11
-import "C"
12
-
13
-// Termios is the Unix API for terminal I/O.
14
-// It is passthrough for syscall.Termios in order to make it portable with
15
-// other platforms where it is not available or handled differently.
16
-type Termios syscall.Termios
17
-
18
-// MakeRaw put the terminal connected to the given file descriptor into raw
19
-// mode and returns the previous state of the terminal so that it can be
20
-// restored.
21
-func MakeRaw(fd uintptr) (*State, error) {
22
-	var oldState State
23
-	if err := tcget(fd, &oldState.termios); err != 0 {
24
-		return nil, err
25
-	}
26
-
27
-	newState := oldState.termios
28
-
29
-	C.cfmakeraw((*C.struct_termios)(unsafe.Pointer(&newState)))
30
-	if err := tcset(fd, &newState); err != 0 {
31
-		return nil, err
32
-	}
33
-	return &oldState, nil
34
-}
35
-
36
-func tcget(fd uintptr, p *Termios) syscall.Errno {
37
-	ret, err := C.tcgetattr(C.int(fd), (*C.struct_termios)(unsafe.Pointer(p)))
38
-	if ret != 0 {
39
-		return err.(syscall.Errno)
40
-	}
41
-	return 0
42
-}
43
-
44
-func tcset(fd uintptr, p *Termios) syscall.Errno {
45
-	ret, err := C.tcsetattr(C.int(fd), C.TCSANOW, (*C.struct_termios)(unsafe.Pointer(p)))
46
-	if ret != 0 {
47
-		return err.(syscall.Errno)
48
-	}
49
-	return 0
50
-}
51 1
deleted file mode 100644
... ...
@@ -1,20 +0,0 @@
1
-// +build !windows
2
-// +build !linux !cgo
3
-// +build !solaris !cgo
4
-
5
-package term
6
-
7
-import (
8
-	"syscall"
9
-	"unsafe"
10
-)
11
-
12
-func tcget(fd uintptr, p *Termios) syscall.Errno {
13
-	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(p)))
14
-	return err
15
-}
16
-
17
-func tcset(fd uintptr, p *Termios) syscall.Errno {
18
-	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(p)))
19
-	return err
20
-}
... ...
@@ -5,15 +5,17 @@ package term
5 5
 import (
6 6
 	"syscall"
7 7
 	"unsafe"
8
+
9
+	"golang.org/x/sys/unix"
8 10
 )
9 11
 
10 12
 // #include <termios.h>
11 13
 import "C"
12 14
 
13 15
 // Termios is the Unix API for terminal I/O.
14
-// It is passthrough for syscall.Termios in order to make it portable with
16
+// It is passthrough for unix.Termios in order to make it portable with
15 17
 // other platforms where it is not available or handled differently.
16
-type Termios syscall.Termios
18
+type Termios unix.Termios
17 19
 
18 20
 // MakeRaw put the terminal connected to the given file descriptor into raw
19 21
 // mode and returns the previous state of the terminal so that it can be
... ...
@@ -26,11 +28,11 @@ func MakeRaw(fd uintptr) (*State, error) {
26 26
 
27 27
 	newState := oldState.termios
28 28
 
29
-	newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON | syscall.IXANY)
30
-	newState.Oflag &^= syscall.OPOST
31
-	newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN)
32
-	newState.Cflag &^= (syscall.CSIZE | syscall.PARENB)
33
-	newState.Cflag |= syscall.CS8
29
+	newState.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON | unix.IXANY)
30
+	newState.Oflag &^= unix.OPOST
31
+	newState.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)
32
+	newState.Cflag &^= (unix.CSIZE | unix.PARENB)
33
+	newState.Cflag |= unix.CS8
34 34
 
35 35
 	/*
36 36
 		VMIN is the minimum number of characters that needs to be read in non-canonical mode for it to be returned
... ...
@@ -10,7 +10,8 @@ import (
10 10
 	"io"
11 11
 	"os"
12 12
 	"os/signal"
13
-	"syscall"
13
+
14
+	"golang.org/x/sys/unix"
14 15
 )
15 16
 
16 17
 var (
... ...
@@ -31,7 +32,7 @@ type Winsize struct {
31 31
 	y      uint16
32 32
 }
33 33
 
34
-// StdStreams returns the standard streams (stdin, stdout, stedrr).
34
+// StdStreams returns the standard streams (stdin, stdout, stderr).
35 35
 func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
36 36
 	return os.Stdin, os.Stdout, os.Stderr
37 37
 }
... ...
@@ -79,7 +80,7 @@ func SaveState(fd uintptr) (*State, error) {
79 79
 // descriptor, with echo disabled.
80 80
 func DisableEcho(fd uintptr, state *State) error {
81 81
 	newState := state.termios
82
-	newState.Lflag &^= syscall.ECHO
82
+	newState.Lflag &^= unix.ECHO
83 83
 
84 84
 	if err := tcset(fd, &newState); err != 0 {
85 85
 		return err
86 86
deleted file mode 100644
... ...
@@ -1,41 +0,0 @@
1
-// +build solaris
2
-
3
-package term
4
-
5
-import (
6
-	"syscall"
7
-	"unsafe"
8
-)
9
-
10
-/*
11
-#include <unistd.h>
12
-#include <stropts.h>
13
-#include <termios.h>
14
-
15
-// Small wrapper to get rid of variadic args of ioctl()
16
-int my_ioctl(int fd, int cmd, struct winsize *ws) {
17
-	return ioctl(fd, cmd, ws);
18
-}
19
-*/
20
-import "C"
21
-
22
-// GetWinsize returns the window size based on the specified file descriptor.
23
-func GetWinsize(fd uintptr) (*Winsize, error) {
24
-	ws := &Winsize{}
25
-	ret, err := C.my_ioctl(C.int(fd), C.int(syscall.TIOCGWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws)))
26
-	// Skip retval = 0
27
-	if ret == 0 {
28
-		return ws, nil
29
-	}
30
-	return ws, err
31
-}
32
-
33
-// SetWinsize tries to set the specified window size for the specified file descriptor.
34
-func SetWinsize(fd uintptr, ws *Winsize) error {
35
-	ret, err := C.my_ioctl(C.int(fd), C.int(syscall.TIOCSWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws)))
36
-	// Skip retval = 0
37
-	if ret == 0 {
38
-		return nil
39
-	}
40
-	return err
41
-}
42 1
deleted file mode 100644
... ...
@@ -1,29 +0,0 @@
1
-// +build !solaris,!windows
2
-
3
-package term
4
-
5
-import (
6
-	"syscall"
7
-	"unsafe"
8
-)
9
-
10
-// GetWinsize returns the window size based on the specified file descriptor.
11
-func GetWinsize(fd uintptr) (*Winsize, error) {
12
-	ws := &Winsize{}
13
-	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(ws)))
14
-	// Skipp errno = 0
15
-	if err == 0 {
16
-		return ws, nil
17
-	}
18
-	return ws, err
19
-}
20
-
21
-// SetWinsize tries to set the specified window size for the specified file descriptor.
22
-func SetWinsize(fd uintptr, ws *Winsize) error {
23
-	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCSWINSZ), uintptr(unsafe.Pointer(ws)))
24
-	// Skipp errno = 0
25
-	if err == 0 {
26
-		return nil
27
-	}
28
-	return err
29
-}
... ...
@@ -6,10 +6,10 @@ import (
6 6
 	"io"
7 7
 	"os"
8 8
 	"os/signal"
9
-	"syscall"
10 9
 
11 10
 	"github.com/Azure/go-ansiterm/winterm"
12 11
 	"github.com/docker/docker/pkg/term/windows"
12
+	"golang.org/x/sys/windows"
13 13
 )
14 14
 
15 15
 // State holds the console mode for the terminal.
... ...
@@ -33,7 +33,7 @@ const (
33 33
 // vtInputSupported is true if enableVirtualTerminalInput is supported by the console
34 34
 var vtInputSupported bool
35 35
 
36
-// StdStreams returns the standard streams (stdin, stdout, stedrr).
36
+// StdStreams returns the standard streams (stdin, stdout, stderr).
37 37
 func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
38 38
 	// Turn on VT handling on all std handles, if possible. This might
39 39
 	// fail, in which case we will fall back to terminal emulation.
... ...
@@ -79,19 +79,19 @@ func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
79 79
 	}
80 80
 
81 81
 	if emulateStdin {
82
-		stdIn = windows.NewAnsiReader(syscall.STD_INPUT_HANDLE)
82
+		stdIn = windowsconsole.NewAnsiReader(windows.STD_INPUT_HANDLE)
83 83
 	} else {
84 84
 		stdIn = os.Stdin
85 85
 	}
86 86
 
87 87
 	if emulateStdout {
88
-		stdOut = windows.NewAnsiWriter(syscall.STD_OUTPUT_HANDLE)
88
+		stdOut = windowsconsole.NewAnsiWriter(windows.STD_OUTPUT_HANDLE)
89 89
 	} else {
90 90
 		stdOut = os.Stdout
91 91
 	}
92 92
 
93 93
 	if emulateStderr {
94
-		stdErr = windows.NewAnsiWriter(syscall.STD_ERROR_HANDLE)
94
+		stdErr = windowsconsole.NewAnsiWriter(windows.STD_ERROR_HANDLE)
95 95
 	} else {
96 96
 		stdErr = os.Stderr
97 97
 	}
... ...
@@ -101,7 +101,7 @@ func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
101 101
 
102 102
 // GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal.
103 103
 func GetFdInfo(in interface{}) (uintptr, bool) {
104
-	return windows.GetHandleInfo(in)
104
+	return windowsconsole.GetHandleInfo(in)
105 105
 }
106 106
 
107 107
 // GetWinsize returns the window size based on the specified file descriptor.
... ...
@@ -121,7 +121,7 @@ func GetWinsize(fd uintptr) (*Winsize, error) {
121 121
 
122 122
 // IsTerminal returns true if the given file descriptor is a terminal.
123 123
 func IsTerminal(fd uintptr) bool {
124
-	return windows.IsConsole(fd)
124
+	return windowsconsole.IsConsole(fd)
125 125
 }
126 126
 
127 127
 // RestoreTerminal restores the terminal connected to the given file descriptor
128 128
new file mode 100644
... ...
@@ -0,0 +1,42 @@
0
+// +build darwin freebsd openbsd
1
+
2
+package term
3
+
4
+import (
5
+	"unsafe"
6
+
7
+	"golang.org/x/sys/unix"
8
+)
9
+
10
+const (
11
+	getTermios = unix.TIOCGETA
12
+	setTermios = unix.TIOCSETA
13
+)
14
+
15
+// Termios is the Unix API for terminal I/O.
16
+type Termios unix.Termios
17
+
18
+// MakeRaw put the terminal connected to the given file descriptor into raw
19
+// mode and returns the previous state of the terminal so that it can be
20
+// restored.
21
+func MakeRaw(fd uintptr) (*State, error) {
22
+	var oldState State
23
+	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
24
+		return nil, err
25
+	}
26
+
27
+	newState := oldState.termios
28
+	newState.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON)
29
+	newState.Oflag &^= unix.OPOST
30
+	newState.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)
31
+	newState.Cflag &^= (unix.CSIZE | unix.PARENB)
32
+	newState.Cflag |= unix.CS8
33
+	newState.Cc[unix.VMIN] = 1
34
+	newState.Cc[unix.VTIME] = 0
35
+
36
+	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
37
+		return nil, err
38
+	}
39
+
40
+	return &oldState, nil
41
+}
0 42
deleted file mode 100644
... ...
@@ -1,69 +0,0 @@
1
-package term
2
-
3
-import (
4
-	"syscall"
5
-	"unsafe"
6
-)
7
-
8
-const (
9
-	getTermios = syscall.TIOCGETA
10
-	setTermios = syscall.TIOCSETA
11
-)
12
-
13
-// Termios magic numbers, passthrough to the ones defined in syscall.
14
-const (
15
-	IGNBRK = syscall.IGNBRK
16
-	PARMRK = syscall.PARMRK
17
-	INLCR  = syscall.INLCR
18
-	IGNCR  = syscall.IGNCR
19
-	ECHONL = syscall.ECHONL
20
-	CSIZE  = syscall.CSIZE
21
-	ICRNL  = syscall.ICRNL
22
-	ISTRIP = syscall.ISTRIP
23
-	PARENB = syscall.PARENB
24
-	ECHO   = syscall.ECHO
25
-	ICANON = syscall.ICANON
26
-	ISIG   = syscall.ISIG
27
-	IXON   = syscall.IXON
28
-	BRKINT = syscall.BRKINT
29
-	INPCK  = syscall.INPCK
30
-	OPOST  = syscall.OPOST
31
-	CS8    = syscall.CS8
32
-	IEXTEN = syscall.IEXTEN
33
-)
34
-
35
-// Termios is the Unix API for terminal I/O.
36
-type Termios struct {
37
-	Iflag  uint64
38
-	Oflag  uint64
39
-	Cflag  uint64
40
-	Lflag  uint64
41
-	Cc     [20]byte
42
-	Ispeed uint64
43
-	Ospeed uint64
44
-}
45
-
46
-// MakeRaw put the terminal connected to the given file descriptor into raw
47
-// mode and returns the previous state of the terminal so that it can be
48
-// restored.
49
-func MakeRaw(fd uintptr) (*State, error) {
50
-	var oldState State
51
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
52
-		return nil, err
53
-	}
54
-
55
-	newState := oldState.termios
56
-	newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
57
-	newState.Oflag &^= OPOST
58
-	newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
59
-	newState.Cflag &^= (CSIZE | PARENB)
60
-	newState.Cflag |= CS8
61
-	newState.Cc[syscall.VMIN] = 1
62
-	newState.Cc[syscall.VTIME] = 0
63
-
64
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
65
-		return nil, err
66
-	}
67
-
68
-	return &oldState, nil
69
-}
70 1
deleted file mode 100644
... ...
@@ -1,69 +0,0 @@
1
-package term
2
-
3
-import (
4
-	"syscall"
5
-	"unsafe"
6
-)
7
-
8
-const (
9
-	getTermios = syscall.TIOCGETA
10
-	setTermios = syscall.TIOCSETA
11
-)
12
-
13
-// Termios magic numbers, passthrough to the ones defined in syscall.
14
-const (
15
-	IGNBRK = syscall.IGNBRK
16
-	PARMRK = syscall.PARMRK
17
-	INLCR  = syscall.INLCR
18
-	IGNCR  = syscall.IGNCR
19
-	ECHONL = syscall.ECHONL
20
-	CSIZE  = syscall.CSIZE
21
-	ICRNL  = syscall.ICRNL
22
-	ISTRIP = syscall.ISTRIP
23
-	PARENB = syscall.PARENB
24
-	ECHO   = syscall.ECHO
25
-	ICANON = syscall.ICANON
26
-	ISIG   = syscall.ISIG
27
-	IXON   = syscall.IXON
28
-	BRKINT = syscall.BRKINT
29
-	INPCK  = syscall.INPCK
30
-	OPOST  = syscall.OPOST
31
-	CS8    = syscall.CS8
32
-	IEXTEN = syscall.IEXTEN
33
-)
34
-
35
-// Termios is the Unix API for terminal I/O.
36
-type Termios struct {
37
-	Iflag  uint32
38
-	Oflag  uint32
39
-	Cflag  uint32
40
-	Lflag  uint32
41
-	Cc     [20]byte
42
-	Ispeed uint32
43
-	Ospeed uint32
44
-}
45
-
46
-// MakeRaw put the terminal connected to the given file descriptor into raw
47
-// mode and returns the previous state of the terminal so that it can be
48
-// restored.
49
-func MakeRaw(fd uintptr) (*State, error) {
50
-	var oldState State
51
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
52
-		return nil, err
53
-	}
54
-
55
-	newState := oldState.termios
56
-	newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
57
-	newState.Oflag &^= OPOST
58
-	newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
59
-	newState.Cflag &^= (CSIZE | PARENB)
60
-	newState.Cflag |= CS8
61
-	newState.Cc[syscall.VMIN] = 1
62
-	newState.Cc[syscall.VTIME] = 0
63
-
64
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
65
-		return nil, err
66
-	}
67
-
68
-	return &oldState, nil
69
-}
... ...
@@ -1,46 +1,37 @@
1
-// +build !cgo
2
-
3 1
 package term
4 2
 
5 3
 import (
6
-	"syscall"
7 4
 	"unsafe"
5
+
6
+	"golang.org/x/sys/unix"
8 7
 )
9 8
 
10 9
 const (
11
-	getTermios = syscall.TCGETS
12
-	setTermios = syscall.TCSETS
10
+	getTermios = unix.TCGETS
11
+	setTermios = unix.TCSETS
13 12
 )
14 13
 
15 14
 // Termios is the Unix API for terminal I/O.
16
-type Termios struct {
17
-	Iflag  uint32
18
-	Oflag  uint32
19
-	Cflag  uint32
20
-	Lflag  uint32
21
-	Cc     [20]byte
22
-	Ispeed uint32
23
-	Ospeed uint32
24
-}
15
+type Termios unix.Termios
25 16
 
26 17
 // MakeRaw put the terminal connected to the given file descriptor into raw
27 18
 // mode and returns the previous state of the terminal so that it can be
28 19
 // restored.
29 20
 func MakeRaw(fd uintptr) (*State, error) {
30 21
 	var oldState State
31
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
22
+	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
32 23
 		return nil, err
33 24
 	}
34 25
 
35 26
 	newState := oldState.termios
36 27
 
37
-	newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON)
38
-	newState.Oflag &^= syscall.OPOST
39
-	newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN)
40
-	newState.Cflag &^= (syscall.CSIZE | syscall.PARENB)
41
-	newState.Cflag |= syscall.CS8
28
+	newState.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON)
29
+	newState.Oflag |= unix.OPOST
30
+	newState.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)
31
+	newState.Cflag &^= (unix.CSIZE | unix.PARENB)
32
+	newState.Cflag |= unix.CS8
42 33
 
43
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
34
+	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
44 35
 		return nil, err
45 36
 	}
46 37
 	return &oldState, nil
47 38
deleted file mode 100644
... ...
@@ -1,69 +0,0 @@
1
-package term
2
-
3
-import (
4
-	"syscall"
5
-	"unsafe"
6
-)
7
-
8
-const (
9
-	getTermios = syscall.TIOCGETA
10
-	setTermios = syscall.TIOCSETA
11
-)
12
-
13
-// Termios magic numbers, passthrough to the ones defined in syscall.
14
-const (
15
-	IGNBRK = syscall.IGNBRK
16
-	PARMRK = syscall.PARMRK
17
-	INLCR  = syscall.INLCR
18
-	IGNCR  = syscall.IGNCR
19
-	ECHONL = syscall.ECHONL
20
-	CSIZE  = syscall.CSIZE
21
-	ICRNL  = syscall.ICRNL
22
-	ISTRIP = syscall.ISTRIP
23
-	PARENB = syscall.PARENB
24
-	ECHO   = syscall.ECHO
25
-	ICANON = syscall.ICANON
26
-	ISIG   = syscall.ISIG
27
-	IXON   = syscall.IXON
28
-	BRKINT = syscall.BRKINT
29
-	INPCK  = syscall.INPCK
30
-	OPOST  = syscall.OPOST
31
-	CS8    = syscall.CS8
32
-	IEXTEN = syscall.IEXTEN
33
-)
34
-
35
-// Termios is the Unix API for terminal I/O.
36
-type Termios struct {
37
-	Iflag  uint32
38
-	Oflag  uint32
39
-	Cflag  uint32
40
-	Lflag  uint32
41
-	Cc     [20]byte
42
-	Ispeed uint32
43
-	Ospeed uint32
44
-}
45
-
46
-// MakeRaw put the terminal connected to the given file descriptor into raw
47
-// mode and returns the previous state of the terminal so that it can be
48
-// restored.
49
-func MakeRaw(fd uintptr) (*State, error) {
50
-	var oldState State
51
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
52
-		return nil, err
53
-	}
54
-
55
-	newState := oldState.termios
56
-	newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
57
-	newState.Oflag &^= OPOST
58
-	newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
59
-	newState.Cflag &^= (CSIZE | PARENB)
60
-	newState.Cflag |= CS8
61
-	newState.Cc[syscall.VMIN] = 1
62
-	newState.Cc[syscall.VTIME] = 0
63
-
64
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
65
-		return nil, err
66
-	}
67
-
68
-	return &oldState, nil
69
-}
... ...
@@ -1,6 +1,6 @@
1 1
 // +build windows
2 2
 
3
-package windows
3
+package windowsconsole
4 4
 
5 5
 import (
6 6
 	"bytes"
... ...
@@ -1,6 +1,6 @@
1 1
 // +build windows
2 2
 
3
-package windows
3
+package windowsconsole
4 4
 
5 5
 import (
6 6
 	"io"
... ...
@@ -1,6 +1,6 @@
1 1
 // +build windows
2 2
 
3
-package windows
3
+package windowsconsole
4 4
 
5 5
 import (
6 6
 	"os"
... ...
@@ -2,7 +2,7 @@
2 2
 // When asked for the set of standard streams (e.g., stdin, stdout, stderr), the code will create
3 3
 // and return pseudo-streams that convert ANSI sequences to / from Windows Console API calls.
4 4
 
5
-package windows
5
+package windowsconsole
6 6
 
7 7
 import (
8 8
 	"io/ioutil"
9 9
new file mode 100644
... ...
@@ -0,0 +1,30 @@
0
+// +build !solaris,!windows
1
+
2
+package term
3
+
4
+import (
5
+	"unsafe"
6
+
7
+	"golang.org/x/sys/unix"
8
+)
9
+
10
+// GetWinsize returns the window size based on the specified file descriptor.
11
+func GetWinsize(fd uintptr) (*Winsize, error) {
12
+	ws := &Winsize{}
13
+	_, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(unix.TIOCGWINSZ), uintptr(unsafe.Pointer(ws)))
14
+	// Skipp errno = 0
15
+	if err == 0 {
16
+		return ws, nil
17
+	}
18
+	return ws, err
19
+}
20
+
21
+// SetWinsize tries to set the specified window size for the specified file descriptor.
22
+func SetWinsize(fd uintptr, ws *Winsize) error {
23
+	_, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(unix.TIOCSWINSZ), uintptr(unsafe.Pointer(ws)))
24
+	// Skipp errno = 0
25
+	if err == 0 {
26
+		return nil
27
+	}
28
+	return err
29
+}
0 30
new file mode 100644
... ...
@@ -0,0 +1,42 @@
0
+// +build solaris,cgo
1
+
2
+package term
3
+
4
+import (
5
+	"unsafe"
6
+
7
+	"golang.org/x/sys/unix"
8
+)
9
+
10
+/*
11
+#include <unistd.h>
12
+#include <stropts.h>
13
+#include <termios.h>
14
+
15
+// Small wrapper to get rid of variadic args of ioctl()
16
+int my_ioctl(int fd, int cmd, struct winsize *ws) {
17
+	return ioctl(fd, cmd, ws);
18
+}
19
+*/
20
+import "C"
21
+
22
+// GetWinsize returns the window size based on the specified file descriptor.
23
+func GetWinsize(fd uintptr) (*Winsize, error) {
24
+	ws := &Winsize{}
25
+	ret, err := C.my_ioctl(C.int(fd), C.int(unix.TIOCGWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws)))
26
+	// Skip retval = 0
27
+	if ret == 0 {
28
+		return ws, nil
29
+	}
30
+	return ws, err
31
+}
32
+
33
+// SetWinsize tries to set the specified window size for the specified file descriptor.
34
+func SetWinsize(fd uintptr, ws *Winsize) error {
35
+	ret, err := C.my_ioctl(C.int(fd), C.int(unix.TIOCSWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws)))
36
+	// Skip retval = 0
37
+	if ret == 0 {
38
+		return nil
39
+	}
40
+	return err
41
+}
0 42
new file mode 100644
... ...
@@ -0,0 +1,136 @@
0
+# the following lines are in sorted order, FYI
1
+github.com/Azure/go-ansiterm 388960b655244e76e24c75f48631564eaefade62
2
+github.com/Microsoft/hcsshim v0.5.17
3
+github.com/Microsoft/go-winio v0.4.1
4
+github.com/Sirupsen/logrus v0.11.0
5
+github.com/davecgh/go-spew 346938d642f2ec3594ed81d874461961cd0faa76
6
+github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
7
+github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git
8
+github.com/gorilla/context v1.1
9
+github.com/gorilla/mux v1.1
10
+github.com/kr/pty 5cf931ef8f
11
+github.com/mattn/go-shellwords v1.0.3
12
+github.com/tchap/go-patricia v2.2.6
13
+github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
14
+# forked golang.org/x/net package includes a patch for lazy loading trace templates
15
+golang.org/x/net c427ad74c6d7a814201695e9ffde0c5d400a7674
16
+golang.org/x/sys 8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9
17
+github.com/docker/go-units 9e638d38cf6977a37a8ea0078f3ee75a7cdb2dd1
18
+github.com/docker/go-connections e15c02316c12de00874640cd76311849de2aeed5
19
+golang.org/x/text f72d8390a633d5dfb0cc84043294db9f6c935756
20
+github.com/stretchr/testify 4d4bfba8f1d1027c4fdbe371823030df51419987
21
+github.com/pmezard/go-difflib v1.0.0
22
+
23
+github.com/RackSec/srslog 456df3a81436d29ba874f3590eeeee25d666f8a5
24
+github.com/imdario/mergo 0.2.1
25
+golang.org/x/sync de49d9dcd27d4f764488181bea099dfe6179bcf0
26
+
27
+#get libnetwork packages
28
+github.com/docker/libnetwork fd9cf1bc88ac6d54f3d0313da8c2660f128a360b https://github.com/fcrisciani/libnetwork
29
+github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894
30
+github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
31
+github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
32
+github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b
33
+github.com/hashicorp/memberlist v0.1.0
34
+github.com/sean-/seed e2103e2c35297fb7e17febb81e49b312087a2372
35
+github.com/hashicorp/go-sockaddr acd314c5781ea706c710d9ea70069fd2e110d61d
36
+github.com/hashicorp/go-multierror fcdddc395df1ddf4247c69bd436e84cfa0733f7e
37
+github.com/hashicorp/serf 598c54895cc5a7b1a24a398d635e8c0ea0959870
38
+github.com/docker/libkv 1d8431073ae03cdaedb198a89722f3aab6d418ef
39
+github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25
40
+github.com/vishvananda/netlink 1e86b2bee5b6a7d377e4c02bb7f98209d6a7297c
41
+github.com/BurntSushi/toml f706d00e3de6abe700c994cdd545a1a4915af060
42
+github.com/samuel/go-zookeeper d0e0d8e11f318e000a8cc434616d69e329edc374
43
+github.com/deckarep/golang-set ef32fa3046d9f249d399f98ebaf9be944430fd1d
44
+github.com/coreos/etcd ea5389a79f40206170582c1ea076191b8622cb8e https://github.com/aaronlehmann/etcd # for https://github.com/coreos/etcd/pull/7830
45
+github.com/ugorji/go f1f1a805ed361a0e078bb537e4ea78cd37dcf065
46
+github.com/hashicorp/consul v0.5.2
47
+github.com/boltdb/bolt fff57c100f4dea1905678da7e90d92429dff2904
48
+github.com/miekg/dns 75e6e86cc601825c5dbcd4e0c209eab180997cd7
49
+
50
+# get graph and distribution packages
51
+github.com/docker/distribution b38e5838b7b2f2ad48e06ec4b500011976080621
52
+github.com/vbatts/tar-split v0.10.1
53
+github.com/opencontainers/go-digest a6d0ee40d4207ea02364bd3b9e8e77b9159ba1eb
54
+
55
+# get go-zfs packages
56
+github.com/mistifyio/go-zfs 22c9b32c84eb0d0c6f4043b6e90fc94073de92fa
57
+github.com/pborman/uuid v1.0
58
+
59
+google.golang.org/grpc v1.0.4
60
+github.com/miekg/pkcs11 df8ae6ca730422dba20c768ff38ef7d79077a59f
61
+
62
+# When updating, also update RUNC_COMMIT in hack/dockerfile/binaries-commits accordingly
63
+github.com/opencontainers/runc 992a5be178a62e026f4069f443c6164912adbf09
64
+github.com/opencontainers/image-spec f03dbe35d449c54915d235f1a3cf8f585a24babe
65
+github.com/opencontainers/runtime-spec d42f1eb741e6361e858d83fc75aa6893b66292c4 # specs
66
+
67
+github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0
68
+
69
+# libcontainer deps (see src/github.com/opencontainers/runc/Godeps/Godeps.json)
70
+github.com/coreos/go-systemd v4
71
+github.com/godbus/dbus v4.0.0
72
+github.com/syndtr/gocapability 2c00daeb6c3b45114c80ac44119e7b8801fdd852
73
+github.com/golang/protobuf 8ee79997227bf9b34611aee7946ae64735e6fd93
74
+
75
+# gelf logging driver deps
76
+github.com/Graylog2/go-gelf 7029da823dad4ef3a876df61065156acb703b2ea
77
+
78
+github.com/fluent/fluent-logger-golang v1.2.1
79
+# fluent-logger-golang deps
80
+github.com/philhofer/fwd 98c11a7a6ec829d672b03833c3d69a7fae1ca972
81
+github.com/tinylib/msgp 75ee40d2601edf122ef667e2a07d600d4c44490c
82
+
83
+# fsnotify
84
+github.com/fsnotify/fsnotify v1.2.11
85
+
86
+# awslogs deps
87
+github.com/aws/aws-sdk-go v1.4.22
88
+github.com/go-ini/ini 060d7da055ba6ec5ea7a31f116332fe5efa04ce0
89
+github.com/jmespath/go-jmespath 0b12d6b521d83fc7f755e7cfc1b1fbdd35a01a74
90
+
91
+# logentries
92
+github.com/bsphere/le_go 7a984a84b5492ae539b79b62fb4a10afc63c7bcf
93
+
94
+# gcplogs deps
95
+golang.org/x/oauth2 96382aa079b72d8c014eb0c50f6c223d1e6a2de0
96
+google.golang.org/api 3cc2e591b550923a2c5f0ab5a803feda924d5823
97
+cloud.google.com/go 9d965e63e8cceb1b5d7977a202f0fcb8866d6525
98
+github.com/googleapis/gax-go da06d194a00e19ce00d9011a13931c3f6f6887c7
99
+google.golang.org/genproto b3e7c2fb04031add52c4817f53f43757ccbf9c18
100
+
101
+# containerd
102
+github.com/containerd/containerd 3addd840653146c90a254301d6c3a663c7fd6429
103
+github.com/tonistiigi/fifo 1405643975692217d6720f8b54aeee1bf2cd5cf4
104
+
105
+# cluster
106
+github.com/docker/swarmkit 1a3e510517be82d18ac04380b5f71eddf06c2fc0
107
+github.com/gogo/protobuf v0.4
108
+github.com/cloudflare/cfssl 7fb22c8cba7ecaf98e4082d22d65800cf45e042a
109
+github.com/google/certificate-transparency d90e65c3a07988180c5b1ece71791c0b6506826e
110
+golang.org/x/crypto 3fbbcd23f1cb824e69491a5930cfeff09b12f4d2
111
+golang.org/x/time a4bde12657593d5e90d0533a3e4fd95e635124cb
112
+github.com/hashicorp/go-memdb cb9a474f84cc5e41b273b20c6927680b2a8776ad
113
+github.com/hashicorp/go-immutable-radix 8e8ed81f8f0bf1bdd829593fdd5c29922c1ea990
114
+github.com/hashicorp/golang-lru a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4
115
+github.com/coreos/pkg fa29b1d70f0beaddd4c7021607cc3c3be8ce94b8
116
+github.com/pivotal-golang/clock 3fd3c1944c59d9742e1cd333672181cd1a6f9fa0
117
+github.com/prometheus/client_golang 52437c81da6b127a9925d17eb3a382a2e5fd395e
118
+github.com/beorn7/perks 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9
119
+github.com/prometheus/client_model fa8ad6fec33561be4280a8f0514318c79d7f6cb6
120
+github.com/prometheus/common ebdfc6da46522d58825777cf1f90490a5b1ef1d8
121
+github.com/prometheus/procfs abf152e5f3e97f2fafac028d2cc06c1feb87ffa5
122
+github.com/matttproud/golang_protobuf_extensions v1.0.0
123
+github.com/pkg/errors 839d9e913e063e28dfd0e6c7b7512793e0a48be9
124
+github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0
125
+
126
+# cli
127
+github.com/spf13/cobra v1.5.1 https://github.com/dnephin/cobra.git
128
+github.com/spf13/pflag 9ff6c6923cfffbcd502984b8e0c80539a94968b7
129
+github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
130
+github.com/Nvveen/Gotty a8b993ba6abdb0e0c12b0125c603323a71c7790c https://github.com/ijc25/Gotty
131
+
132
+# metrics
133
+github.com/docker/go-metrics d466d4f6fd960e01820085bd7e1a24426ee7ef18
134
+
135
+github.com/opencontainers/selinux v1.0.0-rc1
0 136
new file mode 100644
... ...
@@ -0,0 +1,191 @@
0
+
1
+                                 Apache License
2
+                           Version 2.0, January 2004
3
+                        https://www.apache.org/licenses/
4
+
5
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+   1. Definitions.
8
+
9
+      "License" shall mean the terms and conditions for use, reproduction,
10
+      and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+      "Licensor" shall mean the copyright owner or entity authorized by
13
+      the copyright owner that is granting the License.
14
+
15
+      "Legal Entity" shall mean the union of the acting entity and all
16
+      other entities that control, are controlled by, or are under common
17
+      control with that entity. For the purposes of this definition,
18
+      "control" means (i) the power, direct or indirect, to cause the
19
+      direction or management of such entity, whether by contract or
20
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+      outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+      "You" (or "Your") shall mean an individual or Legal Entity
24
+      exercising permissions granted by this License.
25
+
26
+      "Source" form shall mean the preferred form for making modifications,
27
+      including but not limited to software source code, documentation
28
+      source, and configuration files.
29
+
30
+      "Object" form shall mean any form resulting from mechanical
31
+      transformation or translation of a Source form, including but
32
+      not limited to compiled object code, generated documentation,
33
+      and conversions to other media types.
34
+
35
+      "Work" shall mean the work of authorship, whether in Source or
36
+      Object form, made available under the License, as indicated by a
37
+      copyright notice that is included in or attached to the work
38
+      (an example is provided in the Appendix below).
39
+
40
+      "Derivative Works" shall mean any work, whether in Source or Object
41
+      form, that is based on (or derived from) the Work and for which the
42
+      editorial revisions, annotations, elaborations, or other modifications
43
+      represent, as a whole, an original work of authorship. For the purposes
44
+      of this License, Derivative Works shall not include works that remain
45
+      separable from, or merely link (or bind by name) to the interfaces of,
46
+      the Work and Derivative Works thereof.
47
+
48
+      "Contribution" shall mean any work of authorship, including
49
+      the original version of the Work and any modifications or additions
50
+      to that Work or Derivative Works thereof, that is intentionally
51
+      submitted to Licensor for inclusion in the Work by the copyright owner
52
+      or by an individual or Legal Entity authorized to submit on behalf of
53
+      the copyright owner. For the purposes of this definition, "submitted"
54
+      means any form of electronic, verbal, or written communication sent
55
+      to the Licensor or its representatives, including but not limited to
56
+      communication on electronic mailing lists, source code control systems,
57
+      and issue tracking systems that are managed by, or on behalf of, the
58
+      Licensor for the purpose of discussing and improving the Work, but
59
+      excluding communication that is conspicuously marked or otherwise
60
+      designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+      "Contributor" shall mean Licensor and any individual or Legal Entity
63
+      on behalf of whom a Contribution has been received by Licensor and
64
+      subsequently incorporated within the Work.
65
+
66
+   2. Grant of Copyright License. Subject to the terms and conditions of
67
+      this License, each Contributor hereby grants to You a perpetual,
68
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+      copyright license to reproduce, prepare Derivative Works of,
70
+      publicly display, publicly perform, sublicense, and distribute the
71
+      Work and such Derivative Works in Source or Object form.
72
+
73
+   3. Grant of Patent License. Subject to the terms and conditions of
74
+      this License, each Contributor hereby grants to You a perpetual,
75
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+      (except as stated in this section) patent license to make, have made,
77
+      use, offer to sell, sell, import, and otherwise transfer the Work,
78
+      where such license applies only to those patent claims licensable
79
+      by such Contributor that are necessarily infringed by their
80
+      Contribution(s) alone or by combination of their Contribution(s)
81
+      with the Work to which such Contribution(s) was submitted. If You
82
+      institute patent litigation against any entity (including a
83
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+      or a Contribution incorporated within the Work constitutes direct
85
+      or contributory patent infringement, then any patent licenses
86
+      granted to You under this License for that Work shall terminate
87
+      as of the date such litigation is filed.
88
+
89
+   4. Redistribution. You may reproduce and distribute copies of the
90
+      Work or Derivative Works thereof in any medium, with or without
91
+      modifications, and in Source or Object form, provided that You
92
+      meet the following conditions:
93
+
94
+      (a) You must give any other recipients of the Work or
95
+          Derivative Works a copy of this License; and
96
+
97
+      (b) You must cause any modified files to carry prominent notices
98
+          stating that You changed the files; and
99
+
100
+      (c) You must retain, in the Source form of any Derivative Works
101
+          that You distribute, all copyright, patent, trademark, and
102
+          attribution notices from the Source form of the Work,
103
+          excluding those notices that do not pertain to any part of
104
+          the Derivative Works; and
105
+
106
+      (d) If the Work includes a "NOTICE" text file as part of its
107
+          distribution, then any Derivative Works that You distribute must
108
+          include a readable copy of the attribution notices contained
109
+          within such NOTICE file, excluding those notices that do not
110
+          pertain to any part of the Derivative Works, in at least one
111
+          of the following places: within a NOTICE text file distributed
112
+          as part of the Derivative Works; within the Source form or
113
+          documentation, if provided along with the Derivative Works; or,
114
+          within a display generated by the Derivative Works, if and
115
+          wherever such third-party notices normally appear. The contents
116
+          of the NOTICE file are for informational purposes only and
117
+          do not modify the License. You may add Your own attribution
118
+          notices within Derivative Works that You distribute, alongside
119
+          or as an addendum to the NOTICE text from the Work, provided
120
+          that such additional attribution notices cannot be construed
121
+          as modifying the License.
122
+
123
+      You may add Your own copyright statement to Your modifications and
124
+      may provide additional or different license terms and conditions
125
+      for use, reproduction, or distribution of Your modifications, or
126
+      for any such Derivative Works as a whole, provided Your use,
127
+      reproduction, and distribution of the Work otherwise complies with
128
+      the conditions stated in this License.
129
+
130
+   5. Submission of Contributions. Unless You explicitly state otherwise,
131
+      any Contribution intentionally submitted for inclusion in the Work
132
+      by You to the Licensor shall be under the terms and conditions of
133
+      this License, without any additional terms or conditions.
134
+      Notwithstanding the above, nothing herein shall supersede or modify
135
+      the terms of any separate license agreement you may have executed
136
+      with Licensor regarding such Contributions.
137
+
138
+   6. Trademarks. This License does not grant permission to use the trade
139
+      names, trademarks, service marks, or product names of the Licensor,
140
+      except as required for reasonable and customary use in describing the
141
+      origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+   7. Disclaimer of Warranty. Unless required by applicable law or
144
+      agreed to in writing, Licensor provides the Work (and each
145
+      Contributor provides its Contributions) on an "AS IS" BASIS,
146
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+      implied, including, without limitation, any warranties or conditions
148
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+      PARTICULAR PURPOSE. You are solely responsible for determining the
150
+      appropriateness of using or redistributing the Work and assume any
151
+      risks associated with Your exercise of permissions under this License.
152
+
153
+   8. Limitation of Liability. In no event and under no legal theory,
154
+      whether in tort (including negligence), contract, or otherwise,
155
+      unless required by applicable law (such as deliberate and grossly
156
+      negligent acts) or agreed to in writing, shall any Contributor be
157
+      liable to You for damages, including any direct, indirect, special,
158
+      incidental, or consequential damages of any character arising as a
159
+      result of this License or out of the use or inability to use the
160
+      Work (including but not limited to damages for loss of goodwill,
161
+      work stoppage, computer failure or malfunction, or any and all
162
+      other commercial damages or losses), even if such Contributor
163
+      has been advised of the possibility of such damages.
164
+
165
+   9. Accepting Warranty or Additional Liability. While redistributing
166
+      the Work or Derivative Works thereof, You may choose to offer,
167
+      and charge a fee for, acceptance of support, warranty, indemnity,
168
+      or other liability obligations and/or rights consistent with this
169
+      License. However, in accepting such obligations, You may act only
170
+      on Your own behalf and on Your sole responsibility, not on behalf
171
+      of any other Contributor, and only if You agree to indemnify,
172
+      defend, and hold each Contributor harmless for any liability
173
+      incurred by, or claims asserted against, such Contributor by reason
174
+      of your accepting any such warranty or additional liability.
175
+
176
+   END OF TERMS AND CONDITIONS
177
+
178
+   Copyright 2016 Docker, Inc.
179
+
180
+   Licensed under the Apache License, Version 2.0 (the "License");
181
+   you may not use this file except in compliance with the License.
182
+   You may obtain a copy of the License at
183
+
184
+       https://www.apache.org/licenses/LICENSE-2.0
185
+
186
+   Unless required by applicable law or agreed to in writing, software
187
+   distributed under the License is distributed on an "AS IS" BASIS,
188
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+   See the License for the specific language governing permissions and
190
+   limitations under the License.
0 191
new file mode 100644
... ...
@@ -0,0 +1,425 @@
0
+Attribution-ShareAlike 4.0 International
1
+
2
+=======================================================================
3
+
4
+Creative Commons Corporation ("Creative Commons") is not a law firm and
5
+does not provide legal services or legal advice. Distribution of
6
+Creative Commons public licenses does not create a lawyer-client or
7
+other relationship. Creative Commons makes its licenses and related
8
+information available on an "as-is" basis. Creative Commons gives no
9
+warranties regarding its licenses, any material licensed under their
10
+terms and conditions, or any related information. Creative Commons
11
+disclaims all liability for damages resulting from their use to the
12
+fullest extent possible.
13
+
14
+Using Creative Commons Public Licenses
15
+
16
+Creative Commons public licenses provide a standard set of terms and
17
+conditions that creators and other rights holders may use to share
18
+original works of authorship and other material subject to copyright
19
+and certain other rights specified in the public license below. The
20
+following considerations are for informational purposes only, are not
21
+exhaustive, and do not form part of our licenses.
22
+
23
+     Considerations for licensors: Our public licenses are
24
+     intended for use by those authorized to give the public
25
+     permission to use material in ways otherwise restricted by
26
+     copyright and certain other rights. Our licenses are
27
+     irrevocable. Licensors should read and understand the terms
28
+     and conditions of the license they choose before applying it.
29
+     Licensors should also secure all rights necessary before
30
+     applying our licenses so that the public can reuse the
31
+     material as expected. Licensors should clearly mark any
32
+     material not subject to the license. This includes other CC-
33
+     licensed material, or material used under an exception or
34
+     limitation to copyright. More considerations for licensors:
35
+	wiki.creativecommons.org/Considerations_for_licensors
36
+
37
+     Considerations for the public: By using one of our public
38
+     licenses, a licensor grants the public permission to use the
39
+     licensed material under specified terms and conditions. If
40
+     the licensor's permission is not necessary for any reason--for
41
+     example, because of any applicable exception or limitation to
42
+     copyright--then that use is not regulated by the license. Our
43
+     licenses grant only permissions under copyright and certain
44
+     other rights that a licensor has authority to grant. Use of
45
+     the licensed material may still be restricted for other
46
+     reasons, including because others have copyright or other
47
+     rights in the material. A licensor may make special requests,
48
+     such as asking that all changes be marked or described.
49
+     Although not required by our licenses, you are encouraged to
50
+     respect those requests where reasonable. More_considerations
51
+     for the public:
52
+	wiki.creativecommons.org/Considerations_for_licensees
53
+
54
+=======================================================================
55
+
56
+Creative Commons Attribution-ShareAlike 4.0 International Public
57
+License
58
+
59
+By exercising the Licensed Rights (defined below), You accept and agree
60
+to be bound by the terms and conditions of this Creative Commons
61
+Attribution-ShareAlike 4.0 International Public License ("Public
62
+License"). To the extent this Public License may be interpreted as a
63
+contract, You are granted the Licensed Rights in consideration of Your
64
+acceptance of these terms and conditions, and the Licensor grants You
65
+such rights in consideration of benefits the Licensor receives from
66
+making the Licensed Material available under these terms and
67
+conditions.
68
+
69
+
70
+Section 1 -- Definitions.
71
+
72
+  a. Adapted Material means material subject to Copyright and Similar
73
+     Rights that is derived from or based upon the Licensed Material
74
+     and in which the Licensed Material is translated, altered,
75
+     arranged, transformed, or otherwise modified in a manner requiring
76
+     permission under the Copyright and Similar Rights held by the
77
+     Licensor. For purposes of this Public License, where the Licensed
78
+     Material is a musical work, performance, or sound recording,
79
+     Adapted Material is always produced where the Licensed Material is
80
+     synched in timed relation with a moving image.
81
+
82
+  b. Adapter's License means the license You apply to Your Copyright
83
+     and Similar Rights in Your contributions to Adapted Material in
84
+     accordance with the terms and conditions of this Public License.
85
+
86
+  c. BY-SA Compatible License means a license listed at
87
+     creativecommons.org/compatiblelicenses, approved by Creative
88
+     Commons as essentially the equivalent of this Public License.
89
+
90
+  d. Copyright and Similar Rights means copyright and/or similar rights
91
+     closely related to copyright including, without limitation,
92
+     performance, broadcast, sound recording, and Sui Generis Database
93
+     Rights, without regard to how the rights are labeled or
94
+     categorized. For purposes of this Public License, the rights
95
+     specified in Section 2(b)(1)-(2) are not Copyright and Similar
96
+     Rights.
97
+
98
+  e. Effective Technological Measures means those measures that, in the
99
+     absence of proper authority, may not be circumvented under laws
100
+     fulfilling obligations under Article 11 of the WIPO Copyright
101
+     Treaty adopted on December 20, 1996, and/or similar international
102
+     agreements.
103
+
104
+  f. Exceptions and Limitations means fair use, fair dealing, and/or
105
+     any other exception or limitation to Copyright and Similar Rights
106
+     that applies to Your use of the Licensed Material.
107
+
108
+  g. License Elements means the license attributes listed in the name
109
+     of a Creative Commons Public License. The License Elements of this
110
+     Public License are Attribution and ShareAlike.
111
+
112
+  h. Licensed Material means the artistic or literary work, database,
113
+     or other material to which the Licensor applied this Public
114
+     License.
115
+
116
+  i. Licensed Rights means the rights granted to You subject to the
117
+     terms and conditions of this Public License, which are limited to
118
+     all Copyright and Similar Rights that apply to Your use of the
119
+     Licensed Material and that the Licensor has authority to license.
120
+
121
+  j. Licensor means the individual(s) or entity(ies) granting rights
122
+     under this Public License.
123
+
124
+  k. Share means to provide material to the public by any means or
125
+     process that requires permission under the Licensed Rights, such
126
+     as reproduction, public display, public performance, distribution,
127
+     dissemination, communication, or importation, and to make material
128
+     available to the public including in ways that members of the
129
+     public may access the material from a place and at a time
130
+     individually chosen by them.
131
+
132
+  l. Sui Generis Database Rights means rights other than copyright
133
+     resulting from Directive 96/9/EC of the European Parliament and of
134
+     the Council of 11 March 1996 on the legal protection of databases,
135
+     as amended and/or succeeded, as well as other essentially
136
+     equivalent rights anywhere in the world.
137
+
138
+  m. You means the individual or entity exercising the Licensed Rights
139
+     under this Public License. Your has a corresponding meaning.
140
+
141
+
142
+Section 2 -- Scope.
143
+
144
+  a. License grant.
145
+
146
+       1. Subject to the terms and conditions of this Public License,
147
+          the Licensor hereby grants You a worldwide, royalty-free,
148
+          non-sublicensable, non-exclusive, irrevocable license to
149
+          exercise the Licensed Rights in the Licensed Material to:
150
+
151
+            a. reproduce and Share the Licensed Material, in whole or
152
+               in part; and
153
+
154
+            b. produce, reproduce, and Share Adapted Material.
155
+
156
+       2. Exceptions and Limitations. For the avoidance of doubt, where
157
+          Exceptions and Limitations apply to Your use, this Public
158
+          License does not apply, and You do not need to comply with
159
+          its terms and conditions.
160
+
161
+       3. Term. The term of this Public License is specified in Section
162
+          6(a).
163
+
164
+       4. Media and formats; technical modifications allowed. The
165
+          Licensor authorizes You to exercise the Licensed Rights in
166
+          all media and formats whether now known or hereafter created,
167
+          and to make technical modifications necessary to do so. The
168
+          Licensor waives and/or agrees not to assert any right or
169
+          authority to forbid You from making technical modifications
170
+          necessary to exercise the Licensed Rights, including
171
+          technical modifications necessary to circumvent Effective
172
+          Technological Measures. For purposes of this Public License,
173
+          simply making modifications authorized by this Section 2(a)
174
+          (4) never produces Adapted Material.
175
+
176
+       5. Downstream recipients.
177
+
178
+            a. Offer from the Licensor -- Licensed Material. Every
179
+               recipient of the Licensed Material automatically
180
+               receives an offer from the Licensor to exercise the
181
+               Licensed Rights under the terms and conditions of this
182
+               Public License.
183
+
184
+            b. Additional offer from the Licensor -- Adapted Material.
185
+               Every recipient of Adapted Material from You
186
+               automatically receives an offer from the Licensor to
187
+               exercise the Licensed Rights in the Adapted Material
188
+               under the conditions of the Adapter's License You apply.
189
+
190
+            c. No downstream restrictions. You may not offer or impose
191
+               any additional or different terms or conditions on, or
192
+               apply any Effective Technological Measures to, the
193
+               Licensed Material if doing so restricts exercise of the
194
+               Licensed Rights by any recipient of the Licensed
195
+               Material.
196
+
197
+       6. No endorsement. Nothing in this Public License constitutes or
198
+          may be construed as permission to assert or imply that You
199
+          are, or that Your use of the Licensed Material is, connected
200
+          with, or sponsored, endorsed, or granted official status by,
201
+          the Licensor or others designated to receive attribution as
202
+          provided in Section 3(a)(1)(A)(i).
203
+
204
+  b. Other rights.
205
+
206
+       1. Moral rights, such as the right of integrity, are not
207
+          licensed under this Public License, nor are publicity,
208
+          privacy, and/or other similar personality rights; however, to
209
+          the extent possible, the Licensor waives and/or agrees not to
210
+          assert any such rights held by the Licensor to the limited
211
+          extent necessary to allow You to exercise the Licensed
212
+          Rights, but not otherwise.
213
+
214
+       2. Patent and trademark rights are not licensed under this
215
+          Public License.
216
+
217
+       3. To the extent possible, the Licensor waives any right to
218
+          collect royalties from You for the exercise of the Licensed
219
+          Rights, whether directly or through a collecting society
220
+          under any voluntary or waivable statutory or compulsory
221
+          licensing scheme. In all other cases the Licensor expressly
222
+          reserves any right to collect such royalties.
223
+
224
+
225
+Section 3 -- License Conditions.
226
+
227
+Your exercise of the Licensed Rights is expressly made subject to the
228
+following conditions.
229
+
230
+  a. Attribution.
231
+
232
+       1. If You Share the Licensed Material (including in modified
233
+          form), You must:
234
+
235
+            a. retain the following if it is supplied by the Licensor
236
+               with the Licensed Material:
237
+
238
+                 i. identification of the creator(s) of the Licensed
239
+                    Material and any others designated to receive
240
+                    attribution, in any reasonable manner requested by
241
+                    the Licensor (including by pseudonym if
242
+                    designated);
243
+
244
+                ii. a copyright notice;
245
+
246
+               iii. a notice that refers to this Public License;
247
+
248
+                iv. a notice that refers to the disclaimer of
249
+                    warranties;
250
+
251
+                 v. a URI or hyperlink to the Licensed Material to the
252
+                    extent reasonably practicable;
253
+
254
+            b. indicate if You modified the Licensed Material and
255
+               retain an indication of any previous modifications; and
256
+
257
+            c. indicate the Licensed Material is licensed under this
258
+               Public License, and include the text of, or the URI or
259
+               hyperlink to, this Public License.
260
+
261
+       2. You may satisfy the conditions in Section 3(a)(1) in any
262
+          reasonable manner based on the medium, means, and context in
263
+          which You Share the Licensed Material. For example, it may be
264
+          reasonable to satisfy the conditions by providing a URI or
265
+          hyperlink to a resource that includes the required
266
+          information.
267
+
268
+       3. If requested by the Licensor, You must remove any of the
269
+          information required by Section 3(a)(1)(A) to the extent
270
+          reasonably practicable.
271
+
272
+  b. ShareAlike.
273
+
274
+     In addition to the conditions in Section 3(a), if You Share
275
+     Adapted Material You produce, the following conditions also apply.
276
+
277
+       1. The Adapter's License You apply must be a Creative Commons
278
+          license with the same License Elements, this version or
279
+          later, or a BY-SA Compatible License.
280
+
281
+       2. You must include the text of, or the URI or hyperlink to, the
282
+          Adapter's License You apply. You may satisfy this condition
283
+          in any reasonable manner based on the medium, means, and
284
+          context in which You Share Adapted Material.
285
+
286
+       3. You may not offer or impose any additional or different terms
287
+          or conditions on, or apply any Effective Technological
288
+          Measures to, Adapted Material that restrict exercise of the
289
+          rights granted under the Adapter's License You apply.
290
+
291
+
292
+Section 4 -- Sui Generis Database Rights.
293
+
294
+Where the Licensed Rights include Sui Generis Database Rights that
295
+apply to Your use of the Licensed Material:
296
+
297
+  a. for the avoidance of doubt, Section 2(a)(1) grants You the right
298
+     to extract, reuse, reproduce, and Share all or a substantial
299
+     portion of the contents of the database;
300
+
301
+  b. if You include all or a substantial portion of the database
302
+     contents in a database in which You have Sui Generis Database
303
+     Rights, then the database in which You have Sui Generis Database
304
+     Rights (but not its individual contents) is Adapted Material,
305
+
306
+     including for purposes of Section 3(b); and
307
+  c. You must comply with the conditions in Section 3(a) if You Share
308
+     all or a substantial portion of the contents of the database.
309
+
310
+For the avoidance of doubt, this Section 4 supplements and does not
311
+replace Your obligations under this Public License where the Licensed
312
+Rights include other Copyright and Similar Rights.
313
+
314
+
315
+Section 5 -- Disclaimer of Warranties and Limitation of Liability.
316
+
317
+  a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
318
+     EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
319
+     AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
320
+     ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
321
+     IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
322
+     WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
323
+     PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
324
+     ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
325
+     KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
326
+     ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
327
+
328
+  b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
329
+     TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
330
+     NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
331
+     INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
332
+     COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
333
+     USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
334
+     ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
335
+     DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
336
+     IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
337
+
338
+  c. The disclaimer of warranties and limitation of liability provided
339
+     above shall be interpreted in a manner that, to the extent
340
+     possible, most closely approximates an absolute disclaimer and
341
+     waiver of all liability.
342
+
343
+
344
+Section 6 -- Term and Termination.
345
+
346
+  a. This Public License applies for the term of the Copyright and
347
+     Similar Rights licensed here. However, if You fail to comply with
348
+     this Public License, then Your rights under this Public License
349
+     terminate automatically.
350
+
351
+  b. Where Your right to use the Licensed Material has terminated under
352
+     Section 6(a), it reinstates:
353
+
354
+       1. automatically as of the date the violation is cured, provided
355
+          it is cured within 30 days of Your discovery of the
356
+          violation; or
357
+
358
+       2. upon express reinstatement by the Licensor.
359
+
360
+     For the avoidance of doubt, this Section 6(b) does not affect any
361
+     right the Licensor may have to seek remedies for Your violations
362
+     of this Public License.
363
+
364
+  c. For the avoidance of doubt, the Licensor may also offer the
365
+     Licensed Material under separate terms or conditions or stop
366
+     distributing the Licensed Material at any time; however, doing so
367
+     will not terminate this Public License.
368
+
369
+  d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
370
+     License.
371
+
372
+
373
+Section 7 -- Other Terms and Conditions.
374
+
375
+  a. The Licensor shall not be bound by any additional or different
376
+     terms or conditions communicated by You unless expressly agreed.
377
+
378
+  b. Any arrangements, understandings, or agreements regarding the
379
+     Licensed Material not stated herein are separate from and
380
+     independent of the terms and conditions of this Public License.
381
+
382
+
383
+Section 8 -- Interpretation.
384
+
385
+  a. For the avoidance of doubt, this Public License does not, and
386
+     shall not be interpreted to, reduce, limit, restrict, or impose
387
+     conditions on any use of the Licensed Material that could lawfully
388
+     be made without permission under this Public License.
389
+
390
+  b. To the extent possible, if any provision of this Public License is
391
+     deemed unenforceable, it shall be automatically reformed to the
392
+     minimum extent necessary to make it enforceable. If the provision
393
+     cannot be reformed, it shall be severed from this Public License
394
+     without affecting the enforceability of the remaining terms and
395
+     conditions.
396
+
397
+  c. No term or condition of this Public License will be waived and no
398
+     failure to comply consented to unless expressly agreed to by the
399
+     Licensor.
400
+
401
+  d. Nothing in this Public License constitutes or may be interpreted
402
+     as a limitation upon, or waiver of, any privileges and immunities
403
+     that apply to the Licensor or You, including from the legal
404
+     processes of any jurisdiction or authority.
405
+
406
+
407
+=======================================================================
408
+
409
+Creative Commons is not a party to its public licenses.
410
+Notwithstanding, Creative Commons may elect to apply one of its public
411
+licenses to material it publishes and in those instances will be
412
+considered the "Licensor." Except for the limited purpose of indicating
413
+that material is shared under a Creative Commons public license or as
414
+otherwise permitted by the Creative Commons policies published at
415
+creativecommons.org/policies, Creative Commons does not authorize the
416
+use of the trademark "Creative Commons" or any other trademark or logo
417
+of Creative Commons without its prior written consent including,
418
+without limitation, in connection with any unauthorized modifications
419
+to any of its public licenses or any other arrangements,
420
+understandings, or agreements concerning use of licensed material. For
421
+the avoidance of doubt, this paragraph does not form part of the public
422
+licenses.
423
+
424
+Creative Commons may be contacted at creativecommons.org.
0 425
new file mode 100644
... ...
@@ -0,0 +1,104 @@
0
+# go-digest
1
+
2
+[![GoDoc](https://godoc.org/github.com/opencontainers/go-digest?status.svg)](https://godoc.org/github.com/opencontainers/go-digest) [![Go Report Card](https://goreportcard.com/badge/github.com/opencontainers/go-digest)](https://goreportcard.com/report/github.com/opencontainers/go-digest) [![Build Status](https://travis-ci.org/opencontainers/go-digest.svg?branch=master)](https://travis-ci.org/opencontainers/go-digest)
3
+
4
+Common digest package used across the container ecosystem.
5
+
6
+Please see the [godoc](https://godoc.org/github.com/opencontainers/go-digest) for more information.
7
+
8
+# What is a digest?
9
+
10
+A digest is just a hash.
11
+
12
+The most common use case for a digest is to create a content
13
+identifier for use in [Content Addressable Storage](https://en.wikipedia.org/wiki/Content-addressable_storage)
14
+systems:
15
+
16
+```go
17
+id := digest.FromBytes([]byte("my content"))
18
+```
19
+
20
+In the example above, the id can be used to uniquely identify 
21
+the byte slice "my content". This allows two disparate applications
22
+to agree on a verifiable identifier without having to trust one
23
+another.
24
+
25
+An identifying digest can be verified, as follows:
26
+
27
+```go
28
+if id != digest.FromBytes([]byte("my content")) {
29
+  return errors.New("the content has changed!")
30
+}
31
+```
32
+
33
+A `Verifier` type can be used to handle cases where an `io.Reader`
34
+makes more sense:
35
+
36
+```go
37
+rd := getContent()
38
+verifier := id.Verifier()
39
+io.Copy(verifier, rd)
40
+
41
+if !verifier.Verified() {
42
+  return errors.New("the content has changed!")
43
+}
44
+```
45
+
46
+Using [Merkle DAGs](https://en.wikipedia.org/wiki/Merkle_tree), this
47
+can power a rich, safe, content distribution system.
48
+
49
+# Usage
50
+
51
+While the [godoc](https://godoc.org/github.com/opencontainers/go-digest) is
52
+considered the best resource, a few important items need to be called 
53
+out when using this package.
54
+
55
+1. Make sure to import the hash implementations into your application
56
+    or the package will panic. You should have something like the 
57
+    following in the main (or other entrypoint) of your application:
58
+   
59
+    ```go
60
+    import (
61
+        _ "crypto/sha256"
62
+   	    _ "crypto/sha512"
63
+    )
64
+    ```
65
+    This may seem inconvenient but it allows you replace the hash 
66
+    implementations with others, such as https://github.com/stevvooe/resumable.
67
+ 
68
+2. Even though `digest.Digest` may be assemable as a string, _always_ 
69
+    verify your input with `digest.Parse` or use `Digest.Validate`
70
+    when accepting untrusted input. While there are measures to 
71
+    avoid common problems, this will ensure you have valid digests
72
+    in the rest of your application.
73
+
74
+# Stability
75
+
76
+The Go API, at this stage, is considered stable, unless otherwise noted.
77
+
78
+As always, before using a package export, read the [godoc](https://godoc.org/github.com/opencontainers/go-digest).
79
+
80
+# Contributing
81
+
82
+This package is considered fairly complete. It has been in production
83
+in thousands (millions?) of deployments and is fairly battle-hardened.
84
+New additions will be met with skepticism. If you think there is a 
85
+missing feature, please file a bug clearly describing the problem and 
86
+the alternatives you tried before submitting a PR.
87
+
88
+# Reporting security issues
89
+
90
+Please DO NOT file a public issue, instead send your report privately to
91
+security@opencontainers.org.
92
+
93
+The maintainers take security seriously. If you discover a security issue,
94
+please bring it to their attention right away!
95
+
96
+If you are reporting a security issue, do not create an issue or file a pull
97
+request on GitHub. Instead, disclose the issue responsibly by sending an email
98
+to security@opencontainers.org (which is inhabited only by the maintainers of
99
+the various OCI projects).
100
+
101
+# Copyright and license
102
+
103
+Copyright © 2016 Docker, Inc. All rights reserved, except as follows. Code is released under the [Apache 2.0 license](LICENSE.code). This `README.md` file and the [`CONTRIBUTING.md`](CONTRIBUTING.md) file are licensed under the Creative Commons Attribution 4.0 International License under the terms and conditions set forth in the file [`LICENSE.docs`](LICENSE.docs). You may obtain a duplicate copy of the same license, titled CC BY-SA 4.0, at http://creativecommons.org/licenses/by-sa/4.0/.
0 104
new file mode 100644
... ...
@@ -0,0 +1,166 @@
0
+// Copyright 2017 Docker, Inc.
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     https://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package digest
15
+
16
+import (
17
+	"crypto"
18
+	"fmt"
19
+	"hash"
20
+	"io"
21
+)
22
+
23
+// Algorithm identifies and implementation of a digester by an identifier.
24
+// Note the that this defines both the hash algorithm used and the string
25
+// encoding.
26
+type Algorithm string
27
+
28
+// supported digest types
29
+const (
30
+	SHA256 Algorithm = "sha256" // sha256 with hex encoding
31
+	SHA384 Algorithm = "sha384" // sha384 with hex encoding
32
+	SHA512 Algorithm = "sha512" // sha512 with hex encoding
33
+
34
+	// Canonical is the primary digest algorithm used with the distribution
35
+	// project. Other digests may be used but this one is the primary storage
36
+	// digest.
37
+	Canonical = SHA256
38
+)
39
+
40
+var (
41
+	// TODO(stevvooe): Follow the pattern of the standard crypto package for
42
+	// registration of digests. Effectively, we are a registerable set and
43
+	// common symbol access.
44
+
45
+	// algorithms maps values to hash.Hash implementations. Other algorithms
46
+	// may be available but they cannot be calculated by the digest package.
47
+	algorithms = map[Algorithm]crypto.Hash{
48
+		SHA256: crypto.SHA256,
49
+		SHA384: crypto.SHA384,
50
+		SHA512: crypto.SHA512,
51
+	}
52
+)
53
+
54
+// Available returns true if the digest type is available for use. If this
55
+// returns false, Digester and Hash will return nil.
56
+func (a Algorithm) Available() bool {
57
+	h, ok := algorithms[a]
58
+	if !ok {
59
+		return false
60
+	}
61
+
62
+	// check availability of the hash, as well
63
+	return h.Available()
64
+}
65
+
66
+func (a Algorithm) String() string {
67
+	return string(a)
68
+}
69
+
70
+// Size returns number of bytes returned by the hash.
71
+func (a Algorithm) Size() int {
72
+	h, ok := algorithms[a]
73
+	if !ok {
74
+		return 0
75
+	}
76
+	return h.Size()
77
+}
78
+
79
+// Set implemented to allow use of Algorithm as a command line flag.
80
+func (a *Algorithm) Set(value string) error {
81
+	if value == "" {
82
+		*a = Canonical
83
+	} else {
84
+		// just do a type conversion, support is queried with Available.
85
+		*a = Algorithm(value)
86
+	}
87
+
88
+	if !a.Available() {
89
+		return ErrDigestUnsupported
90
+	}
91
+
92
+	return nil
93
+}
94
+
95
+// Digester returns a new digester for the specified algorithm. If the algorithm
96
+// does not have a digester implementation, nil will be returned. This can be
97
+// checked by calling Available before calling Digester.
98
+func (a Algorithm) Digester() Digester {
99
+	return &digester{
100
+		alg:  a,
101
+		hash: a.Hash(),
102
+	}
103
+}
104
+
105
+// Hash returns a new hash as used by the algorithm. If not available, the
106
+// method will panic. Check Algorithm.Available() before calling.
107
+func (a Algorithm) Hash() hash.Hash {
108
+	if !a.Available() {
109
+		// Empty algorithm string is invalid
110
+		if a == "" {
111
+			panic(fmt.Sprintf("empty digest algorithm, validate before calling Algorithm.Hash()"))
112
+		}
113
+
114
+		// NOTE(stevvooe): A missing hash is usually a programming error that
115
+		// must be resolved at compile time. We don't import in the digest
116
+		// package to allow users to choose their hash implementation (such as
117
+		// when using stevvooe/resumable or a hardware accelerated package).
118
+		//
119
+		// Applications that may want to resolve the hash at runtime should
120
+		// call Algorithm.Available before call Algorithm.Hash().
121
+		panic(fmt.Sprintf("%v not available (make sure it is imported)", a))
122
+	}
123
+
124
+	return algorithms[a].New()
125
+}
126
+
127
+// Encode encodes the raw bytes of a digest, typically from a hash.Hash, into
128
+// the encoded portion of the digest.
129
+func (a Algorithm) Encode(d []byte) string {
130
+	// TODO(stevvooe): Currently, all algorithms use a hex encoding. When we
131
+	// add support for back registration, we can modify this accordingly.
132
+	return fmt.Sprintf("%x", d)
133
+}
134
+
135
+// FromReader returns the digest of the reader using the algorithm.
136
+func (a Algorithm) FromReader(rd io.Reader) (Digest, error) {
137
+	digester := a.Digester()
138
+
139
+	if _, err := io.Copy(digester.Hash(), rd); err != nil {
140
+		return "", err
141
+	}
142
+
143
+	return digester.Digest(), nil
144
+}
145
+
146
+// FromBytes digests the input and returns a Digest.
147
+func (a Algorithm) FromBytes(p []byte) Digest {
148
+	digester := a.Digester()
149
+
150
+	if _, err := digester.Hash().Write(p); err != nil {
151
+		// Writes to a Hash should never fail. None of the existing
152
+		// hash implementations in the stdlib or hashes vendored
153
+		// here can return errors from Write. Having a panic in this
154
+		// condition instead of having FromBytes return an error value
155
+		// avoids unnecessary error handling paths in all callers.
156
+		panic("write to hash function returned error: " + err.Error())
157
+	}
158
+
159
+	return digester.Digest()
160
+}
161
+
162
+// FromString digests the string input and returns a Digest.
163
+func (a Algorithm) FromString(s string) Digest {
164
+	return a.FromBytes([]byte(s))
165
+}
0 166
new file mode 100644
... ...
@@ -0,0 +1,164 @@
0
+// Copyright 2017 Docker, Inc.
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     https://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package digest
15
+
16
+import (
17
+	"fmt"
18
+	"hash"
19
+	"io"
20
+	"regexp"
21
+	"strings"
22
+)
23
+
24
+// Digest allows simple protection of hex formatted digest strings, prefixed
25
+// by their algorithm. Strings of type Digest have some guarantee of being in
26
+// the correct format and it provides quick access to the components of a
27
+// digest string.
28
+//
29
+// The following is an example of the contents of Digest types:
30
+//
31
+// 	sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc
32
+//
33
+// This allows to abstract the digest behind this type and work only in those
34
+// terms.
35
+type Digest string
36
+
37
+// NewDigest returns a Digest from alg and a hash.Hash object.
38
+func NewDigest(alg Algorithm, h hash.Hash) Digest {
39
+	return NewDigestFromBytes(alg, h.Sum(nil))
40
+}
41
+
42
+// NewDigestFromBytes returns a new digest from the byte contents of p.
43
+// Typically, this can come from hash.Hash.Sum(...) or xxx.SumXXX(...)
44
+// functions. This is also useful for rebuilding digests from binary
45
+// serializations.
46
+func NewDigestFromBytes(alg Algorithm, p []byte) Digest {
47
+	return NewDigestFromEncoded(alg, alg.Encode(p))
48
+}
49
+
50
+// NewDigestFromHex is deprecated. Please use NewDigestFromEncoded.
51
+func NewDigestFromHex(alg, hex string) Digest {
52
+	return NewDigestFromEncoded(Algorithm(alg), hex)
53
+}
54
+
55
+// NewDigestFromEncoded returns a Digest from alg and the encoded digest.
56
+func NewDigestFromEncoded(alg Algorithm, encoded string) Digest {
57
+	return Digest(fmt.Sprintf("%s:%s", alg, encoded))
58
+}
59
+
60
+// DigestRegexp matches valid digest types.
61
+var DigestRegexp = regexp.MustCompile(`[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[a-zA-Z0-9=_-]+`)
62
+
63
+// DigestRegexpAnchored matches valid digest types, anchored to the start and end of the match.
64
+var DigestRegexpAnchored = regexp.MustCompile(`^` + DigestRegexp.String() + `$`)
65
+
66
+var (
67
+	// ErrDigestInvalidFormat returned when digest format invalid.
68
+	ErrDigestInvalidFormat = fmt.Errorf("invalid checksum digest format")
69
+
70
+	// ErrDigestInvalidLength returned when digest has invalid length.
71
+	ErrDigestInvalidLength = fmt.Errorf("invalid checksum digest length")
72
+
73
+	// ErrDigestUnsupported returned when the digest algorithm is unsupported.
74
+	ErrDigestUnsupported = fmt.Errorf("unsupported digest algorithm")
75
+)
76
+
77
+// Parse parses s and returns the validated digest object. An error will
78
+// be returned if the format is invalid.
79
+func Parse(s string) (Digest, error) {
80
+	d := Digest(s)
81
+	return d, d.Validate()
82
+}
83
+
84
+// FromReader consumes the content of rd until io.EOF, returning canonical digest.
85
+func FromReader(rd io.Reader) (Digest, error) {
86
+	return Canonical.FromReader(rd)
87
+}
88
+
89
+// FromBytes digests the input and returns a Digest.
90
+func FromBytes(p []byte) Digest {
91
+	return Canonical.FromBytes(p)
92
+}
93
+
94
+// FromString digests the input and returns a Digest.
95
+func FromString(s string) Digest {
96
+	return Canonical.FromString(s)
97
+}
98
+
99
+// Validate checks that the contents of d is a valid digest, returning an
100
+// error if not.
101
+func (d Digest) Validate() error {
102
+	s := string(d)
103
+
104
+	i := strings.Index(s, ":")
105
+
106
+	// validate i then run through regexp
107
+	if i < 0 || i+1 == len(s) || !DigestRegexpAnchored.MatchString(s) {
108
+		return ErrDigestInvalidFormat
109
+	}
110
+
111
+	algorithm := Algorithm(s[:i])
112
+	if !algorithm.Available() {
113
+		return ErrDigestUnsupported
114
+	}
115
+
116
+	// Digests much always be hex-encoded, ensuring that their hex portion will
117
+	// always be size*2
118
+	if algorithm.Size()*2 != len(s[i+1:]) {
119
+		return ErrDigestInvalidLength
120
+	}
121
+
122
+	return nil
123
+}
124
+
125
+// Algorithm returns the algorithm portion of the digest. This will panic if
126
+// the underlying digest is not in a valid format.
127
+func (d Digest) Algorithm() Algorithm {
128
+	return Algorithm(d[:d.sepIndex()])
129
+}
130
+
131
+// Verifier returns a writer object that can be used to verify a stream of
132
+// content against the digest. If the digest is invalid, the method will panic.
133
+func (d Digest) Verifier() Verifier {
134
+	return hashVerifier{
135
+		hash:   d.Algorithm().Hash(),
136
+		digest: d,
137
+	}
138
+}
139
+
140
+// Encoded returns the encoded portion of the digest. This will panic if the
141
+// underlying digest is not in a valid format.
142
+func (d Digest) Encoded() string {
143
+	return string(d[d.sepIndex()+1:])
144
+}
145
+
146
+// Hex is deprecated. Please use Digest.Encoded.
147
+func (d Digest) Hex() string {
148
+	return d.Encoded()
149
+}
150
+
151
+func (d Digest) String() string {
152
+	return string(d)
153
+}
154
+
155
+func (d Digest) sepIndex() int {
156
+	i := strings.Index(string(d), ":")
157
+
158
+	if i < 0 {
159
+		panic(fmt.Sprintf("no ':' separator in digest %q", d))
160
+	}
161
+
162
+	return i
163
+}
0 164
new file mode 100644
... ...
@@ -0,0 +1,39 @@
0
+// Copyright 2017 Docker, Inc.
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     https://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package digest
15
+
16
+import "hash"
17
+
18
+// Digester calculates the digest of written data. Writes should go directly
19
+// to the return value of Hash, while calling Digest will return the current
20
+// value of the digest.
21
+type Digester interface {
22
+	Hash() hash.Hash // provides direct access to underlying hash instance.
23
+	Digest() Digest
24
+}
25
+
26
+// digester provides a simple digester definition that embeds a hasher.
27
+type digester struct {
28
+	alg  Algorithm
29
+	hash hash.Hash
30
+}
31
+
32
+func (d *digester) Hash() hash.Hash {
33
+	return d.hash
34
+}
35
+
36
+func (d *digester) Digest() Digest {
37
+	return NewDigest(d.alg, d.hash)
38
+}
0 39
new file mode 100644
... ...
@@ -0,0 +1,56 @@
0
+// Copyright 2017 Docker, Inc.
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     https://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+// Package digest provides a generalized type to opaquely represent message
15
+// digests and their operations within the registry. The Digest type is
16
+// designed to serve as a flexible identifier in a content-addressable system.
17
+// More importantly, it provides tools and wrappers to work with
18
+// hash.Hash-based digests with little effort.
19
+//
20
+// Basics
21
+//
22
+// The format of a digest is simply a string with two parts, dubbed the
23
+// "algorithm" and the "digest", separated by a colon:
24
+//
25
+// 	<algorithm>:<digest>
26
+//
27
+// An example of a sha256 digest representation follows:
28
+//
29
+// 	sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc
30
+//
31
+// In this case, the string "sha256" is the algorithm and the hex bytes are
32
+// the "digest".
33
+//
34
+// Because the Digest type is simply a string, once a valid Digest is
35
+// obtained, comparisons are cheap, quick and simple to express with the
36
+// standard equality operator.
37
+//
38
+// Verification
39
+//
40
+// The main benefit of using the Digest type is simple verification against a
41
+// given digest. The Verifier interface, modeled after the stdlib hash.Hash
42
+// interface, provides a common write sink for digest verification. After
43
+// writing is complete, calling the Verifier.Verified method will indicate
44
+// whether or not the stream of bytes matches the target digest.
45
+//
46
+// Missing Features
47
+//
48
+// In addition to the above, we intend to add the following features to this
49
+// package:
50
+//
51
+// 1. A Digester type that supports write sink digest calculation.
52
+//
53
+// 2. Suspend and resume of ongoing digest calculations to support efficient digest verification in the registry.
54
+//
55
+package digest
0 56
new file mode 100644
... ...
@@ -0,0 +1,45 @@
0
+// Copyright 2017 Docker, Inc.
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     https://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package digest
15
+
16
+import (
17
+	"hash"
18
+	"io"
19
+)
20
+
21
+// Verifier presents a general verification interface to be used with message
22
+// digests and other byte stream verifications. Users instantiate a Verifier
23
+// from one of the various methods, write the data under test to it then check
24
+// the result with the Verified method.
25
+type Verifier interface {
26
+	io.Writer
27
+
28
+	// Verified will return true if the content written to Verifier matches
29
+	// the digest.
30
+	Verified() bool
31
+}
32
+
33
+type hashVerifier struct {
34
+	digest Digest
35
+	hash   hash.Hash
36
+}
37
+
38
+func (hv hashVerifier) Write(p []byte) (n int, err error) {
39
+	return hv.hash.Write(p)
40
+}
41
+
42
+func (hv hashVerifier) Verified() bool {
43
+	return hv.digest == NewDigest(hv.digest.Algorithm(), hv.hash)
44
+}
0 45
new file mode 100644
... ...
@@ -0,0 +1,191 @@
0
+
1
+                                 Apache License
2
+                           Version 2.0, January 2004
3
+                        http://www.apache.org/licenses/
4
+
5
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+   1. Definitions.
8
+
9
+      "License" shall mean the terms and conditions for use, reproduction,
10
+      and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+      "Licensor" shall mean the copyright owner or entity authorized by
13
+      the copyright owner that is granting the License.
14
+
15
+      "Legal Entity" shall mean the union of the acting entity and all
16
+      other entities that control, are controlled by, or are under common
17
+      control with that entity. For the purposes of this definition,
18
+      "control" means (i) the power, direct or indirect, to cause the
19
+      direction or management of such entity, whether by contract or
20
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+      outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+      "You" (or "Your") shall mean an individual or Legal Entity
24
+      exercising permissions granted by this License.
25
+
26
+      "Source" form shall mean the preferred form for making modifications,
27
+      including but not limited to software source code, documentation
28
+      source, and configuration files.
29
+
30
+      "Object" form shall mean any form resulting from mechanical
31
+      transformation or translation of a Source form, including but
32
+      not limited to compiled object code, generated documentation,
33
+      and conversions to other media types.
34
+
35
+      "Work" shall mean the work of authorship, whether in Source or
36
+      Object form, made available under the License, as indicated by a
37
+      copyright notice that is included in or attached to the work
38
+      (an example is provided in the Appendix below).
39
+
40
+      "Derivative Works" shall mean any work, whether in Source or Object
41
+      form, that is based on (or derived from) the Work and for which the
42
+      editorial revisions, annotations, elaborations, or other modifications
43
+      represent, as a whole, an original work of authorship. For the purposes
44
+      of this License, Derivative Works shall not include works that remain
45
+      separable from, or merely link (or bind by name) to the interfaces of,
46
+      the Work and Derivative Works thereof.
47
+
48
+      "Contribution" shall mean any work of authorship, including
49
+      the original version of the Work and any modifications or additions
50
+      to that Work or Derivative Works thereof, that is intentionally
51
+      submitted to Licensor for inclusion in the Work by the copyright owner
52
+      or by an individual or Legal Entity authorized to submit on behalf of
53
+      the copyright owner. For the purposes of this definition, "submitted"
54
+      means any form of electronic, verbal, or written communication sent
55
+      to the Licensor or its representatives, including but not limited to
56
+      communication on electronic mailing lists, source code control systems,
57
+      and issue tracking systems that are managed by, or on behalf of, the
58
+      Licensor for the purpose of discussing and improving the Work, but
59
+      excluding communication that is conspicuously marked or otherwise
60
+      designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+      "Contributor" shall mean Licensor and any individual or Legal Entity
63
+      on behalf of whom a Contribution has been received by Licensor and
64
+      subsequently incorporated within the Work.
65
+
66
+   2. Grant of Copyright License. Subject to the terms and conditions of
67
+      this License, each Contributor hereby grants to You a perpetual,
68
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+      copyright license to reproduce, prepare Derivative Works of,
70
+      publicly display, publicly perform, sublicense, and distribute the
71
+      Work and such Derivative Works in Source or Object form.
72
+
73
+   3. Grant of Patent License. Subject to the terms and conditions of
74
+      this License, each Contributor hereby grants to You a perpetual,
75
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+      (except as stated in this section) patent license to make, have made,
77
+      use, offer to sell, sell, import, and otherwise transfer the Work,
78
+      where such license applies only to those patent claims licensable
79
+      by such Contributor that are necessarily infringed by their
80
+      Contribution(s) alone or by combination of their Contribution(s)
81
+      with the Work to which such Contribution(s) was submitted. If You
82
+      institute patent litigation against any entity (including a
83
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+      or a Contribution incorporated within the Work constitutes direct
85
+      or contributory patent infringement, then any patent licenses
86
+      granted to You under this License for that Work shall terminate
87
+      as of the date such litigation is filed.
88
+
89
+   4. Redistribution. You may reproduce and distribute copies of the
90
+      Work or Derivative Works thereof in any medium, with or without
91
+      modifications, and in Source or Object form, provided that You
92
+      meet the following conditions:
93
+
94
+      (a) You must give any other recipients of the Work or
95
+          Derivative Works a copy of this License; and
96
+
97
+      (b) You must cause any modified files to carry prominent notices
98
+          stating that You changed the files; and
99
+
100
+      (c) You must retain, in the Source form of any Derivative Works
101
+          that You distribute, all copyright, patent, trademark, and
102
+          attribution notices from the Source form of the Work,
103
+          excluding those notices that do not pertain to any part of
104
+          the Derivative Works; and
105
+
106
+      (d) If the Work includes a "NOTICE" text file as part of its
107
+          distribution, then any Derivative Works that You distribute must
108
+          include a readable copy of the attribution notices contained
109
+          within such NOTICE file, excluding those notices that do not
110
+          pertain to any part of the Derivative Works, in at least one
111
+          of the following places: within a NOTICE text file distributed
112
+          as part of the Derivative Works; within the Source form or
113
+          documentation, if provided along with the Derivative Works; or,
114
+          within a display generated by the Derivative Works, if and
115
+          wherever such third-party notices normally appear. The contents
116
+          of the NOTICE file are for informational purposes only and
117
+          do not modify the License. You may add Your own attribution
118
+          notices within Derivative Works that You distribute, alongside
119
+          or as an addendum to the NOTICE text from the Work, provided
120
+          that such additional attribution notices cannot be construed
121
+          as modifying the License.
122
+
123
+      You may add Your own copyright statement to Your modifications and
124
+      may provide additional or different license terms and conditions
125
+      for use, reproduction, or distribution of Your modifications, or
126
+      for any such Derivative Works as a whole, provided Your use,
127
+      reproduction, and distribution of the Work otherwise complies with
128
+      the conditions stated in this License.
129
+
130
+   5. Submission of Contributions. Unless You explicitly state otherwise,
131
+      any Contribution intentionally submitted for inclusion in the Work
132
+      by You to the Licensor shall be under the terms and conditions of
133
+      this License, without any additional terms or conditions.
134
+      Notwithstanding the above, nothing herein shall supersede or modify
135
+      the terms of any separate license agreement you may have executed
136
+      with Licensor regarding such Contributions.
137
+
138
+   6. Trademarks. This License does not grant permission to use the trade
139
+      names, trademarks, service marks, or product names of the Licensor,
140
+      except as required for reasonable and customary use in describing the
141
+      origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+   7. Disclaimer of Warranty. Unless required by applicable law or
144
+      agreed to in writing, Licensor provides the Work (and each
145
+      Contributor provides its Contributions) on an "AS IS" BASIS,
146
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+      implied, including, without limitation, any warranties or conditions
148
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+      PARTICULAR PURPOSE. You are solely responsible for determining the
150
+      appropriateness of using or redistributing the Work and assume any
151
+      risks associated with Your exercise of permissions under this License.
152
+
153
+   8. Limitation of Liability. In no event and under no legal theory,
154
+      whether in tort (including negligence), contract, or otherwise,
155
+      unless required by applicable law (such as deliberate and grossly
156
+      negligent acts) or agreed to in writing, shall any Contributor be
157
+      liable to You for damages, including any direct, indirect, special,
158
+      incidental, or consequential damages of any character arising as a
159
+      result of this License or out of the use or inability to use the
160
+      Work (including but not limited to damages for loss of goodwill,
161
+      work stoppage, computer failure or malfunction, or any and all
162
+      other commercial damages or losses), even if such Contributor
163
+      has been advised of the possibility of such damages.
164
+
165
+   9. Accepting Warranty or Additional Liability. While redistributing
166
+      the Work or Derivative Works thereof, You may choose to offer,
167
+      and charge a fee for, acceptance of support, warranty, indemnity,
168
+      or other liability obligations and/or rights consistent with this
169
+      License. However, in accepting such obligations, You may act only
170
+      on Your own behalf and on Your sole responsibility, not on behalf
171
+      of any other Contributor, and only if You agree to indemnify,
172
+      defend, and hold each Contributor harmless for any liability
173
+      incurred by, or claims asserted against, such Contributor by reason
174
+      of your accepting any such warranty or additional liability.
175
+
176
+   END OF TERMS AND CONDITIONS
177
+
178
+   Copyright 2016 The Linux Foundation.
179
+
180
+   Licensed under the Apache License, Version 2.0 (the "License");
181
+   you may not use this file except in compliance with the License.
182
+   You may obtain a copy of the License at
183
+
184
+       http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+   Unless required by applicable law or agreed to in writing, software
187
+   distributed under the License is distributed on an "AS IS" BASIS,
188
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+   See the License for the specific language governing permissions and
190
+   limitations under the License.
0 191
new file mode 100644
... ...
@@ -0,0 +1,167 @@
0
+# OCI Image Format Specification
1
+<div>
2
+<a href="https://travis-ci.org/opencontainers/image-spec">
3
+<img src="https://travis-ci.org/opencontainers/image-spec.svg?branch=master"></img>
4
+</a>
5
+</div>
6
+
7
+The OCI Image Format project creates and maintains the software shipping container image format spec (OCI Image Format).
8
+
9
+**[The specification can be found here](spec.md).**
10
+
11
+This repository also provides [Go types](specs-go), [intra-blob validation tooling, and JSON Schema](schema).
12
+The Go types and validation should be compatible with the current Go release; earlier Go releases are not supported.
13
+
14
+Additional documentation about how this group operates:
15
+
16
+- [Code of Conduct](https://github.com/opencontainers/tob/blob/d2f9d68c1332870e40693fe077d311e0742bc73d/code-of-conduct.md)
17
+- [Roadmap](#roadmap)
18
+- [Releases](RELEASES.md)
19
+- [Project Documentation](project.md)
20
+
21
+The _optional_ and _base_ layers of all OCI projects are tracked in the [OCI Scope Table](https://www.opencontainers.org/about/oci-scope-table).
22
+
23
+## Running an OCI Image
24
+
25
+The OCI Image Format partner project is the [OCI Runtime Spec project](https://github.com/opencontainers/runtime-spec).
26
+The Runtime Specification outlines how to run a "[filesystem bundle](https://github.com/opencontainers/runtime-spec/blob/master/bundle.md)" that is unpacked on disk.
27
+At a high-level an OCI implementation would download an OCI Image then unpack that image into an OCI Runtime filesystem bundle.
28
+At this point the OCI Runtime Bundle would be run by an OCI Runtime.
29
+
30
+This entire workflow supports the UX that users have come to expect from container engines like Docker and rkt: primarily, the ability to run an image with no additional arguments:
31
+
32
+* docker run example.com/org/app:v1.0.0
33
+* rkt run example.com/org/app,version=v1.0.0
34
+
35
+To support this UX the OCI Image Format contains sufficient information to launch the application on the target platform (e.g. command, arguments, environment variables, etc).
36
+
37
+## FAQ
38
+
39
+**Q: Why doesn't this project mention distribution?**
40
+
41
+A: Distribution, for example using HTTP as both Docker v2.2 and AppC do today, is currently out of scope on the [OCI Scope Table](https://www.opencontainers.org/about/oci-scope-table).
42
+There has been [some discussion on the TOB mailing list](https://groups.google.com/a/opencontainers.org/d/msg/tob/A3JnmI-D-6Y/tLuptPDHAgAJ) to make distribution an optional layer, but this topic is a work in progress.
43
+
44
+**Q: What happens to AppC or Docker Image Formats?**
45
+
46
+A: Existing formats can continue to be a proving ground for technologies, as needed.
47
+The OCI Image Format project strives to provide a dependable open specification that can be shared between different tools and be evolved for years or decades of compatibility; as the deb and rpm format have.
48
+
49
+Find more [FAQ on the OCI site](https://www.opencontainers.org/faq).
50
+
51
+## Roadmap
52
+
53
+The [GitHub milestones](https://github.com/opencontainers/image-spec/milestones) lay out the path to the OCI v1.0.0 release in late 2016.
54
+
55
+# Contributing
56
+
57
+Development happens on GitHub for the spec.
58
+Issues are used for bugs and actionable items and longer discussions can happen on the [mailing list](#mailing-list).
59
+
60
+The specification and code is licensed under the Apache 2.0 license found in the `LICENSE` file of this repository.
61
+
62
+## Discuss your design
63
+
64
+The project welcomes submissions, but please let everyone know what you are working on.
65
+
66
+Before undertaking a nontrivial change to this specification, send mail to the [mailing list](#mailing-list) to discuss what you plan to do.
67
+This gives everyone a chance to validate the design, helps prevent duplication of effort, and ensures that the idea fits.
68
+It also guarantees that the design is sound before code is written; a GitHub pull-request is not the place for high-level discussions.
69
+
70
+Typos and grammatical errors can go straight to a pull-request.
71
+When in doubt, start on the [mailing-list](#mailing-list).
72
+
73
+## Weekly Call
74
+
75
+The contributors and maintainers of all OCI projects have a weekly meeting Wednesdays at 2:00 PM (USA Pacific).
76
+Everyone is welcome to participate via [UberConference web][UberConference] or audio-only: +1-415-968-0849 (no PIN needed).
77
+An initial agenda will be posted to the [mailing list](#mailing-list) earlier in the week, and everyone is welcome to propose additional topics or suggest other agenda alterations there.
78
+Minutes are posted to the [mailing list](#mailing-list) and minutes from past calls are archived [here][minutes].
79
+
80
+## Mailing List
81
+
82
+You can subscribe and join the mailing list on [Google Groups](https://groups.google.com/a/opencontainers.org/forum/#!forum/dev).
83
+
84
+## IRC
85
+
86
+OCI discussion happens on #opencontainers on Freenode ([logs][irc-logs]).
87
+
88
+## Markdown style
89
+
90
+To keep consistency throughout the Markdown files in the Open Container spec all files should be formatted one sentence per line.
91
+This fixes two things: it makes diffing easier with git and it resolves fights about line wrapping length.
92
+For example, this paragraph will span three lines in the Markdown source.
93
+
94
+## Git commit
95
+
96
+### Sign your work
97
+
98
+The sign-off is a simple line at the end of the explanation for the patch, which certifies that you wrote it or otherwise have the right to pass it on as an open-source patch.
99
+The rules are pretty simple: if you can certify the below (from [developercertificate.org](http://developercertificate.org/)):
100
+
101
+```
102
+Developer Certificate of Origin
103
+Version 1.1
104
+
105
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
106
+660 York Street, Suite 102,
107
+San Francisco, CA 94110 USA
108
+
109
+Everyone is permitted to copy and distribute verbatim copies of this
110
+license document, but changing it is not allowed.
111
+
112
+
113
+Developer's Certificate of Origin 1.1
114
+
115
+By making a contribution to this project, I certify that:
116
+
117
+(a) The contribution was created in whole or in part by me and I
118
+    have the right to submit it under the open source license
119
+    indicated in the file; or
120
+
121
+(b) The contribution is based upon previous work that, to the best
122
+    of my knowledge, is covered under an appropriate open source
123
+    license and I have the right under that license to submit that
124
+    work with modifications, whether created in whole or in part
125
+    by me, under the same open source license (unless I am
126
+    permitted to submit under a different license), as indicated
127
+    in the file; or
128
+
129
+(c) The contribution was provided directly to me by some other
130
+    person who certified (a), (b) or (c) and I have not modified
131
+    it.
132
+
133
+(d) I understand and agree that this project and the contribution
134
+    are public and that a record of the contribution (including all
135
+    personal information I submit with it, including my sign-off) is
136
+    maintained indefinitely and may be redistributed consistent with
137
+    this project or the open source license(s) involved.
138
+```
139
+
140
+then you just add a line to every git commit message:
141
+
142
+    Signed-off-by: Joe Smith <joe@gmail.com>
143
+
144
+using your real name (sorry, no pseudonyms or anonymous contributions.)
145
+
146
+You can add the sign off when creating the git commit via `git commit -s`.
147
+
148
+### Commit Style
149
+
150
+Simple house-keeping for clean git history.
151
+Read more on [How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/) or the Discussion section of [`git-commit(1)`](http://git-scm.com/docs/git-commit).
152
+
153
+1. Separate the subject from body with a blank line
154
+2. Limit the subject line to 50 characters
155
+3. Capitalize the subject line
156
+4. Do not end the subject line with a period
157
+5. Use the imperative mood in the subject line
158
+6. Wrap the body at 72 characters
159
+7. Use the body to explain what and why vs. how
160
+  * If there was important/useful/essential conversation or information, copy or include a reference
161
+8. When possible, one keyword to scope the change in the subject (i.e. "README: ...", "runtime: ...")
162
+
163
+
164
+[UberConference]: https://www.uberconference.com/opencontainers
165
+[irc-logs]: http://ircbot.wl.linuxfoundation.org/eavesdrop/%23opencontainers/
166
+[minutes]: http://ircbot.wl.linuxfoundation.org/meetings/opencontainers/
0 167
new file mode 100644
... ...
@@ -0,0 +1,103 @@
0
+// Copyright 2016 The Linux Foundation
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     http://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package v1
15
+
16
+import (
17
+	"time"
18
+
19
+	digest "github.com/opencontainers/go-digest"
20
+)
21
+
22
+// ImageConfig defines the execution parameters which should be used as a base when running a container using an image.
23
+type ImageConfig struct {
24
+	// User defines the username or UID which the process in the container should run as.
25
+	User string `json:"User,omitempty"`
26
+
27
+	// ExposedPorts a set of ports to expose from a container running this image.
28
+	ExposedPorts map[string]struct{} `json:"ExposedPorts,omitempty"`
29
+
30
+	// Env is a list of environment variables to be used in a container.
31
+	Env []string `json:"Env,omitempty"`
32
+
33
+	// Entrypoint defines a list of arguments to use as the command to execute when the container starts.
34
+	Entrypoint []string `json:"Entrypoint,omitempty"`
35
+
36
+	// Cmd defines the default arguments to the entrypoint of the container.
37
+	Cmd []string `json:"Cmd,omitempty"`
38
+
39
+	// Volumes is a set of directories which should be created as data volumes in a container running this image.
40
+	Volumes map[string]struct{} `json:"Volumes,omitempty"`
41
+
42
+	// WorkingDir sets the current working directory of the entrypoint process in the container.
43
+	WorkingDir string `json:"WorkingDir,omitempty"`
44
+
45
+	// Labels contains arbitrary metadata for the container.
46
+	Labels map[string]string `json:"Labels,omitempty"`
47
+
48
+	// StopSignal contains the system call signal that will be sent to the container to exit.
49
+	StopSignal string `json:"StopSignal,omitempty"`
50
+}
51
+
52
+// RootFS describes a layer content addresses
53
+type RootFS struct {
54
+	// Type is the type of the rootfs.
55
+	Type string `json:"type"`
56
+
57
+	// DiffIDs is an array of layer content hashes (DiffIDs), in order from bottom-most to top-most.
58
+	DiffIDs []digest.Digest `json:"diff_ids"`
59
+}
60
+
61
+// History describes the history of a layer.
62
+type History struct {
63
+	// Created is the combined date and time at which the layer was created, formatted as defined by RFC 3339, section 5.6.
64
+	Created *time.Time `json:"created,omitempty"`
65
+
66
+	// CreatedBy is the command which created the layer.
67
+	CreatedBy string `json:"created_by,omitempty"`
68
+
69
+	// Author is the author of the build point.
70
+	Author string `json:"author,omitempty"`
71
+
72
+	// Comment is a custom message set when creating the layer.
73
+	Comment string `json:"comment,omitempty"`
74
+
75
+	// EmptyLayer is used to mark if the history item created a filesystem diff.
76
+	EmptyLayer bool `json:"empty_layer,omitempty"`
77
+}
78
+
79
+// Image is the JSON structure which describes some basic information about the image.
80
+// This provides the `application/vnd.oci.image.config.v1+json` mediatype when marshalled to JSON.
81
+type Image struct {
82
+	// Created is the combined date and time at which the image was created, formatted as defined by RFC 3339, section 5.6.
83
+	Created *time.Time `json:"created,omitempty"`
84
+
85
+	// Author defines the name and/or email address of the person or entity which created and is responsible for maintaining the image.
86
+	Author string `json:"author,omitempty"`
87
+
88
+	// Architecture is the CPU architecture which the binaries in this image are built to run on.
89
+	Architecture string `json:"architecture"`
90
+
91
+	// OS is the name of the operating system which the image is built to run on.
92
+	OS string `json:"os"`
93
+
94
+	// Config defines the execution parameters which should be used as a base when running a container using the image.
95
+	Config ImageConfig `json:"config,omitempty"`
96
+
97
+	// RootFS references the layer content addresses used by the image.
98
+	RootFS RootFS `json:"rootfs"`
99
+
100
+	// History describes the history of each layer.
101
+	History []History `json:"history,omitempty"`
102
+}
0 103
new file mode 100644
... ...
@@ -0,0 +1,64 @@
0
+// Copyright 2016 The Linux Foundation
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     http://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package v1
15
+
16
+import digest "github.com/opencontainers/go-digest"
17
+
18
+// Descriptor describes the disposition of targeted content.
19
+// This structure provides `application/vnd.oci.descriptor.v1+json` mediatype
20
+// when marshalled to JSON.
21
+type Descriptor struct {
22
+	// MediaType is the media type of the object this schema refers to.
23
+	MediaType string `json:"mediaType,omitempty"`
24
+
25
+	// Digest is the digest of the targeted content.
26
+	Digest digest.Digest `json:"digest"`
27
+
28
+	// Size specifies the size in bytes of the blob.
29
+	Size int64 `json:"size"`
30
+
31
+	// URLs specifies a list of URLs from which this object MAY be downloaded
32
+	URLs []string `json:"urls,omitempty"`
33
+
34
+	// Annotations contains arbitrary metadata relating to the targeted content.
35
+	Annotations map[string]string `json:"annotations,omitempty"`
36
+
37
+	// Platform describes the platform which the image in the manifest runs on.
38
+	//
39
+	// This should only be used when referring to a manifest.
40
+	Platform *Platform `json:"platform,omitempty"`
41
+}
42
+
43
+// Platform describes the platform which the image in the manifest runs on.
44
+type Platform struct {
45
+	// Architecture field specifies the CPU architecture, for example
46
+	// `amd64` or `ppc64`.
47
+	Architecture string `json:"architecture"`
48
+
49
+	// OS specifies the operating system, for example `linux` or `windows`.
50
+	OS string `json:"os"`
51
+
52
+	// OSVersion is an optional field specifying the operating system
53
+	// version, for example on Windows `10.0.14393.1066`.
54
+	OSVersion string `json:"os.version,omitempty"`
55
+
56
+	// OSFeatures is an optional field specifying an array of strings,
57
+	// each listing a required OS feature (for example on Windows `win32k`).
58
+	OSFeatures []string `json:"os.features,omitempty"`
59
+
60
+	// Variant is an optional field specifying a variant of the CPU, for
61
+	// example `v7` to specify ARMv7 when architecture is `arm`.
62
+	Variant string `json:"variant,omitempty"`
63
+}
0 64
new file mode 100644
... ...
@@ -0,0 +1,29 @@
0
+// Copyright 2016 The Linux Foundation
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     http://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package v1
15
+
16
+import "github.com/opencontainers/image-spec/specs-go"
17
+
18
+// Index references manifests for various platforms.
19
+// This structure provides `application/vnd.oci.image.index.v1+json` mediatype when marshalled to JSON.
20
+type Index struct {
21
+	specs.Versioned
22
+
23
+	// Manifests references platform specific manifests.
24
+	Manifests []Descriptor `json:"manifests"`
25
+
26
+	// Annotations contains arbitrary metadata for the image index.
27
+	Annotations map[string]string `json:"annotations,omitempty"`
28
+}
0 29
new file mode 100644
... ...
@@ -0,0 +1,28 @@
0
+// Copyright 2016 The Linux Foundation
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     http://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package v1
15
+
16
+const (
17
+	// ImageLayoutFile is the file name of oci image layout file
18
+	ImageLayoutFile = "oci-layout"
19
+	// ImageLayoutVersion is the version of ImageLayout
20
+	ImageLayoutVersion = "1.0.0"
21
+)
22
+
23
+// ImageLayout is the structure in the "oci-layout" file, found in the root
24
+// of an OCI Image-layout directory.
25
+type ImageLayout struct {
26
+	Version string `json:"imageLayoutVersion"`
27
+}
0 28
new file mode 100644
... ...
@@ -0,0 +1,32 @@
0
+// Copyright 2016 The Linux Foundation
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     http://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package v1
15
+
16
+import "github.com/opencontainers/image-spec/specs-go"
17
+
18
+// Manifest provides `application/vnd.oci.image.manifest.v1+json` mediatype structure when marshalled to JSON.
19
+type Manifest struct {
20
+	specs.Versioned
21
+
22
+	// Config references a configuration object for a container, by digest.
23
+	// The referenced configuration object is a JSON blob that the runtime uses to set up the container.
24
+	Config Descriptor `json:"config"`
25
+
26
+	// Layers is an indexed list of layers referenced by the manifest.
27
+	Layers []Descriptor `json:"layers"`
28
+
29
+	// Annotations contains arbitrary metadata for the image manifest.
30
+	Annotations map[string]string `json:"annotations,omitempty"`
31
+}
0 32
new file mode 100644
... ...
@@ -0,0 +1,48 @@
0
+// Copyright 2016 The Linux Foundation
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     http://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package v1
15
+
16
+const (
17
+	// MediaTypeDescriptor specifies the media type for a content descriptor.
18
+	MediaTypeDescriptor = "application/vnd.oci.descriptor.v1+json"
19
+
20
+	// MediaTypeLayoutHeader specifies the media type for the oci-layout.
21
+	MediaTypeLayoutHeader = "application/vnd.oci.layout.header.v1+json"
22
+
23
+	// MediaTypeImageManifest specifies the media type for an image manifest.
24
+	MediaTypeImageManifest = "application/vnd.oci.image.manifest.v1+json"
25
+
26
+	// MediaTypeImageIndex specifies the media type for an image index.
27
+	MediaTypeImageIndex = "application/vnd.oci.image.index.v1+json"
28
+
29
+	// MediaTypeImageLayer is the media type used for layers referenced by the manifest.
30
+	MediaTypeImageLayer = "application/vnd.oci.image.layer.v1.tar"
31
+
32
+	// MediaTypeImageLayerGzip is the media type used for gzipped layers
33
+	// referenced by the manifest.
34
+	MediaTypeImageLayerGzip = "application/vnd.oci.image.layer.v1.tar+gzip"
35
+
36
+	// MediaTypeImageLayerNonDistributable is the media type for layers referenced by
37
+	// the manifest but with distribution restrictions.
38
+	MediaTypeImageLayerNonDistributable = "application/vnd.oci.image.layer.nondistributable.v1.tar"
39
+
40
+	// MediaTypeImageLayerNonDistributableGzip is the media type for
41
+	// gzipped layers referenced by the manifest but with distribution
42
+	// restrictions.
43
+	MediaTypeImageLayerNonDistributableGzip = "application/vnd.oci.image.layer.nondistributable.v1.tar+gzip"
44
+
45
+	// MediaTypeImageConfig specifies the media type for the image configuration.
46
+	MediaTypeImageConfig = "application/vnd.oci.image.config.v1+json"
47
+)
0 48
new file mode 100644
... ...
@@ -0,0 +1,32 @@
0
+// Copyright 2016 The Linux Foundation
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     http://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package specs
15
+
16
+import "fmt"
17
+
18
+const (
19
+	// VersionMajor is for an API incompatible changes
20
+	VersionMajor = 1
21
+	// VersionMinor is for functionality in a backwards-compatible manner
22
+	VersionMinor = 0
23
+	// VersionPatch is for backwards-compatible bug fixes
24
+	VersionPatch = 0
25
+
26
+	// VersionDev indicates development branch. Releases will be empty string.
27
+	VersionDev = "-rc6-dev"
28
+)
29
+
30
+// Version is the specification version that the package types support.
31
+var Version = fmt.Sprintf("%d.%d.%d%s", VersionMajor, VersionMinor, VersionPatch, VersionDev)
0 32
new file mode 100644
... ...
@@ -0,0 +1,23 @@
0
+// Copyright 2016 The Linux Foundation
1
+//
2
+// Licensed under the Apache License, Version 2.0 (the "License");
3
+// you may not use this file except in compliance with the License.
4
+// You may obtain a copy of the License at
5
+//
6
+//     http://www.apache.org/licenses/LICENSE-2.0
7
+//
8
+// Unless required by applicable law or agreed to in writing, software
9
+// distributed under the License is distributed on an "AS IS" BASIS,
10
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+// See the License for the specific language governing permissions and
12
+// limitations under the License.
13
+
14
+package specs
15
+
16
+// Versioned provides a struct with the manifest schemaVersion and mediaType.
17
+// Incoming content with unknown schema version can be decoded against this
18
+// struct to check the version.
19
+type Versioned struct {
20
+	// SchemaVersion is the image manifest schema that this image follows
21
+	SchemaVersion int `json:"schemaVersion"`
22
+}