Browse code

bump to master

Victor Vieux authored on 2013/05/29 22:52:18
Showing 32 changed files
... ...
@@ -1,3 +1,8 @@
1
+# This file lists all individuals having contributed content to the repository.
2
+# If you're submitting a patch, please add your name here in alphabetical order as part of the patch.
3
+#
4
+# For a list of active project maintainers, see the MAINTAINERS file.
5
+#
1 6
 Al Tobey <al@ooyala.com>
2 7
 Alexey Shamrin <shamrin@gmail.com>
3 8
 Andrea Luzzardi <aluzzardi@gmail.com>
... ...
@@ -1,9 +1,6 @@
1 1
 # Contributing to Docker
2 2
 
3
-Want to hack on Docker? Awesome! There are instructions to get you
4
-started on the website: http://docker.io/gettingstarted.html
5
-
6
-They are probably not perfect, please let us know if anything feels
3
+Want to hack on Docker? Awesome! Here are instructions to get you started. They are probably not perfect, please let us know if anything feels
7 4
 wrong or incomplete.
8 5
 
9 6
 ## Contribution guidelines
... ...
@@ -91,3 +88,73 @@ Add your name to the AUTHORS file, but make sure the list is sorted and your
91 91
 name and email address match your git configuration. The AUTHORS file is
92 92
 regenerated occasionally from the git commit history, so a mismatch may result
93 93
 in your changes being overwritten.
94
+
95
+
96
+## Decision process
97
+
98
+### How are decisions made?
99
+
100
+Short answer: with pull requests to the docker repository.
101
+
102
+Docker is an open-source project with an open design philosophy. This means that the repository is the source of truth for EVERY aspect of the project,
103
+including its philosophy, design, roadmap and APIs. *If it's part of the project, it's in the repo. It's in the repo, it's part of the project.*
104
+
105
+As a result, all decisions can be expressed as changes to the repository. An implementation change is a change to the source code. An API change is a change to
106
+the API specification. A philosophy change is a change to the philosophy manifesto. And so on.
107
+
108
+All decisions affecting docker, big and small, follow the same 3 steps:
109
+
110
+* Step 1: Open a pull request. Anyone can do this.
111
+
112
+* Step 2: Discuss the pull request. Anyone can do this.
113
+
114
+* Step 3: Accept or refuse a pull request. The relevant maintainer does this (see below "Who decides what?")
115
+
116
+
117
+### Who decides what?
118
+
119
+So all decisions are pull requests, and the relevant maintainer makes the decision by accepting or refusing the pull request.
120
+But how do we identify the relevant maintainer for a given pull request?
121
+
122
+Docker follows the timeless, highly efficient and totally unfair system known as [Benevolent dictator for life](http://en.wikipedia.org/wiki/Benevolent_Dictator_for_Life),
123
+with yours truly, Solomon Hykes, in the role of BDFL.
124
+This means that all decisions are made by default by me. Since making every decision myself would be highly unscalable, in practice decisions are spread across multiple maintainers.
125
+
126
+The relevant maintainer for a pull request is assigned in 3 steps:
127
+
128
+* Step 1: Determine the subdirectory affected by the pull request. This might be src/registry, docs/source/api, or any other part of the repo.
129
+
130
+* Step 2: Find the MAINTAINERS file which affects this directory. If the directory itself does not have a MAINTAINERS file, work your way up the the repo hierarchy until you find one.
131
+
132
+* Step 3: The first maintainer listed is the primary maintainer. The pull request is assigned to him. He may assign it to other listed maintainers, at his discretion.
133
+
134
+
135
+### I'm a maintainer, should I make pull requests too?
136
+
137
+Primary maintainers are not required to create pull requests when changing their own subdirectory, but secondary maintainers are.
138
+
139
+### Who assigns maintainers?
140
+
141
+Solomon.
142
+
143
+### How can I become a maintainer?
144
+
145
+* Step 1: learn the component inside out
146
+* Step 2: make yourself useful by contributing code, bugfixes, support etc.
147
+* Step 3: volunteer on the irc channel (#docker@freenode)
148
+
149
+Don't forget: being a maintainer is a time investment. Make sure you will have time to make yourself available.
150
+You don't have to be a maintainer to make a difference on the project!
151
+
152
+### What are a maintainer's responsibility?
153
+
154
+It is every maintainer's responsibility to:
155
+
156
+* 1) Expose a clear roadmap for improving their component.
157
+* 2) Deliver prompt feedback and decisions on pull requests.
158
+* 3) Be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list.
159
+* 4) Make sure their component respects the philosophy, design and roadmap of the project.
160
+
161
+### How is this process changed?
162
+
163
+Just like everything else: by making a pull request :)
94 164
new file mode 100644
... ...
@@ -0,0 +1,4 @@
0
+Solomon Hykes <solomon@dotcloud.com>
1
+Guillaume Charmes <guillaume@dotcloud.com>
2
+api.go: Victor Vieux <victor@dotcloud.com>
3
+Vagrantfile: Daniel Mizyrycki <daniel@dotcloud.com>
0 4
deleted file mode 100644
... ...
@@ -1,71 +0,0 @@
1
-
2
-## Spec for data volumes
3
-
4
-Spec owner: Solomon Hykes <solomon@dotcloud.com>
5
-
6
-Data volumes (issue #111) are a much-requested feature which trigger much discussion and debate. Below is the current authoritative spec for implementing data volumes.
7
-This spec will be deprecated once the feature is fully implemented.
8
-
9
-Discussion, requests, trolls, demands, offerings, threats and other forms of supplications concerning this spec should be addressed to Solomon here: https://github.com/dotcloud/docker/issues/111
10
-
11
-
12
-### 1. Creating data volumes
13
-
14
-At container creation, parts of a container's filesystem can be mounted as separate data volumes. Volumes are defined with the -v flag.
15
-
16
-For example:
17
-
18
-```bash
19
-$ docker run -v /var/lib/postgres -v /var/log postgres /usr/bin/postgres
20
-```
21
-
22
-In this example, a new container is created from the 'postgres' image. At the same time, docker creates 2 new data volumes: one will be mapped to the container at /var/lib/postgres, the other at /var/log.
23
-
24
-2 important notes:
25
-
26
-1) Volumes don't have top-level names. At no point does the user provide a name, or is a name given to him. Volumes are identified by the path at which they are mounted inside their container.
27
-
28
-2) The user doesn't choose the source of the volume. Docker only mounts volumes it created itself, in the same way that it only runs containers that it created itself. That is by design.
29
-
30
-
31
-### 2. Sharing data volumes
32
-
33
-Instead of creating its own volumes, a container can share another container's volumes. For example:
34
-
35
-```bash
36
-$ docker run --volumes-from $OTHER_CONTAINER_ID postgres /usr/local/bin/postgres-backup
37
-```
38
-
39
-In this example, a new container is created from the 'postgres' example. At the same time, docker will *re-use* the 2 data volumes created in the previous example. One volume will be mounted on the /var/lib/postgres of *both* containers, and the other will be mounted on the /var/log of both containers.
40
-
41
-### 3. Under the hood
42
-
43
-Docker stores volumes in /var/lib/docker/volumes. Each volume receives a globally unique ID at creation, and is stored at /var/lib/docker/volumes/ID.
44
-
45
-At creation, volumes are attached to a single container - the source of truth for this mapping will be the container's configuration.
46
-
47
-Mounting a volume consists of calling "mount --bind" from the volume's directory to the appropriate sub-directory of the container mountpoint. This may be done by Docker itself, or farmed out to lxc (which supports mount-binding) if possible.
48
-
49
-
50
-### 4. Backups, transfers and other volume operations
51
-
52
-Volumes sometimes need to be backed up, transfered between hosts, synchronized, etc. These operations typically are application-specific or site-specific, eg. rsync vs. S3 upload vs. replication vs...
53
-
54
-Rather than attempting to implement all these scenarios directly, Docker will allow for custom implementations using an extension mechanism.
55
-
56
-### 5. Custom volume handlers
57
-
58
-Docker allows for arbitrary code to be executed against a container's volumes, to implement any custom action: backup, transfer, synchronization across hosts, etc.
59
-
60
-Here's an example:
61
-
62
-```bash
63
-$ DB=$(docker run -d -v /var/lib/postgres -v /var/log postgres /usr/bin/postgres)
64
-
65
-$ BACKUP_JOB=$(docker run -d --volumes-from $DB shykes/backuper /usr/local/bin/backup-postgres --s3creds=$S3CREDS)
66
-
67
-$ docker wait $BACKUP_JOB
68
-```
69
-
70
-Congratulations, you just implemented a custom volume handler, using Docker's built-in ability to 1) execute arbitrary code and 2) share volumes between containers.
71
-
... ...
@@ -33,6 +33,13 @@ func parseForm(r *http.Request) error {
33 33
 	return nil
34 34
 }
35 35
 
36
+func parseMultipartForm(r *http.Request) error {
37
+	if err := r.ParseMultipartForm(4096); err != nil && !strings.HasPrefix(err.Error(), "mime:") {
38
+		return err
39
+	}
40
+	return nil
41
+}
42
+
36 43
 func httpError(w http.ResponseWriter, err error) {
37 44
 	if strings.HasPrefix(err.Error(), "No such") {
38 45
 		http.Error(w, err.Error(), http.StatusNotFound)
... ...
@@ -206,7 +213,7 @@ func getContainersChanges(srv *Server, version float64, w http.ResponseWriter, r
206 206
 	return nil
207 207
 }
208 208
 
209
-func getContainersPs(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
209
+func getContainersJson(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
210 210
 	if err := parseForm(r); err != nil {
211 211
 		return err
212 212
 	}
... ...
@@ -347,13 +354,18 @@ func postImagesInsert(srv *Server, version float64, w http.ResponseWriter, r *ht
347 347
 		w.Header().Set("Content-Type", "application/json")
348 348
 	}
349 349
 	sf := utils.NewStreamFormatter(version > 1.0)
350
-	if err := srv.ImageInsert(name, url, path, w, sf); err != nil {
350
+	imgId, err := srv.ImageInsert(name, url, path, w, sf)
351
+	if err != nil {
351 352
 		if sf.Used() {
352 353
 			w.Write(sf.FormatError(err))
353 354
 			return nil
354 355
 		}
356
+	}
357
+	b, err := json.Marshal(&ApiId{Id: imgId})
358
+	if err != nil {
355 359
 		return err
356 360
 	}
361
+	writeJson(w, b)
357 362
 	return nil
358 363
 }
359 364
 
... ...
@@ -564,6 +576,10 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r
564 564
 	}
565 565
 	name := vars["name"]
566 566
 
567
+	if _, err := srv.ContainerInspect(name); err != nil {
568
+		return err
569
+	}
570
+
567 571
 	in, out, err := hijackServer(w)
568 572
 	if err != nil {
569 573
 		return err
... ...
@@ -636,6 +652,30 @@ func postImagesGetCache(srv *Server, version float64, w http.ResponseWriter, r *
636 636
 	return nil
637 637
 }
638 638
 
639
+func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
640
+	if err := r.ParseMultipartForm(4096); err != nil {
641
+		return err
642
+	}
643
+
644
+	dockerfile, _, err := r.FormFile("Dockerfile")
645
+	if err != nil {
646
+		return err
647
+	}
648
+
649
+	context, _, err := r.FormFile("Context")
650
+	if err != nil {
651
+		if err != http.ErrMissingFile {
652
+			return err
653
+		}
654
+	}
655
+
656
+	b := NewBuildFile(srv, utils.NewWriteFlusher(w))
657
+	if _, err := b.Build(dockerfile, context); err != nil {
658
+		fmt.Fprintf(w, "Error build: %s\n", err)
659
+	}
660
+	return nil
661
+}
662
+
639 663
 func ListenAndServe(addr string, srv *Server, logging bool) error {
640 664
 	r := mux.NewRouter()
641 665
 	log.Printf("Listening for HTTP on %s\n", addr)
... ...
@@ -650,7 +690,8 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
650 650
 			"/images/search":                getImagesSearch,
651 651
 			"/images/{name:.*}/history":     getImagesHistory,
652 652
 			"/images/{name:.*}/json":        getImagesByName,
653
-			"/containers/ps":                getContainersPs,
653
+			"/containers/ps":                getContainersJson,
654
+			"/containers/json":              getContainersJson,
654 655
 			"/containers/{name:.*}/export":  getContainersExport,
655 656
 			"/containers/{name:.*}/changes": getContainersChanges,
656 657
 			"/containers/{name:.*}/json":    getContainersByName,
... ...
@@ -658,6 +699,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
658 658
 		"POST": {
659 659
 			"/auth":                         postAuth,
660 660
 			"/commit":                       postCommit,
661
+			"/build":                        postBuild,
661 662
 			"/images/create":                postImagesCreate,
662 663
 			"/images/{name:.*}/insert":      postImagesInsert,
663 664
 			"/images/{name:.*}/push":        postImagesPush,
... ...
@@ -318,7 +318,7 @@ func TestGetImagesByName(t *testing.T) {
318 318
 	}
319 319
 }
320 320
 
321
-func TestGetContainersPs(t *testing.T) {
321
+func TestGetContainersJson(t *testing.T) {
322 322
 	runtime, err := newTestRuntime()
323 323
 	if err != nil {
324 324
 		t.Fatal(err)
... ...
@@ -336,13 +336,13 @@ func TestGetContainersPs(t *testing.T) {
336 336
 	}
337 337
 	defer runtime.Destroy(container)
338 338
 
339
-	req, err := http.NewRequest("GET", "/containers?quiet=1&all=1", nil)
339
+	req, err := http.NewRequest("GET", "/containers/json?all=1", nil)
340 340
 	if err != nil {
341 341
 		t.Fatal(err)
342 342
 	}
343 343
 
344 344
 	r := httptest.NewRecorder()
345
-	if err := getContainersPs(srv, API_VERSION, r, req, nil); err != nil {
345
+	if err := getContainersJson(srv, API_VERSION, r, req, nil); err != nil {
346 346
 		t.Fatal(err)
347 347
 	}
348 348
 	containers := []ApiContainers{}
... ...
@@ -2,6 +2,7 @@ package docker
2 2
 
3 3
 import (
4 4
 	"errors"
5
+	"fmt"
5 6
 	"io"
6 7
 	"io/ioutil"
7 8
 	"os"
... ...
@@ -31,6 +32,20 @@ func (compression *Compression) Flag() string {
31 31
 	return ""
32 32
 }
33 33
 
34
+func (compression *Compression) Extension() string {
35
+	switch *compression {
36
+	case Uncompressed:
37
+		return "tar"
38
+	case Bzip2:
39
+		return "tar.bz2"
40
+	case Gzip:
41
+		return "tar.gz"
42
+	case Xz:
43
+		return "tar.xz"
44
+	}
45
+	return ""
46
+}
47
+
34 48
 func Tar(path string, compression Compression) (io.Reader, error) {
35 49
 	cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-c"+compression.Flag(), ".")
36 50
 	return CmdStream(cmd)
... ...
@@ -41,7 +56,7 @@ func Untar(archive io.Reader, path string) error {
41 41
 	cmd.Stdin = archive
42 42
 	output, err := cmd.CombinedOutput()
43 43
 	if err != nil {
44
-		return errors.New(err.Error() + ": " + string(output))
44
+		return fmt.Errorf("%s: %s", err, output)
45 45
 	}
46 46
 	return nil
47 47
 }
48 48
new file mode 120000
... ...
@@ -0,0 +1 @@
0
+../registry/MAINTAINERS
0 1
\ No newline at end of file
... ...
@@ -12,12 +12,6 @@ import (
12 12
 	"strings"
13 13
 )
14 14
 
15
-type BuilderClient interface {
16
-	Build(io.Reader) (string, error)
17
-	CmdFrom(string) error
18
-	CmdRun(string) error
19
-}
20
-
21 15
 type builderClient struct {
22 16
 	cli *DockerCli
23 17
 
... ...
@@ -158,8 +152,23 @@ func (b *builderClient) CmdExpose(args string) error {
158 158
 }
159 159
 
160 160
 func (b *builderClient) CmdInsert(args string) error {
161
-	// FIXME: Reimplement this once the remove_hijack branch gets merged.
162
-	// We need to retrieve the resulting Id
161
+	// tmp := strings.SplitN(args, "\t ", 2)
162
+	// sourceUrl, destPath := tmp[0], tmp[1]
163
+
164
+	// v := url.Values{}
165
+	// v.Set("url", sourceUrl)
166
+	// v.Set("path", destPath)
167
+	// body, _, err := b.cli.call("POST", "/images/insert?"+v.Encode(), nil)
168
+	// if err != nil {
169
+	// 	return err
170
+	// }
171
+
172
+	// apiId := &ApiId{}
173
+	// if err := json.Unmarshal(body, apiId); err != nil {
174
+	// 	return err
175
+	// }
176
+
177
+	// FIXME: Reimplement this, we need to retrieve the resulting Id
163 178
 	return fmt.Errorf("INSERT not implemented")
164 179
 }
165 180
 
... ...
@@ -240,7 +249,7 @@ func (b *builderClient) commit(id string) error {
240 240
 	return nil
241 241
 }
242 242
 
243
-func (b *builderClient) Build(dockerfile io.Reader) (string, error) {
243
+func (b *builderClient) Build(dockerfile, context io.Reader) (string, error) {
244 244
 	defer b.clearTmp(b.tmpContainers, b.tmpImages)
245 245
 	file := bufio.NewReader(dockerfile)
246 246
 	for {
... ...
@@ -263,18 +272,18 @@ func (b *builderClient) Build(dockerfile io.Reader) (string, error) {
263 263
 		instruction := strings.ToLower(strings.Trim(tmp[0], " "))
264 264
 		arguments := strings.Trim(tmp[1], " ")
265 265
 
266
-		fmt.Printf("%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image)
266
+		fmt.Fprintf(os.Stderr, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image)
267 267
 
268 268
 		method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:]))
269 269
 		if !exists {
270
-			fmt.Printf("Skipping unknown instruction %s\n", strings.ToUpper(instruction))
270
+			fmt.Fprintf(os.Stderr, "Skipping unknown instruction %s\n", strings.ToUpper(instruction))
271 271
 		}
272 272
 		ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface()
273 273
 		if ret != nil {
274 274
 			return "", ret.(error)
275 275
 		}
276 276
 
277
-		fmt.Printf("===> %v\n", b.image)
277
+		fmt.Fprintf(os.Stderr, "===> %v\n", b.image)
278 278
 	}
279 279
 	if b.needCommit {
280 280
 		if err := b.commit(""); err != nil {
... ...
@@ -289,13 +298,13 @@ func (b *builderClient) Build(dockerfile io.Reader) (string, error) {
289 289
 		for i := range b.tmpContainers {
290 290
 			delete(b.tmpContainers, i)
291 291
 		}
292
-		fmt.Printf("Build finished. image id: %s\n", b.image)
292
+		fmt.Fprintf(os.Stderr, "Build finished. image id: %s\n", b.image)
293 293
 		return b.image, nil
294 294
 	}
295 295
 	return "", fmt.Errorf("An error occured during the build\n")
296 296
 }
297 297
 
298
-func NewBuilderClient(addr string, port int) BuilderClient {
298
+func NewBuilderClient(addr string, port int) BuildFile {
299 299
 	return &builderClient{
300 300
 		cli:           NewDockerCli(addr, port),
301 301
 		config:        &Config{},
302 302
new file mode 100644
... ...
@@ -0,0 +1,377 @@
0
+package docker
1
+
2
+import (
3
+	"bufio"
4
+	"encoding/json"
5
+	"fmt"
6
+	"github.com/dotcloud/docker/utils"
7
+	"io"
8
+	"io/ioutil"
9
+	"os"
10
+	"path"
11
+	"reflect"
12
+	"strings"
13
+)
14
+
15
+type BuildFile interface {
16
+	Build(io.Reader, io.Reader) (string, error)
17
+	CmdFrom(string) error
18
+	CmdRun(string) error
19
+}
20
+
21
+type buildFile struct {
22
+	runtime *Runtime
23
+	builder *Builder
24
+	srv     *Server
25
+
26
+	image      string
27
+	maintainer string
28
+	config     *Config
29
+	context    string
30
+
31
+	tmpContainers map[string]struct{}
32
+	tmpImages     map[string]struct{}
33
+
34
+	needCommit bool
35
+
36
+	out io.Writer
37
+}
38
+
39
+func (b *buildFile) clearTmp(containers, images map[string]struct{}) {
40
+	for c := range containers {
41
+		tmp := b.runtime.Get(c)
42
+		b.runtime.Destroy(tmp)
43
+		utils.Debugf("Removing container %s", c)
44
+	}
45
+	for i := range images {
46
+		b.runtime.graph.Delete(i)
47
+		utils.Debugf("Removing image %s", i)
48
+	}
49
+}
50
+
51
+func (b *buildFile) CmdFrom(name string) error {
52
+	image, err := b.runtime.repositories.LookupImage(name)
53
+	if err != nil {
54
+		if b.runtime.graph.IsNotExist(err) {
55
+
56
+			var tag, remote string
57
+			if strings.Contains(name, ":") {
58
+				remoteParts := strings.Split(name, ":")
59
+				tag = remoteParts[1]
60
+				remote = remoteParts[0]
61
+			} else {
62
+				remote = name
63
+			}
64
+
65
+			if err := b.srv.ImagePull(remote, tag, "", b.out, utils.NewStreamFormatter(false)); err != nil {
66
+				return err
67
+			}
68
+
69
+			image, err = b.runtime.repositories.LookupImage(name)
70
+			if err != nil {
71
+				return err
72
+			}
73
+		} else {
74
+			return err
75
+		}
76
+	}
77
+	b.image = image.Id
78
+	b.config = &Config{}
79
+	return nil
80
+}
81
+
82
+func (b *buildFile) CmdMaintainer(name string) error {
83
+	b.needCommit = true
84
+	b.maintainer = name
85
+	return nil
86
+}
87
+
88
+func (b *buildFile) CmdRun(args string) error {
89
+	if b.image == "" {
90
+		return fmt.Errorf("Please provide a source image with `from` prior to run")
91
+	}
92
+	config, _, err := ParseRun([]string{b.image, "/bin/sh", "-c", args}, nil)
93
+	if err != nil {
94
+		return err
95
+	}
96
+
97
+	cmd, env := b.config.Cmd, b.config.Env
98
+	b.config.Cmd = nil
99
+	MergeConfig(b.config, config)
100
+
101
+	if cache, err := b.srv.ImageGetCached(b.image, config); err != nil {
102
+		return err
103
+	} else if cache != nil {
104
+		utils.Debugf("Use cached version")
105
+		b.image = cache.Id
106
+		return nil
107
+	}
108
+
109
+	cid, err := b.run()
110
+	if err != nil {
111
+		return err
112
+	}
113
+	b.config.Cmd, b.config.Env = cmd, env
114
+	return b.commit(cid)
115
+}
116
+
117
+func (b *buildFile) CmdEnv(args string) error {
118
+	b.needCommit = true
119
+	tmp := strings.SplitN(args, " ", 2)
120
+	if len(tmp) != 2 {
121
+		return fmt.Errorf("Invalid ENV format")
122
+	}
123
+	key := strings.Trim(tmp[0], " ")
124
+	value := strings.Trim(tmp[1], " ")
125
+
126
+	for i, elem := range b.config.Env {
127
+		if strings.HasPrefix(elem, key+"=") {
128
+			b.config.Env[i] = key + "=" + value
129
+			return nil
130
+		}
131
+	}
132
+	b.config.Env = append(b.config.Env, key+"="+value)
133
+	return nil
134
+}
135
+
136
+func (b *buildFile) CmdCmd(args string) error {
137
+	b.needCommit = true
138
+	var cmd []string
139
+	if err := json.Unmarshal([]byte(args), &cmd); err != nil {
140
+		utils.Debugf("Error unmarshalling: %s, using /bin/sh -c", err)
141
+		b.config.Cmd = []string{"/bin/sh", "-c", args}
142
+	} else {
143
+		b.config.Cmd = cmd
144
+	}
145
+	return nil
146
+}
147
+
148
+func (b *buildFile) CmdExpose(args string) error {
149
+	ports := strings.Split(args, " ")
150
+	b.config.PortSpecs = append(ports, b.config.PortSpecs...)
151
+	return nil
152
+}
153
+
154
+func (b *buildFile) CmdInsert(args string) error {
155
+	if b.image == "" {
156
+		return fmt.Errorf("Please provide a source image with `from` prior to insert")
157
+	}
158
+	tmp := strings.SplitN(args, " ", 2)
159
+	if len(tmp) != 2 {
160
+		return fmt.Errorf("Invalid INSERT format")
161
+	}
162
+	sourceUrl := strings.Trim(tmp[0], " ")
163
+	destPath := strings.Trim(tmp[1], " ")
164
+
165
+	file, err := utils.Download(sourceUrl, b.out)
166
+	if err != nil {
167
+		return err
168
+	}
169
+	defer file.Body.Close()
170
+
171
+	b.config.Cmd = []string{"echo", "INSERT", sourceUrl, "in", destPath}
172
+	cid, err := b.run()
173
+	if err != nil {
174
+		return err
175
+	}
176
+
177
+	container := b.runtime.Get(cid)
178
+	if container == nil {
179
+		return fmt.Errorf("An error occured while creating the container")
180
+	}
181
+
182
+	if err := container.Inject(file.Body, destPath); err != nil {
183
+		return err
184
+	}
185
+
186
+	return b.commit(cid)
187
+}
188
+
189
+func (b *buildFile) CmdAdd(args string) error {
190
+	if b.context == "" {
191
+		return fmt.Errorf("No context given. Impossible to use ADD")
192
+	}
193
+	tmp := strings.SplitN(args, " ", 2)
194
+	if len(tmp) != 2 {
195
+		return fmt.Errorf("Invalid INSERT format")
196
+	}
197
+	orig := strings.Trim(tmp[0], " ")
198
+	dest := strings.Trim(tmp[1], " ")
199
+
200
+	b.config.Cmd = []string{"echo", "PUSH", orig, "in", dest}
201
+	cid, err := b.run()
202
+	if err != nil {
203
+		return err
204
+	}
205
+
206
+	container := b.runtime.Get(cid)
207
+	if container == nil {
208
+		return fmt.Errorf("Error while creating the container (CmdAdd)")
209
+	}
210
+
211
+	if err := os.MkdirAll(path.Join(container.rwPath(), dest), 0700); err != nil {
212
+		return err
213
+	}
214
+
215
+	origPath := path.Join(b.context, orig)
216
+	destPath := path.Join(container.rwPath(), dest)
217
+
218
+	fi, err := os.Stat(origPath)
219
+	if err != nil {
220
+		return err
221
+	}
222
+	if fi.IsDir() {
223
+		files, err := ioutil.ReadDir(path.Join(b.context, orig))
224
+		if err != nil {
225
+			return err
226
+		}
227
+		for _, fi := range files {
228
+			if err := utils.CopyDirectory(path.Join(origPath, fi.Name()), path.Join(destPath, fi.Name())); err != nil {
229
+				return err
230
+			}
231
+		}
232
+	} else {
233
+		if err := utils.CopyDirectory(origPath, destPath); err != nil {
234
+			return err
235
+		}
236
+	}
237
+
238
+	return b.commit(cid)
239
+}
240
+
241
+func (b *buildFile) run() (string, error) {
242
+	if b.image == "" {
243
+		return "", fmt.Errorf("Please provide a source image with `from` prior to run")
244
+	}
245
+	b.config.Image = b.image
246
+
247
+	// Create the container and start it
248
+	c, err := b.builder.Create(b.config)
249
+	if err != nil {
250
+		return "", err
251
+	}
252
+	b.tmpContainers[c.Id] = struct{}{}
253
+
254
+	//start the container
255
+	if err := c.Start(); err != nil {
256
+		return "", err
257
+	}
258
+
259
+	// Wait for it to finish
260
+	if ret := c.Wait(); ret != 0 {
261
+		return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, ret)
262
+	}
263
+
264
+	return c.Id, nil
265
+}
266
+
267
+func (b *buildFile) commit(id string) error {
268
+	if b.image == "" {
269
+		return fmt.Errorf("Please provide a source image with `from` prior to commit")
270
+	}
271
+	b.config.Image = b.image
272
+	if id == "" {
273
+		cmd := b.config.Cmd
274
+		b.config.Cmd = []string{"true"}
275
+		if cid, err := b.run(); err != nil {
276
+			return err
277
+		} else {
278
+			id = cid
279
+		}
280
+		b.config.Cmd = cmd
281
+	}
282
+
283
+	container := b.runtime.Get(id)
284
+	if container == nil {
285
+		return fmt.Errorf("An error occured while creating the container")
286
+	}
287
+
288
+	// Commit the container
289
+	image, err := b.builder.Commit(container, "", "", "", b.maintainer, nil)
290
+	if err != nil {
291
+		return err
292
+	}
293
+	b.tmpImages[image.Id] = struct{}{}
294
+	b.image = image.Id
295
+	b.needCommit = false
296
+	return nil
297
+}
298
+
299
+func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) {
300
+	defer b.clearTmp(b.tmpContainers, b.tmpImages)
301
+
302
+	if context != nil {
303
+		name, err := ioutil.TempDir("/tmp", "docker-build")
304
+		if err != nil {
305
+			return "", err
306
+		}
307
+		if err := Untar(context, name); err != nil {
308
+			return "", err
309
+		}
310
+		defer os.RemoveAll(name)
311
+		b.context = name
312
+	}
313
+	file := bufio.NewReader(dockerfile)
314
+	for {
315
+		line, err := file.ReadString('\n')
316
+		if err != nil {
317
+			if err == io.EOF {
318
+				break
319
+			}
320
+			return "", err
321
+		}
322
+		line = strings.Replace(strings.TrimSpace(line), "	", " ", 1)
323
+		// Skip comments and empty line
324
+		if len(line) == 0 || line[0] == '#' {
325
+			continue
326
+		}
327
+		tmp := strings.SplitN(line, " ", 2)
328
+		if len(tmp) != 2 {
329
+			return "", fmt.Errorf("Invalid Dockerfile format")
330
+		}
331
+		instruction := strings.ToLower(strings.Trim(tmp[0], " "))
332
+		arguments := strings.Trim(tmp[1], " ")
333
+
334
+		fmt.Fprintf(b.out, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image)
335
+
336
+		method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:]))
337
+		if !exists {
338
+			fmt.Fprintf(b.out, "Skipping unknown instruction %s\n", strings.ToUpper(instruction))
339
+		}
340
+		ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface()
341
+		if ret != nil {
342
+			return "", ret.(error)
343
+		}
344
+
345
+		fmt.Fprintf(b.out, "===> %v\n", b.image)
346
+	}
347
+	if b.needCommit {
348
+		if err := b.commit(""); err != nil {
349
+			return "", err
350
+		}
351
+	}
352
+	if b.image != "" {
353
+		// The build is successful, keep the temporary containers and images
354
+		for i := range b.tmpImages {
355
+			delete(b.tmpImages, i)
356
+		}
357
+		fmt.Fprintf(b.out, "Build success.\n Image id:\n%s\n", b.image)
358
+		return b.image, nil
359
+	}
360
+	for i := range b.tmpContainers {
361
+		delete(b.tmpContainers, i)
362
+	}
363
+	return "", fmt.Errorf("An error occured during the build\n")
364
+}
365
+
366
+func NewBuildFile(srv *Server, out io.Writer) BuildFile {
367
+	return &buildFile{
368
+		builder:       NewBuilder(srv.runtime),
369
+		runtime:       srv.runtime,
370
+		srv:           srv,
371
+		config:        &Config{},
372
+		out:           out,
373
+		tmpContainers: make(map[string]struct{}),
374
+		tmpImages:     make(map[string]struct{}),
375
+	}
376
+}
0 377
new file mode 100644
... ...
@@ -0,0 +1,72 @@
0
+package docker
1
+
2
+import (
3
+	"github.com/dotcloud/docker/utils"
4
+	"strings"
5
+	"testing"
6
+)
7
+
8
+const Dockerfile = `
9
+# VERSION		0.1
10
+# DOCKER-VERSION	0.2
11
+
12
+from   ` + unitTestImageName + `
13
+run    sh -c 'echo root:testpass > /tmp/passwd'
14
+run    mkdir -p /var/run/sshd
15
+`
16
+
17
+func TestBuild(t *testing.T) {
18
+	runtime, err := newTestRuntime()
19
+	if err != nil {
20
+		t.Fatal(err)
21
+	}
22
+	defer nuke(runtime)
23
+
24
+	srv := &Server{runtime: runtime}
25
+
26
+	buildfile := NewBuildFile(srv, &utils.NopWriter{})
27
+
28
+	imgId, err := buildfile.Build(strings.NewReader(Dockerfile), nil)
29
+	if err != nil {
30
+		t.Fatal(err)
31
+	}
32
+
33
+	builder := NewBuilder(runtime)
34
+	container, err := builder.Create(
35
+		&Config{
36
+			Image: imgId,
37
+			Cmd:   []string{"cat", "/tmp/passwd"},
38
+		},
39
+	)
40
+	if err != nil {
41
+		t.Fatal(err)
42
+	}
43
+	defer runtime.Destroy(container)
44
+
45
+	output, err := container.Output()
46
+	if err != nil {
47
+		t.Fatal(err)
48
+	}
49
+	if string(output) != "root:testpass\n" {
50
+		t.Fatalf("Unexpected output. Read '%s', expected '%s'", output, "root:testpass\n")
51
+	}
52
+
53
+	container2, err := builder.Create(
54
+		&Config{
55
+			Image: imgId,
56
+			Cmd:   []string{"ls", "-d", "/var/run/sshd"},
57
+		},
58
+	)
59
+	if err != nil {
60
+		t.Fatal(err)
61
+	}
62
+	defer runtime.Destroy(container2)
63
+
64
+	output, err = container2.Output()
65
+	if err != nil {
66
+		t.Fatal(err)
67
+	}
68
+	if string(output) != "/var/run/sshd\n" {
69
+		t.Fatal("/var/run/sshd has not been created")
70
+	}
71
+}
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"github.com/dotcloud/docker/utils"
11 11
 	"io"
12 12
 	"io/ioutil"
13
+	"mime/multipart"
13 14
 	"net"
14 15
 	"net/http"
15 16
 	"net/http/httputil"
... ...
@@ -74,7 +75,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
74 74
 	help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n  -H=\"%s:%d\": Host:port to bind/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", cli.host, cli.port)
75 75
 	for cmd, description := range map[string]string{
76 76
 		"attach":  "Attach to a running container",
77
-		"build":   "Build a container from Dockerfile or via stdin",
77
+		"build":   "Build a container from a Dockerfile",
78 78
 		"commit":  "Create a new image from a container's changes",
79 79
 		"diff":    "Inspect changes on a container's filesystem",
80 80
 		"export":  "Stream the contents of a container as a tar archive",
... ...
@@ -122,39 +123,104 @@ func (cli *DockerCli) CmdInsert(args ...string) error {
122 122
 	v.Set("url", cmd.Arg(1))
123 123
 	v.Set("path", cmd.Arg(2))
124 124
 
125
-	err := cli.stream("POST", "/images/"+cmd.Arg(0)+"/insert?"+v.Encode(), nil, os.Stdout)
126
-	if err != nil {
125
+	if err := cli.stream("POST", "/images/"+cmd.Arg(0)+"/insert?"+v.Encode(), nil, os.Stdout); err != nil {
127 126
 		return err
128 127
 	}
129 128
 	return nil
130 129
 }
131 130
 
132 131
 func (cli *DockerCli) CmdBuild(args ...string) error {
133
-	cmd := Subcmd("build", "-|Dockerfile", "Build an image from Dockerfile or via stdin")
132
+	cmd := Subcmd("build", "[OPTIONS] [CONTEXT]", "Build an image from a Dockerfile")
133
+	fileName := cmd.String("f", "Dockerfile", "Use `file` as Dockerfile. Can be '-' for stdin")
134 134
 	if err := cmd.Parse(args); err != nil {
135 135
 		return nil
136 136
 	}
137
+
137 138
 	var (
138
-		file io.ReadCloser
139
-		err  error
139
+		file          io.ReadCloser
140
+		multipartBody io.Reader
141
+		err           error
140 142
 	)
141 143
 
142
-	if cmd.NArg() == 0 {
143
-		file, err = os.Open("Dockerfile")
144
+	// Init the needed component for the Multipart
145
+	buff := bytes.NewBuffer([]byte{})
146
+	multipartBody = buff
147
+	w := multipart.NewWriter(buff)
148
+	boundary := strings.NewReader("\r\n--" + w.Boundary() + "--\r\n")
149
+
150
+	// Create a FormFile multipart for the Dockerfile
151
+	if *fileName == "-" {
152
+		file = os.Stdin
153
+	} else {
154
+		file, err = os.Open(*fileName)
144 155
 		if err != nil {
145 156
 			return err
146 157
 		}
147
-	} else if cmd.Arg(0) == "-" {
148
-		file = os.Stdin
158
+		defer file.Close()
159
+	}
160
+	if wField, err := w.CreateFormFile("Dockerfile", *fileName); err != nil {
161
+		return err
149 162
 	} else {
150
-		file, err = os.Open(cmd.Arg(0))
163
+		io.Copy(wField, file)
164
+	}
165
+	multipartBody = io.MultiReader(multipartBody, boundary)
166
+
167
+	compression := Bzip2
168
+
169
+	// Create a FormFile multipart for the context if needed
170
+	if cmd.Arg(0) != "" {
171
+		// FIXME: Use NewTempArchive in order to have the size and avoid too much memory usage?
172
+		context, err := Tar(cmd.Arg(0), compression)
151 173
 		if err != nil {
152 174
 			return err
153 175
 		}
176
+		// NOTE: Do this in case '.' or '..' is input
177
+		absPath, err := filepath.Abs(cmd.Arg(0))
178
+		if err != nil {
179
+			return err
180
+		}
181
+		if wField, err := w.CreateFormFile("Context", filepath.Base(absPath)+"."+compression.Extension()); err != nil {
182
+			return err
183
+		} else {
184
+			// FIXME: Find a way to have a progressbar for the upload too
185
+			sf := utils.NewStreamFormatter(false)
186
+			io.Copy(wField, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, sf.FormatProgress("Caching Context", "%v/%v (%v)"), sf))
187
+		}
188
+
189
+		multipartBody = io.MultiReader(multipartBody, boundary)
154 190
 	}
155
-	if _, err := NewBuilderClient("0.0.0.0", 4243).Build(file); err != nil {
191
+
192
+	// Send the multipart request with correct content-type
193
+	req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), multipartBody)
194
+	if err != nil {
156 195
 		return err
157 196
 	}
197
+	req.Header.Set("Content-Type", w.FormDataContentType())
198
+	if cmd.Arg(0) != "" {
199
+		req.Header.Set("X-Docker-Context-Compression", compression.Flag())
200
+		fmt.Println("Uploading Context...")
201
+	}
202
+
203
+	resp, err := http.DefaultClient.Do(req)
204
+	if err != nil {
205
+		return err
206
+	}
207
+	defer resp.Body.Close()
208
+
209
+	// Check for errors
210
+	if resp.StatusCode < 200 || resp.StatusCode >= 400 {
211
+		body, err := ioutil.ReadAll(resp.Body)
212
+		if err != nil {
213
+			return err
214
+		}
215
+		return fmt.Errorf("error: %s", body)
216
+	}
217
+
218
+	// Output the result
219
+	if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
220
+		return err
221
+	}
222
+
158 223
 	return nil
159 224
 }
160 225
 
... ...
@@ -788,7 +854,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
788 788
 		v.Set("before", *before)
789 789
 	}
790 790
 
791
-	body, _, err := cli.call("GET", "/containers/ps?"+v.Encode(), nil)
791
+	body, _, err := cli.call("GET", "/containers/json?"+v.Encode(), nil)
792 792
 	if err != nil {
793 793
 		return err
794 794
 	}
... ...
@@ -806,9 +872,9 @@ func (cli *DockerCli) CmdPs(args ...string) error {
806 806
 	for _, out := range outs {
807 807
 		if !*quiet {
808 808
 			if *noTrunc {
809
-				fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, out.Status, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports)
809
+				fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\n", out.Id, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
810 810
 			} else {
811
-				fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", utils.TruncateId(out.Id), out.Image, utils.Trunc(out.Command, 20), out.Status, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports)
811
+				fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\n", utils.TruncateId(out.Id), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
812 812
 			}
813 813
 		} else {
814 814
 			if *noTrunc {
815 815
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+# Maintainer wanted! Enroll on #docker@freenode
0 1
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+Solomon Hykes <solomon@dotcloud.com>
0 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+Andy Rothfusz <andy@dotcloud.com>
1
+Ken Cochrane <ken@dotcloud.com>
0 2
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+Solomon Hykes <solomon@dotcloud.com>
... ...
@@ -31,7 +31,7 @@ You can still call an old version of the api using /v1.0/images/<name>/insert
31 31
 List containers
32 32
 ***************
33 33
 
34
-.. http:get:: /containers/ps
34
+.. http:get:: /containers/json
35 35
 
36 36
 	List containers
37 37
 
... ...
@@ -39,7 +39,7 @@ List containers
39 39
 
40 40
 	.. sourcecode:: http
41 41
 
42
-	   GET /containers/ps?all=1&before=8dfafdbc3a40 HTTP/1.1
42
+	   GET /containers/json?all=1&before=8dfafdbc3a40 HTTP/1.1
43 43
 	   
44 44
 	**Example response**:
45 45
 
... ...
@@ -385,7 +385,7 @@ Attach to a container
385 385
 
386 386
 .. http:post:: /containers/(id)/attach
387 387
 
388
-	Stop the container ``id``
388
+	Attach to the container ``id``
389 389
 
390 390
 	**Example request**:
391 391
 
... ...
@@ -5,101 +5,5 @@
5 5
 Contributing to Docker
6 6
 ======================
7 7
 
8
-Want to hack on Docker? Awesome! There are instructions to get you
9
-started on the website: http://docker.io/gettingstarted.html
8
+Want to hack on Docker? Awesome! The repository includes `all the instructions you need to get started <https://github.com/dotcloud/docker/blob/master/CONTRIBUTING.md>`.
10 9
 
11
-They are probably not perfect, please let us know if anything feels
12
-wrong or incomplete.
13
-
14
-Contribution guidelines
15
-
16
-Pull requests are always welcome
17
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
-
19
-We are always thrilled to receive pull requests, and do our best to
20
-process them as fast as possible. Not sure if that typo is worth a pull
21
-request? Do it! We will appreciate it.
22
-
23
-If your pull request is not accepted on the first try, don't be
24
-discouraged! If there's a problem with the implementation, hopefully you
25
-received feedback on what to improve.
26
-
27
-We're trying very hard to keep Docker lean and focused. We don't want it
28
-to do everything for everybody. This means that we might decide against
29
-incorporating a new feature. However, there might be a way to implement
30
-that feature *on top of* docker.
31
-
32
-Discuss your design on the mailing list
33
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34
-
35
-We recommend discussing your plans `on the mailing
36
-list <https://groups.google.com/forum/?fromgroups#!forum/docker-club>`__
37
-before starting to code - especially for more ambitious contributions.
38
-This gives other contributors a chance to point you in the right
39
-direction, give feedback on your design, and maybe point out if someone
40
-else is working on the same thing.
41
-
42
-Create issues...
43
-~~~~~~~~~~~~~~~~
44
-
45
-Any significant improvement should be documented as `a github
46
-issue <https://github.com/dotcloud/docker/issues>`__ before anybody
47
-starts working on it.
48
-
49
-...but check for existing issues first!
50
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51
-
52
-Please take a moment to check that an issue doesn't already exist
53
-documenting your bug report or improvement proposal. If it does, it
54
-never hurts to add a quick "+1" or "I have this problem too". This will
55
-help prioritize the most common problems and requests.
56
-
57
-Conventions
58
-~~~~~~~~~~~
59
-
60
-Fork the repo and make changes on your fork in a feature branch:
61
-
62
-- If it's a bugfix branch, name it XXX-something where XXX is the number of the
63
-  issue
64
-- If it's a feature branch, create an enhancement issue to announce your
65
-  intentions, and name it XXX-something where XXX is the number of the issue.
66
-
67
-Submit unit tests for your changes.  Go has a great test framework built in; use
68
-it! Take a look at existing tests for inspiration. Run the full test suite on
69
-your branch before submitting a pull request.
70
-
71
-Make sure you include relevant updates or additions to documentation when
72
-creating or modifying features.
73
-
74
-Write clean code. Universally formatted code promotes ease of writing, reading,
75
-and maintenance. Always run ``go fmt`` before committing your changes. Most
76
-editors have plugins that do this automatically, and there's also a git
77
-pre-commit hook:
78
-
79
-.. code-block:: bash
80
-
81
-    curl -o .git/hooks/pre-commit https://raw.github.com/edsrzf/gofmt-git-hook/master/fmt-check && chmod +x .git/hooks/pre-commit
82
-
83
-
84
-Pull requests descriptions should be as clear as possible and include a
85
-reference to all the issues that they address.
86
-
87
-Code review comments may be added to your pull request. Discuss, then make the
88
-suggested modifications and push additional commits to your feature branch. Be
89
-sure to post a comment after pushing. The new commits will show up in the pull
90
-request automatically, but the reviewers will not be notified unless you
91
-comment.
92
-
93
-Before the pull request is merged, make sure that you squash your commits into
94
-logical units of work using ``git rebase -i`` and ``git push -f``. After every
95
-commit the test suite should be passing. Include documentation changes in the
96
-same commit so that a revert would remove all traces of the feature or fix.
97
-
98
-Commits that fix or close an issue should include a reference like ``Closes #XXX``
99
-or ``Fixes #XXX``, which will automatically close the issue when merged.
100
-
101
-Add your name to the AUTHORS file, but make sure the list is sorted and your
102
-name and email address match your git configuration. The AUTHORS file is
103
-regenerated occasionally from the git commit history, so a mismatch may result
104
-in your changes being overwritten.
... ...
@@ -27,7 +27,7 @@ But we know people have had success running it under
27 27
 Dependencies:
28 28
 -------------
29 29
 
30
-* 3.8 Kernel
30
+* 3.8 Kernel (read more about :ref:`kernel`)
31 31
 * AUFS filesystem support
32 32
 * lxc
33 33
 * bsdtar
... ...
@@ -16,7 +16,7 @@ Right now, the officially supported distribution are:
16 16
 
17 17
 Docker has the following dependencies
18 18
 
19
-* Linux kernel 3.8
19
+* Linux kernel 3.8 (read more about :ref:`kernel`)
20 20
 * AUFS file system support (we are working on BTRFS support as an alternative)
21 21
 
22 22
 .. _ubuntu_precise:
... ...
@@ -54,9 +54,9 @@ which makes installing Docker on Ubuntu very easy.
54 54
 .. code-block:: bash
55 55
 
56 56
    # Add the PPA sources to your apt sources list.
57
-   sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' > /etc/apt/sources.list.d/lxc-docker.list"
57
+   sudo apt-get install python-software-properties && sudo add-apt-repository ppa:dotcloud/lxc-docker
58 58
 
59
-   # Update your sources, you will see a warning.
59
+   # Update your sources
60 60
    sudo apt-get update
61 61
 
62 62
    # Install, you will see another warning that the package cannot be authenticated. Confirm install.
... ...
@@ -25,9 +25,9 @@ Installation
25 25
 The module is available on the `Puppet Forge <https://forge.puppetlabs.com/garethr/docker/>`_
26 26
 and can be installed using the built-in module tool.
27 27
 
28
-   .. code-block:: bash
28
+.. code-block:: bash
29 29
 
30
-      puppet module install garethr/docker
30
+   puppet module install garethr/docker
31 31
 
32 32
 It can also be found on `GitHub <https://www.github.com/garethr/garethr-docker>`_ 
33 33
 if you would rather download the source.
... ...
@@ -41,9 +41,9 @@ for managing images and containers.
41 41
 Installation
42 42
 ~~~~~~~~~~~~
43 43
 
44
-   .. code-block:: ruby
44
+.. code-block:: ruby
45 45
 
46
-      include 'docker'
46
+  include 'docker'
47 47
 
48 48
 Images
49 49
 ~~~~~~
... ...
@@ -51,26 +51,26 @@ Images
51 51
 The next step is probably to install a docker image, for this we have a
52 52
 defined type which can be used like so:
53 53
 
54
-   .. code-block:: ruby
54
+.. code-block:: ruby
55 55
 
56
-      docker::image { 'base': }
56
+  docker::image { 'base': }
57 57
 
58 58
 This is equivalent to running:
59 59
 
60
-   .. code-block:: bash
60
+.. code-block:: bash
61 61
 
62
-      docker pull base
62
+  docker pull base
63 63
 
64 64
 Note that it will only if the image of that name does not already exist.
65 65
 This is downloading a large binary so on first run can take a while.
66 66
 For that reason this define turns off the default 5 minute timeout
67 67
 for exec. Note that you can also remove images you no longer need with:
68 68
 
69
-   .. code-block:: ruby
69
+.. code-block:: ruby
70 70
 
71
-      docker::image { 'base':
72
-        ensure => 'absent',
73
-      }
71
+  docker::image { 'base':
72
+    ensure => 'absent',
73
+  }
74 74
 
75 75
 Containers
76 76
 ~~~~~~~~~~
... ...
@@ -78,35 +78,35 @@ Containers
78 78
 Now you have an image you can run commands within a container managed by
79 79
 docker.
80 80
 
81
-   .. code-block:: ruby
81
+.. code-block:: ruby
82 82
 
83
-      docker::run { 'helloworld':
84
-        image   => 'base',
85
-        command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
86
-      }
83
+  docker::run { 'helloworld':
84
+    image   => 'base',
85
+    command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
86
+  }
87 87
 
88 88
 This is equivalent to running the following command, but under upstart:
89 89
 
90
-   .. code-block:: bash
90
+.. code-block:: bash
91 91
 
92
-      docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done"
92
+  docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done"
93 93
 
94 94
 Run also contains a number of optional parameters:
95 95
 
96
-   .. code-block:: ruby
97
-
98
-      docker::run { 'helloworld':
99
-        image        => 'base',
100
-        command      => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
101
-        ports        => ['4444', '4555'],
102
-        volumes      => ['/var/lib/counchdb', '/var/log'],
103
-        volumes_from => '6446ea52fbc9',
104
-        memory_limit => 10485760, # bytes 
105
-        username     => 'example',
106
-        hostname     => 'example.com',
107
-        env          => ['FOO=BAR', 'FOO2=BAR2'],
108
-        dns          => ['8.8.8.8', '8.8.4.4'],
109
-      }
96
+.. code-block:: ruby
97
+
98
+  docker::run { 'helloworld':
99
+    image        => 'base',
100
+    command      => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
101
+    ports        => ['4444', '4555'],
102
+    volumes      => ['/var/lib/counchdb', '/var/log'],
103
+    volumes_from => '6446ea52fbc9',
104
+    memory_limit => 10485760, # bytes
105
+    username     => 'example',
106
+    hostname     => 'example.com',
107
+    env          => ['FOO=BAR', 'FOO2=BAR2'],
108
+    dns          => ['8.8.8.8', '8.8.4.4'],
109
+  }
110 110
 
111 111
 Note that ports, env, dns and volumes can be set with either a single string
112 112
 or as above with an array of values.
113 113
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+Thatcher Penskens <thatcher@dotcloud.com>
0 1
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+Thatcher Penskens <thatcher@dotcloud.com>
... ...
@@ -89,9 +89,10 @@
89 89
                     <li>
90 90
                         <p><strong>Install Docker</strong></p>
91 91
                         <p>Add the Ubuntu PPA (Personal Package Archive) sources to your apt sources list, update and install.</p>
92
-                        <p>You may see some warnings that the GPG keys cannot be verified.</p>
92
+                        <p>This may import a new GPG key (key 63561DC6: public key "Launchpad PPA for dotcloud team" imported).</p>
93 93
                         <div class="highlight">
94
-                            <pre>sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' >> /etc/apt/sources.list"</pre>
94
+                            <pre>sudo apt-get install software-properties-common</pre>
95
+                            <pre>sudo add-apt-repository ppa:dotcloud/lxc-docker</pre>
95 96
                             <pre>sudo apt-get update</pre>
96 97
                             <pre>sudo apt-get install lxc-docker</pre>
97 98
                         </div>
98 99
new file mode 100755
... ...
@@ -0,0 +1,3 @@
0
+#!/bin/sh
1
+
2
+find $1 -name MAINTAINERS -exec cat {} ';' | sed -E -e 's/^[^:]*: *(.*)$/\1/' | grep -E -v -e '^ *$' -e '^ *#.*$' | sort -u
0 3
new file mode 100755
... ...
@@ -0,0 +1,58 @@
0
+#!/bin/sh
1
+
2
+if [ $# -ne 1 ]; then
3
+	echo >&2 "Usage: $0 PATH"
4
+	echo >&2 "Show the primary and secondary maintainers for a given path"
5
+	exit 1
6
+fi
7
+
8
+set -e
9
+
10
+DEST=$1
11
+DESTFILE=""
12
+if [ ! -d $DEST ]; then
13
+	DESTFILE=$(basename $DEST)
14
+	DEST=$(dirname $DEST)
15
+fi
16
+
17
+MAINTAINERS=()
18
+cd $DEST
19
+while true; do
20
+	if [ -e ./MAINTAINERS ]; then
21
+		{
22
+			while read line; do
23
+				re='^([^:]*): *(.*)$'
24
+				file=$(echo $line | sed -E -n "s/$re/\1/p")
25
+				if [ ! -z "$file" ]; then
26
+					if [ "$file" = "$DESTFILE" ]; then
27
+						echo "Override: $line"
28
+						maintainer=$(echo $line | sed -E -n "s/$re/\2/p")
29
+						MAINTAINERS=("$maintainer" "${MAINTAINERS[@]}")
30
+					fi
31
+				else
32
+					MAINTAINERS+=("$line");
33
+				fi
34
+			done;
35
+		} < MAINTAINERS
36
+	fi
37
+	if [ -d .git ]; then
38
+		break
39
+	fi
40
+	if [ "$(pwd)" = "/" ]; then
41
+		break
42
+	fi
43
+	cd ..
44
+done
45
+
46
+PRIMARY="${MAINTAINERS[0]}"
47
+PRIMARY_FIRSTNAME=$(echo $PRIMARY | cut -d' ' -f1)
48
+
49
+firstname() {
50
+	echo $1 | cut -d' ' -f1
51
+}
52
+
53
+echo "--- $PRIMARY is the PRIMARY MAINTAINER of $1. Assign pull requests to him."
54
+echo "$(firstname $PRIMARY) may assign pull requests to the following secondary maintainers:"
55
+for SECONDARY in "${MAINTAINERS[@]:1}"; do
56
+	echo "--- $SECONDARY"
57
+done
0 58
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+Daniel Mizyrycki <daniel@dotcloud.com>
0 1
new file mode 100644
... ...
@@ -0,0 +1,3 @@
0
+Sam Alba <sam@dotcloud.com>
1
+Joffrey Fuhrer <joffrey@dotcloud.com>
2
+Ken Cochrane <ken@dotcloud.com>
... ...
@@ -8,7 +8,6 @@ import (
8 8
 	"io/ioutil"
9 9
 	"net"
10 10
 	"os"
11
-	"os/exec"
12 11
 	"os/user"
13 12
 	"sync"
14 13
 	"testing"
... ...
@@ -32,13 +31,6 @@ func nuke(runtime *Runtime) error {
32 32
 	return os.RemoveAll(runtime.root)
33 33
 }
34 34
 
35
-func CopyDirectory(source, dest string) error {
36
-	if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil {
37
-		return err
38
-	}
39
-	return nil
40
-}
41
-
42 35
 func layerArchive(tarfile string) (io.Reader, error) {
43 36
 	// FIXME: need to close f somewhere
44 37
 	f, err := os.Open(tarfile)
... ...
@@ -90,7 +82,7 @@ func newTestRuntime() (*Runtime, error) {
90 90
 	if err := os.Remove(root); err != nil {
91 91
 		return nil, err
92 92
 	}
93
-	if err := CopyDirectory(unitTestStoreBase, root); err != nil {
93
+	if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil {
94 94
 		return nil, err
95 95
 	}
96 96
 
... ...
@@ -347,7 +339,7 @@ func TestRestore(t *testing.T) {
347 347
 	if err := os.Remove(root); err != nil {
348 348
 		t.Fatal(err)
349 349
 	}
350
-	if err := CopyDirectory(unitTestStoreBase, root); err != nil {
350
+	if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil {
351 351
 		t.Fatal(err)
352 352
 	}
353 353
 
... ...
@@ -67,40 +67,40 @@ func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
67 67
 	return outs, nil
68 68
 }
69 69
 
70
-func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.StreamFormatter) error {
70
+func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.StreamFormatter) (string, error) {
71 71
 	out = utils.NewWriteFlusher(out)
72 72
 	img, err := srv.runtime.repositories.LookupImage(name)
73 73
 	if err != nil {
74
-		return err
74
+		return "", err
75 75
 	}
76 76
 
77 77
 	file, err := utils.Download(url, out)
78 78
 	if err != nil {
79
-		return err
79
+		return "", err
80 80
 	}
81 81
 	defer file.Body.Close()
82 82
 
83 83
 	config, _, err := ParseRun([]string{img.Id, "echo", "insert", url, path}, srv.runtime.capabilities)
84 84
 	if err != nil {
85
-		return err
85
+		return "", err
86 86
 	}
87 87
 
88 88
 	b := NewBuilder(srv.runtime)
89 89
 	c, err := b.Create(config)
90 90
 	if err != nil {
91
-		return err
91
+		return "", err
92 92
 	}
93 93
 
94 94
 	if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, sf.FormatProgress("Downloading", "%v/%v (%v)"), sf), path); err != nil {
95
-		return err
95
+		return "", err
96 96
 	}
97 97
 	// FIXME: Handle custom repo, tag comment, author
98 98
 	img, err = b.Commit(c, "", "", img.Comment, img.Author, nil)
99 99
 	if err != nil {
100
-		return err
100
+		return "", err
101 101
 	}
102 102
 	out.Write(sf.FormatStatus(img.Id))
103
-	return nil
103
+	return img.ShortId(), nil
104 104
 }
105 105
 
106 106
 func (srv *Server) ImagesViz(out io.Writer) error {
107 107
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+Daniel Mizyrycki <daniel@dotcloud.com>
... ...
@@ -534,6 +534,13 @@ func GetKernelVersion() (*KernelVersionInfo, error) {
534 534
 	}, nil
535 535
 }
536 536
 
537
+func CopyDirectory(source, dest string) error {
538
+	if output, err := exec.Command("cp", "-ra", source, dest).CombinedOutput(); err != nil {
539
+		return fmt.Errorf("Error copy: %s (%s)", err, output)
540
+	}
541
+	return nil
542
+}
543
+
537 544
 type NopFlusher struct{}
538 545
 
539 546
 func (f *NopFlusher) Flush() {}
... ...
@@ -613,5 +620,3 @@ func (sf *StreamFormatter) FormatProgress(action, str string) []byte {
613 613
 func (sf *StreamFormatter) Used() bool {
614 614
 	return sf.used
615 615
 }
616
-
617
-