From 0f135ad7f31df2952352feb9ef00863d61577467 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 22 May 2013 20:07:26 -0700 Subject: [PATCH 01/42] Start moving the docker builder into the server --- api.go | 80 ++++++++++++++++++++++++++++++++++++++++++++++- builder_client.go | 35 +++++++++++++-------- commands.go | 50 +++++++++++++++++++++++++++-- server.go | 16 +++++----- 4 files changed, 157 insertions(+), 24 deletions(-) diff --git a/api.go b/api.go index 29103fac10..5812743dfe 100644 --- a/api.go +++ b/api.go @@ -1,6 +1,7 @@ package docker import ( + "bytes" "encoding/json" "fmt" "github.com/dotcloud/docker/auth" @@ -9,6 +10,7 @@ import ( "io" "log" "net/http" + "os" "strconv" "strings" ) @@ -31,6 +33,13 @@ func parseForm(r *http.Request) error { return nil } +func parseMultipartForm(r *http.Request) error { + if err := r.ParseMultipartForm(4096); err != nil && !strings.HasPrefix(err.Error(), "mime:") { + return err + } + return nil +} + func httpError(w http.ResponseWriter, err error) { if strings.HasPrefix(err.Error(), "No such") { http.Error(w, err.Error(), http.StatusNotFound) @@ -329,9 +338,15 @@ func postImagesInsert(srv *Server, w http.ResponseWriter, r *http.Request, vars } name := vars["name"] - if err := srv.ImageInsert(name, url, path, w); err != nil { + imgId, err := srv.ImageInsert(name, url, path, w) + if err != nil { return err } + b, err := json.Marshal(&ApiId{Id: imgId}) + if err != nil { + return err + } + writeJson(w, b) return nil } @@ -585,6 +600,68 @@ func postImagesGetCache(srv *Server, w http.ResponseWriter, r *http.Request, var return nil } +func Upload(w http.ResponseWriter, req *http.Request) { + + mr, err := req.MultipartReader() + if err != nil { + return + } + length := req.ContentLength + for { + + part, err := mr.NextPart() + if err == io.EOF { + break + } + var read int64 + var p float32 + for { + buffer := make([]byte, 100000) + cBytes, err := part.Read(buffer) + if err == io.EOF { + break + } + read = read + int64(cBytes) + //fmt.Printf("read: %v \n",read ) + p = float32(read) / float32(length) * 100 + fmt.Printf("progress: %v \n", p) + os.Stdout.Write(buffer) + } + } +} + +func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { + + Upload(w, r) + + // io.Copy(os.Stderr, r.Body) + + if err := r.ParseMultipartForm(409699); err != nil { + utils.Debugf("----- %s\n", err) + return err + } + + mpr, err := r.MultipartReader() + if err != nil { + return err + } + + p, err := mpr.NextPart() + if err != nil { + return err + } + + dockerfile := make([]byte, 4096) + p.Read(dockerfile) + + utils.Debugf("Dockerfile >>>%s<<<\n", dockerfile) + b := NewBuildFile(srv, w) + if _, err := b.Build(bytes.NewReader(dockerfile)); err != nil { + return err + } + return nil +} + func ListenAndServe(addr string, srv *Server, logging bool) error { r := mux.NewRouter() log.Printf("Listening for HTTP on %s\n", addr) @@ -607,6 +684,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { "POST": { "/auth": postAuth, "/commit": postCommit, + "/build": postBuild, "/images/create": postImagesCreate, "/images/{name:.*}/insert": postImagesInsert, "/images/{name:.*}/push": postImagesPush, diff --git a/builder_client.go b/builder_client.go index ceeab002c9..e0a55ae6c9 100644 --- a/builder_client.go +++ b/builder_client.go @@ -12,12 +12,6 @@ import ( "strings" ) -type BuilderClient interface { - Build(io.Reader) (string, error) - CmdFrom(string) error - CmdRun(string) error -} - type builderClient struct { cli *DockerCli @@ -164,8 +158,23 @@ func (b *builderClient) CmdExpose(args string) error { } func (b *builderClient) CmdInsert(args string) error { - // FIXME: Reimplement this once the remove_hijack branch gets merged. - // We need to retrieve the resulting Id + // tmp := strings.SplitN(args, "\t ", 2) + // sourceUrl, destPath := tmp[0], tmp[1] + + // v := url.Values{} + // v.Set("url", sourceUrl) + // v.Set("path", destPath) + // body, _, err := b.cli.call("POST", "/images/insert?"+v.Encode(), nil) + // if err != nil { + // return err + // } + + // apiId := &ApiId{} + // if err := json.Unmarshal(body, apiId); err != nil { + // return err + // } + + // FIXME: Reimplement this, we need to retrieve the resulting Id return fmt.Errorf("INSERT not implemented") } @@ -269,18 +278,18 @@ func (b *builderClient) Build(dockerfile io.Reader) (string, error) { instruction := strings.ToLower(strings.Trim(tmp[0], " ")) arguments := strings.Trim(tmp[1], " ") - fmt.Printf("%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image) + fmt.Fprintf(os.Stderr, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image) method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:])) if !exists { - fmt.Printf("Skipping unknown instruction %s\n", strings.ToUpper(instruction)) + fmt.Fprintf(os.Stderr, "Skipping unknown instruction %s\n", strings.ToUpper(instruction)) } ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface() if ret != nil { return "", ret.(error) } - fmt.Printf("===> %v\n", b.image) + fmt.Fprintf(os.Stderr, "===> %v\n", b.image) } if b.needCommit { if err := b.commit(""); err != nil { @@ -295,13 +304,13 @@ func (b *builderClient) Build(dockerfile io.Reader) (string, error) { for i := range b.tmpContainers { delete(b.tmpContainers, i) } - fmt.Printf("Build finished. image id: %s\n", b.image) + fmt.Fprintf(os.Stderr, "Build finished. image id: %s\n", b.image) return b.image, nil } return "", fmt.Errorf("An error occured during the build\n") } -func NewBuilderClient(addr string, port int) BuilderClient { +func NewBuilderClient(addr string, port int) BuildFile { return &builderClient{ cli: NewDockerCli(addr, port), config: &Config{}, diff --git a/commands.go b/commands.go index 5e459a1d94..4291b1d8de 100644 --- a/commands.go +++ b/commands.go @@ -10,6 +10,7 @@ import ( "github.com/dotcloud/docker/utils" "io" "io/ioutil" + "mime/multipart" "net" "net/http" "net/http/httputil" @@ -104,14 +105,59 @@ func (cli *DockerCli) CmdInsert(args ...string) error { v.Set("url", cmd.Arg(1)) v.Set("path", cmd.Arg(2)) - err := cli.stream("POST", "/images/"+cmd.Arg(0)+"/insert?"+v.Encode(), nil, os.Stdout) - if err != nil { + if err := cli.stream("POST", "/images/"+cmd.Arg(0)+"/insert?"+v.Encode(), nil, os.Stdout); err != nil { return err } return nil } func (cli *DockerCli) CmdBuild(args ...string) error { + + buff := bytes.NewBuffer([]byte{}) + + w := multipart.NewWriter(buff) + + dockerfile, err := w.CreateFormFile("Dockerfile", "Dockerfile") + if err != nil { + return err + } + file, err := os.Open("Dockerfile") + if err != nil { + return err + } + dockerfile.Write([]byte(w.Boundary() + "\r\n")) + if _, err := io.Copy(dockerfile, file); err != nil { + return err + } + dockerfile.Write([]byte("\r\n" + w.Boundary())) + + // req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), buff) + // if err != nil { + // return err + // } + // req.Header.Set("Content-Type", w.FormDataContentType()) + resp, err := http.Post(fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), w.FormDataContentType(), buff) + if err != nil { + return err + } + defer resp.Body.Close() + + if resp.StatusCode < 200 || resp.StatusCode >= 400 { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return err + } + return fmt.Errorf("error: %s", body) + } + + if _, err := io.Copy(os.Stdout, resp.Body); err != nil { + return err + } + + return nil +} + +func (cli *DockerCli) CmdBuildClient(args ...string) error { cmd := Subcmd("build", "-|Dockerfile", "Build an image from Dockerfile or via stdin") if err := cmd.Parse(args); err != nil { return nil diff --git a/server.go b/server.go index 564b1c812d..06f947d89f 100644 --- a/server.go +++ b/server.go @@ -67,40 +67,40 @@ func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) { return outs, nil } -func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error { +func (srv *Server) ImageInsert(name, url, path string, out io.Writer) (string, error) { out = utils.NewWriteFlusher(out) img, err := srv.runtime.repositories.LookupImage(name) if err != nil { - return err + return "", err } file, err := utils.Download(url, out) if err != nil { - return err + return "", err } defer file.Body.Close() config, _, err := ParseRun([]string{img.Id, "echo", "insert", url, path}, srv.runtime.capabilities) if err != nil { - return err + return "", err } b := NewBuilder(srv.runtime) c, err := b.Create(config) if err != nil { - return err + return "", err } if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, "Downloading %v/%v (%v)"), path); err != nil { - return err + return "", err } // FIXME: Handle custom repo, tag comment, author img, err = b.Commit(c, "", "", img.Comment, img.Author, nil) if err != nil { - return err + return "", err } fmt.Fprintf(out, "%s\n", img.Id) - return nil + return img.ShortId(), nil } func (srv *Server) ImagesViz(out io.Writer) error { From d42c10aa094e39d8c1184b61c98777d8c59ae900 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 23 May 2013 18:32:56 -0700 Subject: [PATCH 02/42] Implement Context within docker build (not yet in use) --- api.go | 23 +++++----------- builder_client.go | 2 +- commands.go | 70 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/api.go b/api.go index 5812743dfe..0a65543b79 100644 --- a/api.go +++ b/api.go @@ -1,7 +1,6 @@ package docker import ( - "bytes" "encoding/json" "fmt" "github.com/dotcloud/docker/auth" @@ -631,32 +630,24 @@ func Upload(w http.ResponseWriter, req *http.Request) { } func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - - Upload(w, r) - - // io.Copy(os.Stderr, r.Body) - - if err := r.ParseMultipartForm(409699); err != nil { - utils.Debugf("----- %s\n", err) + if err := r.ParseMultipartForm(4096); err != nil { return err } - mpr, err := r.MultipartReader() + file, _, err := r.FormFile("Dockerfile") if err != nil { return err } - p, err := mpr.NextPart() + context, _, err := r.FormFile("Context") if err != nil { - return err + if err != http.ErrMissingFile { + return err + } } - dockerfile := make([]byte, 4096) - p.Read(dockerfile) - - utils.Debugf("Dockerfile >>>%s<<<\n", dockerfile) b := NewBuildFile(srv, w) - if _, err := b.Build(bytes.NewReader(dockerfile)); err != nil { + if _, err := b.Build(file, context); err != nil { return err } return nil diff --git a/builder_client.go b/builder_client.go index e0a55ae6c9..0b511ee218 100644 --- a/builder_client.go +++ b/builder_client.go @@ -255,7 +255,7 @@ func (b *builderClient) commit(id string) error { return nil } -func (b *builderClient) Build(dockerfile io.Reader) (string, error) { +func (b *builderClient) Build(dockerfile, context io.Reader) (string, error) { defer b.clearTmp(b.tmpContainers, b.tmpImages) file := bufio.NewReader(dockerfile) for { diff --git a/commands.go b/commands.go index 4291b1d8de..f5c658e6b1 100644 --- a/commands.go +++ b/commands.go @@ -57,7 +57,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error { help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n" for cmd, description := range map[string]string{ "attach": "Attach to a running container", - "build": "Build a container from Dockerfile or via stdin", + "build": "Build a container from a Dockerfile", "commit": "Create a new image from a container's changes", "diff": "Inspect changes on a container's filesystem", "export": "Stream the contents of a container as a tar archive", @@ -112,36 +112,67 @@ func (cli *DockerCli) CmdInsert(args ...string) error { } func (cli *DockerCli) CmdBuild(args ...string) error { + cmd := Subcmd("build", "[OPTIONS]", "Build an image from a Dockerfile") + fileName := cmd.String("f", "Dockerfile", "Use file as Dockerfile. Can be '-' for stdin") + contextPath := cmd.String("c", "", "Use the specified directory as context for the build") + if err := cmd.Parse(args); err != nil { + return nil + } + var ( + file io.ReadCloser + multipartBody io.Reader + err error + ) + + // Init the needed component for the Multipart buff := bytes.NewBuffer([]byte{}) - + multipartBody = buff w := multipart.NewWriter(buff) + boundary := strings.NewReader("\r\n--" + w.Boundary() + "--\r\n") - dockerfile, err := w.CreateFormFile("Dockerfile", "Dockerfile") + // Create a FormFile multipart for the Dockerfile + if *fileName == "-" { + file = os.Stdin + } else { + file, err = os.Open(*fileName) + if err != nil { + return err + } + defer file.Close() + } + if _, err := w.CreateFormFile("Dockerfile", *fileName); err != nil { + return err + } + multipartBody = io.MultiReader(multipartBody, file) + + // Create a FormFile multipart for the context if needed + if *contextPath != "" { + // FIXME: Use NewTempArchive in order to have the size and avoid too much memory usage? + context, err := Tar(*contextPath, Bzip2) + if err != nil { + return err + } + if _, err := w.CreateFormFile("Context", *contextPath+".tar.bz2"); err != nil { + return err + } + multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)")) + } + + // Send the multipart request with correct content-type + req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), io.MultiReader(multipartBody, boundary)) if err != nil { return err } - file, err := os.Open("Dockerfile") - if err != nil { - return err - } - dockerfile.Write([]byte(w.Boundary() + "\r\n")) - if _, err := io.Copy(dockerfile, file); err != nil { - return err - } - dockerfile.Write([]byte("\r\n" + w.Boundary())) + req.Header.Set("Content-Type", w.FormDataContentType()) - // req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), buff) - // if err != nil { - // return err - // } - // req.Header.Set("Content-Type", w.FormDataContentType()) - resp, err := http.Post(fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), w.FormDataContentType(), buff) + resp, err := http.DefaultClient.Do(req) if err != nil { return err } defer resp.Body.Close() + // Check for errors if resp.StatusCode < 200 || resp.StatusCode >= 400 { body, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -150,6 +181,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return fmt.Errorf("error: %s", body) } + // Output the result if _, err := io.Copy(os.Stdout, resp.Body); err != nil { return err } @@ -180,7 +212,7 @@ func (cli *DockerCli) CmdBuildClient(args ...string) error { return err } } - if _, err := NewBuilderClient("0.0.0.0", 4243).Build(file); err != nil { + if _, err := NewBuilderClient("0.0.0.0", 4243).Build(file, nil); err != nil { return err } return nil From e3f04298597195a95557c4224c05df752dc08695 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 23 May 2013 18:33:31 -0700 Subject: [PATCH 03/42] Add missing buildfile.go --- buildfile.go | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 buildfile.go diff --git a/buildfile.go b/buildfile.go new file mode 100644 index 0000000000..0784f54328 --- /dev/null +++ b/buildfile.go @@ -0,0 +1,311 @@ +package docker + +import ( + "bufio" + "encoding/json" + "fmt" + "github.com/dotcloud/docker/utils" + "io" + "os" + "reflect" + "strings" +) + +type BuildFile interface { + Build(io.Reader, io.Reader) (string, error) + CmdFrom(string) error + CmdRun(string) error +} + +type buildFile struct { + runtime *Runtime + builder *Builder + srv *Server + + image string + maintainer string + config *Config + + tmpContainers map[string]struct{} + tmpImages map[string]struct{} + + needCommit bool + + out io.Writer +} + +func (b *buildFile) clearTmp(containers, images map[string]struct{}) { + for c := range containers { + tmp := b.runtime.Get(c) + b.runtime.Destroy(tmp) + utils.Debugf("Removing container %s", c) + } + for i := range images { + b.runtime.graph.Delete(i) + utils.Debugf("Removing image %s", i) + } +} + +func (b *buildFile) CmdFrom(name string) error { + image, err := b.runtime.repositories.LookupImage(name) + if err != nil { + if b.runtime.graph.IsNotExist(err) { + + var tag, remote string + if strings.Contains(name, ":") { + remoteParts := strings.Split(name, ":") + tag = remoteParts[1] + remote = remoteParts[0] + } else { + remote = name + } + + if err := b.srv.ImagePull(remote, tag, "", b.out); err != nil { + return err + } + + image, err = b.runtime.repositories.LookupImage(name) + if err != nil { + return err + } + } else { + return err + } + } + b.image = image.Id + b.config = &Config{} + return nil +} + +func (b *buildFile) CmdMaintainer(name string) error { + b.needCommit = true + b.maintainer = name + return nil +} + +func (b *buildFile) CmdRun(args string) error { + if b.image == "" { + return fmt.Errorf("Please provide a source image with `from` prior to run") + } + config, _, err := ParseRun([]string{b.image, "/bin/sh", "-c", args}, nil) + if err != nil { + return err + } + + cmd, env := b.config.Cmd, b.config.Env + b.config.Cmd = nil + MergeConfig(b.config, config) + + if cache, err := b.srv.ImageGetCached(b.image, config); err != nil { + return err + } else if cache != nil { + utils.Debugf("Use cached version") + b.image = cache.Id + return nil + } + + cid, err := b.run() + if err != nil { + return err + } + b.config.Cmd, b.config.Env = cmd, env + return b.commit(cid) +} + +func (b *buildFile) CmdEnv(args string) error { + b.needCommit = true + tmp := strings.SplitN(args, " ", 2) + if len(tmp) != 2 { + return fmt.Errorf("Invalid ENV format") + } + key := strings.Trim(tmp[0], " ") + value := strings.Trim(tmp[1], " ") + + for i, elem := range b.config.Env { + if strings.HasPrefix(elem, key+"=") { + b.config.Env[i] = key + "=" + value + return nil + } + } + b.config.Env = append(b.config.Env, key+"="+value) + return nil +} + +func (b *buildFile) CmdCmd(args string) error { + b.needCommit = true + var cmd []string + if err := json.Unmarshal([]byte(args), &cmd); err != nil { + utils.Debugf("Error unmarshalling: %s, using /bin/sh -c", err) + b.config.Cmd = []string{"/bin/sh", "-c", args} + } else { + b.config.Cmd = cmd + } + return nil +} + +func (b *buildFile) CmdExpose(args string) error { + ports := strings.Split(args, " ") + b.config.PortSpecs = append(ports, b.config.PortSpecs...) + return nil +} + +func (b *buildFile) CmdInsert(args string) error { + if b.image == "" { + return fmt.Errorf("Please provide a source image with `from` prior to insert") + } + tmp := strings.SplitN(args, " ", 2) + if len(tmp) != 2 { + return fmt.Errorf("Invalid INSERT format") + } + sourceUrl := strings.Trim(tmp[0], " ") + destPath := strings.Trim(tmp[1], " ") + + file, err := utils.Download(sourceUrl, b.out) + if err != nil { + return err + } + defer file.Body.Close() + + cid, err := b.run() + if err != nil { + return err + } + + container := b.runtime.Get(cid) + if container == nil { + return fmt.Errorf("An error occured while creating the container") + } + + if err := container.Inject(file.Body, destPath); err != nil { + return err + } + + return b.commit(cid) +} + +func (b *buildFile) run() (string, error) { + if b.image == "" { + return "", fmt.Errorf("Please provide a source image with `from` prior to run") + } + b.config.Image = b.image + + // Create the container and start it + c, err := b.builder.Create(b.config) + if err != nil { + return "", err + } + b.tmpContainers[c.Id] = struct{}{} + + //start the container + if err := c.Start(); err != nil { + return "", err + } + + // Wait for it to finish + if ret := c.Wait(); ret != 0 { + return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, ret) + } + + return c.Id, nil +} + +func (b *buildFile) commit(id string) error { + if b.image == "" { + return fmt.Errorf("Please provide a source image with `from` prior to commit") + } + b.config.Image = b.image + + if id == "" { + cmd := b.config.Cmd + b.config.Cmd = []string{"true"} + if cid, err := b.run(); err != nil { + return err + } else { + id = cid + } + b.config.Cmd = cmd + } + + container := b.runtime.Get(id) + if container == nil { + return fmt.Errorf("An error occured while creating the container") + } + + // Commit the container + image, err := b.builder.Commit(container, "", "", "", b.maintainer, nil) + if err != nil { + return err + } + b.tmpImages[image.Id] = struct{}{} + b.image = image.Id + b.needCommit = false + return nil +} + +func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { + b.out = os.Stdout + + defer b.clearTmp(b.tmpContainers, b.tmpImages) + file := bufio.NewReader(dockerfile) + for { + line, err := file.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + return "", err + } + line = strings.Replace(strings.TrimSpace(line), " ", " ", 1) + // Skip comments and empty line + if len(line) == 0 || line[0] == '#' { + continue + } + tmp := strings.SplitN(line, " ", 2) + if len(tmp) != 2 { + return "", fmt.Errorf("Invalid Dockerfile format") + } + instruction := strings.ToLower(strings.Trim(tmp[0], " ")) + arguments := strings.Trim(tmp[1], " ") + + fmt.Fprintf(b.out, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image) + + method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:])) + if !exists { + fmt.Fprintf(b.out, "Skipping unknown instruction %s\n", strings.ToUpper(instruction)) + } + ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface() + if ret != nil { + return "", ret.(error) + } + + fmt.Fprintf(b.out, "===> %v\n", b.image) + } + if b.needCommit { + if err := b.commit(""); err != nil { + return "", err + } + } + if b.image != "" { + // The build is successful, keep the temporary containers and images + for i := range b.tmpImages { + delete(b.tmpImages, i) + } + fmt.Fprintf(b.out, "Build finished. image id: %s\n", b.image) + return b.image, nil + } + for i := range b.tmpContainers { + delete(b.tmpContainers, i) + } + return "", fmt.Errorf("An error occured during the build\n") +} + +func NewBuildFile(srv *Server, out io.Writer) BuildFile { + return &buildFile{ + builder: NewBuilder(srv.runtime), + runtime: srv.runtime, + srv: srv, + config: &Config{}, + tmpContainers: make(map[string]struct{}), + tmpImages: make(map[string]struct{}), + } +} From 2cd00a47a5a8f405eb6a7b3f34edaf38c89e9b1c Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 23 May 2013 18:34:38 -0700 Subject: [PATCH 04/42] remove unused function --- api.go | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/api.go b/api.go index 0a65543b79..d3eb9101b7 100644 --- a/api.go +++ b/api.go @@ -599,36 +599,6 @@ func postImagesGetCache(srv *Server, w http.ResponseWriter, r *http.Request, var return nil } -func Upload(w http.ResponseWriter, req *http.Request) { - - mr, err := req.MultipartReader() - if err != nil { - return - } - length := req.ContentLength - for { - - part, err := mr.NextPart() - if err == io.EOF { - break - } - var read int64 - var p float32 - for { - buffer := make([]byte, 100000) - cBytes, err := part.Read(buffer) - if err == io.EOF { - break - } - read = read + int64(cBytes) - //fmt.Printf("read: %v \n",read ) - p = float32(read) / float32(length) * 100 - fmt.Printf("progress: %v \n", p) - os.Stdout.Write(buffer) - } - } -} - func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := r.ParseMultipartForm(4096); err != nil { return err From 4e576f047fc8a5a75fa88a66132bdade4f3a1e44 Mon Sep 17 00:00:00 2001 From: kim0 Date: Fri, 24 May 2013 18:55:32 +0300 Subject: [PATCH 05/42] Properly install ppa, avoid GPG key warning --- docs/sources/installation/ubuntulinux.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sources/installation/ubuntulinux.rst b/docs/sources/installation/ubuntulinux.rst index 6d2d3e671d..82d44827a0 100644 --- a/docs/sources/installation/ubuntulinux.rst +++ b/docs/sources/installation/ubuntulinux.rst @@ -54,9 +54,9 @@ which makes installing Docker on Ubuntu very easy. .. code-block:: bash # Add the PPA sources to your apt sources list. - sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' > /etc/apt/sources.list.d/lxc-docker.list" + sudo apt-get install python-software-properties && sudo add-apt-repository ppa:dotcloud/lxc-docker - # Update your sources, you will see a warning. + # Update your sources sudo apt-get update # Install, you will see another warning that the package cannot be authenticated. Confirm install. From c5f15dcd3de02a10452963a9c56cb2e587972f58 Mon Sep 17 00:00:00 2001 From: Thatcher Peskens Date: Fri, 24 May 2013 14:42:00 -0700 Subject: [PATCH 06/42] Added links to @jpetazzo 's kernel article, removed quote indents from puppet.rst --- docs/sources/installation/binaries.rst | 2 +- docs/sources/installation/ubuntulinux.rst | 2 +- docs/sources/use/puppet.rst | 64 +++++++++++------------ 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/sources/installation/binaries.rst b/docs/sources/installation/binaries.rst index 8bab5695cd..e7a07b6db1 100644 --- a/docs/sources/installation/binaries.rst +++ b/docs/sources/installation/binaries.rst @@ -27,7 +27,7 @@ But we know people have had success running it under Dependencies: ------------- -* 3.8 Kernel +* 3.8 Kernel (read more about :ref:`kernel`) * AUFS filesystem support * lxc * bsdtar diff --git a/docs/sources/installation/ubuntulinux.rst b/docs/sources/installation/ubuntulinux.rst index 0aaa76250e..ac94913ebc 100644 --- a/docs/sources/installation/ubuntulinux.rst +++ b/docs/sources/installation/ubuntulinux.rst @@ -16,7 +16,7 @@ Right now, the officially supported distribution are: Docker has the following dependencies -* Linux kernel 3.8 +* Linux kernel 3.8 (read more about :ref:`kernel`) * AUFS file system support (we are working on BTRFS support as an alternative) .. _ubuntu_precise: diff --git a/docs/sources/use/puppet.rst b/docs/sources/use/puppet.rst index 1c48aec8e5..5606f2a863 100644 --- a/docs/sources/use/puppet.rst +++ b/docs/sources/use/puppet.rst @@ -25,9 +25,9 @@ Installation The module is available on the `Puppet Forge `_ and can be installed using the built-in module tool. - .. code-block:: bash +.. code-block:: bash - puppet module install garethr/docker + puppet module install garethr/docker It can also be found on `GitHub `_ if you would rather download the source. @@ -41,9 +41,9 @@ for managing images and containers. Installation ~~~~~~~~~~~~ - .. code-block:: ruby +.. code-block:: ruby - include 'docker' + include 'docker' Images ~~~~~~ @@ -51,26 +51,26 @@ Images The next step is probably to install a docker image, for this we have a defined type which can be used like so: - .. code-block:: ruby +.. code-block:: ruby - docker::image { 'base': } + docker::image { 'base': } This is equivalent to running: - .. code-block:: bash +.. code-block:: bash - docker pull base + docker pull base Note that it will only if the image of that name does not already exist. This is downloading a large binary so on first run can take a while. For that reason this define turns off the default 5 minute timeout for exec. Note that you can also remove images you no longer need with: - .. code-block:: ruby +.. code-block:: ruby - docker::image { 'base': - ensure => 'absent', - } + docker::image { 'base': + ensure => 'absent', + } Containers ~~~~~~~~~~ @@ -78,35 +78,35 @@ Containers Now you have an image you can run commands within a container managed by docker. - .. code-block:: ruby +.. code-block:: ruby - docker::run { 'helloworld': - image => 'base', - command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', - } + docker::run { 'helloworld': + image => 'base', + command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', + } This is equivalent to running the following command, but under upstart: - .. code-block:: bash +.. code-block:: bash - docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done" + docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done" Run also contains a number of optional parameters: - .. code-block:: ruby +.. code-block:: ruby - docker::run { 'helloworld': - image => 'base', - command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', - ports => ['4444', '4555'], - volumes => ['/var/lib/counchdb', '/var/log'], - volumes_from => '6446ea52fbc9', - memory_limit => 10485760, # bytes - username => 'example', - hostname => 'example.com', - env => ['FOO=BAR', 'FOO2=BAR2'], - dns => ['8.8.8.8', '8.8.4.4'], - } + docker::run { 'helloworld': + image => 'base', + command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', + ports => ['4444', '4555'], + volumes => ['/var/lib/counchdb', '/var/log'], + volumes_from => '6446ea52fbc9', + memory_limit => 10485760, # bytes + username => 'example', + hostname => 'example.com', + env => ['FOO=BAR', 'FOO2=BAR2'], + dns => ['8.8.8.8', '8.8.4.4'], + } Note that ports, env, dns and volumes can be set with either a single string or as above with an array of values. From 7d6ff7be129d70f0ff5c50a47d70a32a1e6274bc Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Tue, 28 May 2013 06:27:12 -0700 Subject: [PATCH 07/42] Fix attach API docs. --- docs/sources/api/docker_remote_api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 4c8ebe847f..0dcf842738 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -378,7 +378,7 @@ Attach to a container .. http:post:: /containers/(id)/attach - Stop the container ``id`` + Attach to the container ``id`` **Example request**: From d9670f427522fc847313ad1b94b1e288dafe7690 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 28 May 2013 15:06:26 +0000 Subject: [PATCH 08/42] invert status created --- commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 6c4dcd14d6..f68bfbad53 100644 --- a/commands.go +++ b/commands.go @@ -806,9 +806,9 @@ func (cli *DockerCli) CmdPs(args ...string) error { for _, out := range outs { if !*quiet { if *noTrunc { - 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) + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports) } else { - 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) + 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), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports) } } else { if *noTrunc { From 4f9443927e8bc8a724b43afae6cf7a183cd9acd0 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 28 May 2013 16:08:05 +0000 Subject: [PATCH 09/42] rename containers/ps to containers/json --- api.go | 5 +++-- api_test.go | 6 +++--- commands.go | 2 +- docs/sources/api/docker_remote_api.rst | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api.go b/api.go index 3164a886f6..d23b8901b9 100644 --- a/api.go +++ b/api.go @@ -206,7 +206,7 @@ func getContainersChanges(srv *Server, version float64, w http.ResponseWriter, r return nil } -func getContainersPs(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getContainersJson(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -627,7 +627,8 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { "/images/search": getImagesSearch, "/images/{name:.*}/history": getImagesHistory, "/images/{name:.*}/json": getImagesByName, - "/containers/ps": getContainersPs, + "/containers/ps": getContainersJson, + "/containers/json": getContainersJson, "/containers/{name:.*}/export": getContainersExport, "/containers/{name:.*}/changes": getContainersChanges, "/containers/{name:.*}/json": getContainersByName, diff --git a/api_test.go b/api_test.go index 06413e1303..f94ba23fa0 100644 --- a/api_test.go +++ b/api_test.go @@ -318,7 +318,7 @@ func TestGetImagesByName(t *testing.T) { } } -func TestGetContainersPs(t *testing.T) { +func TestGetContainersJson(t *testing.T) { runtime, err := newTestRuntime() if err != nil { t.Fatal(err) @@ -336,13 +336,13 @@ func TestGetContainersPs(t *testing.T) { } defer runtime.Destroy(container) - req, err := http.NewRequest("GET", "/containers?quiet=1&all=1", nil) + req, err := http.NewRequest("GET", "/containers/json?all=1", nil) if err != nil { t.Fatal(err) } r := httptest.NewRecorder() - if err := getContainersPs(srv, API_VERSION, r, req, nil); err != nil { + if err := getContainersJson(srv, API_VERSION, r, req, nil); err != nil { t.Fatal(err) } containers := []ApiContainers{} diff --git a/commands.go b/commands.go index 6c4dcd14d6..05d66bce20 100644 --- a/commands.go +++ b/commands.go @@ -788,7 +788,7 @@ func (cli *DockerCli) CmdPs(args ...string) error { v.Set("before", *before) } - body, _, err := cli.call("GET", "/containers/ps?"+v.Encode(), nil) + body, _, err := cli.call("GET", "/containers/json?"+v.Encode(), nil) if err != nil { return err } diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 0dcf842738..bd87dc7a03 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -24,7 +24,7 @@ Docker Remote API List containers *************** -.. http:get:: /containers/ps +.. http:get:: /containers/json List containers @@ -32,7 +32,7 @@ List containers .. sourcecode:: http - GET /containers/ps?all=1&before=8dfafdbc3a40 HTTP/1.1 + GET /containers/json?all=1&before=8dfafdbc3a40 HTTP/1.1 **Example response**: From e5fa4a4956393afc473539710e2a4b7297eb6ebf Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 28 May 2013 16:19:12 +0000 Subject: [PATCH 10/42] return 404 on no such containers in /attach --- api.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api.go b/api.go index 3164a886f6..581cc84d1d 100644 --- a/api.go +++ b/api.go @@ -541,6 +541,10 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r } name := vars["name"] + if _, err := srv.ContainerInspect(name); err != nil { + return err + } + in, out, err := hijackServer(w) if err != nil { return err From 525080100d2e2a7899c9a51a1ca57e28e32e8488 Mon Sep 17 00:00:00 2001 From: meejah Date: Tue, 28 May 2013 10:54:32 -0600 Subject: [PATCH 11/42] Use Ubuntu's built-in method to add a PPA repository, which correctly handles keys for you. --- docs/website/gettingstarted/index.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/website/gettingstarted/index.html b/docs/website/gettingstarted/index.html index 622cdbbd42..1da2f2cc3b 100644 --- a/docs/website/gettingstarted/index.html +++ b/docs/website/gettingstarted/index.html @@ -89,9 +89,10 @@
  • Install Docker

    Add the Ubuntu PPA (Personal Package Archive) sources to your apt sources list, update and install.

    -

    You may see some warnings that the GPG keys cannot be verified.

    +

    This may import a new GPG key (key 63561DC6: public key "Launchpad PPA for dotcloud team" imported).

    -
    sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' >> /etc/apt/sources.list"
    +
    apt-get install software-properties-common
    +
    add-apt-repository ppa:dotcloud/lxc-docker
    sudo apt-get update
    sudo apt-get install lxc-docker
    From 444f7020cbc639fd781744be207c843aaf663077 Mon Sep 17 00:00:00 2001 From: meejah Date: Tue, 28 May 2013 10:56:26 -0600 Subject: [PATCH 12/42] Add sudo to commands. --- docs/website/gettingstarted/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/website/gettingstarted/index.html b/docs/website/gettingstarted/index.html index 1da2f2cc3b..5a8de3232b 100644 --- a/docs/website/gettingstarted/index.html +++ b/docs/website/gettingstarted/index.html @@ -91,8 +91,8 @@

    Add the Ubuntu PPA (Personal Package Archive) sources to your apt sources list, update and install.

    This may import a new GPG key (key 63561DC6: public key "Launchpad PPA for dotcloud team" imported).

    -
    apt-get install software-properties-common
    -
    add-apt-repository ppa:dotcloud/lxc-docker
    +
    sudo apt-get install software-properties-common
    +
    sudo add-apt-repository ppa:dotcloud/lxc-docker
    sudo apt-get update
    sudo apt-get install lxc-docker
    From 54db18625aa7154c9dd230907444676fa3079b99 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:37:49 -0700 Subject: [PATCH 13/42] Add Extension() method to Compresison type --- api.go | 1 - archive.go | 17 ++++++++++++++++- buildfile.go | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index d3eb9101b7..a1a6949626 100644 --- a/api.go +++ b/api.go @@ -9,7 +9,6 @@ import ( "io" "log" "net/http" - "os" "strconv" "strings" ) diff --git a/archive.go b/archive.go index 8a011eb6e1..4120a52c1d 100644 --- a/archive.go +++ b/archive.go @@ -2,6 +2,7 @@ package docker import ( "errors" + "fmt" "io" "io/ioutil" "os" @@ -31,6 +32,20 @@ func (compression *Compression) Flag() string { return "" } +func (compression *Compression) Extension() string { + switch *compression { + case Uncompressed: + return "tar" + case Bzip2: + return "tar.bz2" + case Gzip: + return "tar.gz" + case Xz: + return "tar.xz" + } + return "" +} + func Tar(path string, compression Compression) (io.Reader, error) { cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-c"+compression.Flag(), ".") return CmdStream(cmd) @@ -41,7 +56,7 @@ func Untar(archive io.Reader, path string) error { cmd.Stdin = archive output, err := cmd.CombinedOutput() if err != nil { - return errors.New(err.Error() + ": " + string(output)) + return fmt.Errorf("%s: %s", err, output) } return nil } diff --git a/buildfile.go b/buildfile.go index 0784f54328..d0f0b6e7d7 100644 --- a/buildfile.go +++ b/buildfile.go @@ -6,7 +6,9 @@ import ( "fmt" "github.com/dotcloud/docker/utils" "io" + "io/ioutil" "os" + "path" "reflect" "strings" ) From 6ae3800151025ff73a97c40af578ee714164003b Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:38:26 -0700 Subject: [PATCH 14/42] Implement the CmdAdd instruction --- buildfile.go | 48 +++++++++++++++++++++++++++++++++++++++++++++--- commands.go | 29 ----------------------------- runtime_test.go | 11 ++--------- utils/utils.go | 7 +++++++ 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/buildfile.go b/buildfile.go index d0f0b6e7d7..0cd8aa1822 100644 --- a/buildfile.go +++ b/buildfile.go @@ -27,6 +27,7 @@ type buildFile struct { image string maintainer string config *Config + context string tmpContainers map[string]struct{} tmpImages map[string]struct{} @@ -168,6 +169,7 @@ func (b *buildFile) CmdInsert(args string) error { } defer file.Body.Close() + b.config.Cmd = []string{"echo", "INSERT", sourceUrl, "in", destPath} cid, err := b.run() if err != nil { return err @@ -185,6 +187,36 @@ func (b *buildFile) CmdInsert(args string) error { return b.commit(cid) } +func (b *buildFile) CmdAdd(args string) error { + tmp := strings.SplitN(args, " ", 2) + if len(tmp) != 2 { + return fmt.Errorf("Invalid INSERT format") + } + orig := strings.Trim(tmp[0], " ") + dest := strings.Trim(tmp[1], " ") + + b.config.Cmd = []string{"echo", "PUSH", orig, "in", dest} + cid, err := b.run() + if err != nil { + return err + } + + container := b.runtime.Get(cid) + if container == nil { + return fmt.Errorf("Error while creating the container (CmdAdd)") + } + + if err := os.MkdirAll(path.Join(container.rwPath(), dest), 0700); err != nil { + return err + } + + if err := utils.CopyDirectory(path.Join(b.context, orig), path.Join(container.rwPath(), dest)); err != nil { + return err + } + + return b.commit(cid) +} + func (b *buildFile) run() (string, error) { if b.image == "" { return "", fmt.Errorf("Please provide a source image with `from` prior to run") @@ -216,7 +248,6 @@ func (b *buildFile) commit(id string) error { return fmt.Errorf("Please provide a source image with `from` prior to commit") } b.config.Image = b.image - if id == "" { cmd := b.config.Cmd b.config.Cmd = []string{"true"} @@ -245,9 +276,19 @@ func (b *buildFile) commit(id string) error { } func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { - b.out = os.Stdout - defer b.clearTmp(b.tmpContainers, b.tmpImages) + + if context != nil { + name, err := ioutil.TempDir("/tmp", "docker-build") + if err != nil { + return "", err + } + if err := Untar(context, name); err != nil { + return "", err + } + defer os.RemoveAll(name) + b.context = name + } file := bufio.NewReader(dockerfile) for { line, err := file.ReadString('\n') @@ -307,6 +348,7 @@ func NewBuildFile(srv *Server, out io.Writer) BuildFile { runtime: srv.runtime, srv: srv, config: &Config{}, + out: out, tmpContainers: make(map[string]struct{}), tmpImages: make(map[string]struct{}), } diff --git a/commands.go b/commands.go index f5c658e6b1..79fdafe7d8 100644 --- a/commands.go +++ b/commands.go @@ -189,35 +189,6 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return nil } -func (cli *DockerCli) CmdBuildClient(args ...string) error { - cmd := Subcmd("build", "-|Dockerfile", "Build an image from Dockerfile or via stdin") - if err := cmd.Parse(args); err != nil { - return nil - } - var ( - file io.ReadCloser - err error - ) - - if cmd.NArg() == 0 { - file, err = os.Open("Dockerfile") - if err != nil { - return err - } - } else if cmd.Arg(0) == "-" { - file = os.Stdin - } else { - file, err = os.Open(cmd.Arg(0)) - if err != nil { - return err - } - } - if _, err := NewBuilderClient("0.0.0.0", 4243).Build(file, nil); err != nil { - return err - } - return nil -} - // 'docker login': login / register a user to registry service. func (cli *DockerCli) CmdLogin(args ...string) error { var readStringOnRawTerminal = func(stdin io.Reader, stdout io.Writer, echo bool) string { diff --git a/runtime_test.go b/runtime_test.go index 01bd2a0128..9ca280495b 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -32,13 +32,6 @@ func nuke(runtime *Runtime) error { return os.RemoveAll(runtime.root) } -func CopyDirectory(source, dest string) error { - if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil { - return err - } - return nil -} - func layerArchive(tarfile string) (io.Reader, error) { // FIXME: need to close f somewhere f, err := os.Open(tarfile) @@ -88,7 +81,7 @@ func newTestRuntime() (*Runtime, error) { if err := os.Remove(root); err != nil { return nil, err } - if err := CopyDirectory(unitTestStoreBase, root); err != nil { + if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil { return nil, err } @@ -345,7 +338,7 @@ func TestRestore(t *testing.T) { if err := os.Remove(root); err != nil { t.Fatal(err) } - if err := CopyDirectory(unitTestStoreBase, root); err != nil { + if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil { t.Fatal(err) } diff --git a/utils/utils.go b/utils/utils.go index 150eae8570..90ef30625c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -531,6 +531,13 @@ func GetKernelVersion() (*KernelVersionInfo, error) { }, nil } +func CopyDirectory(source, dest string) error { + if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil { + return err + } + return nil +} + type NopFlusher struct{} func (f *NopFlusher) Flush() {} From 90ffcda05547332020ec6f2b98179380f7d0e56f Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:38:40 -0700 Subject: [PATCH 15/42] Update the UI for docker build --- commands.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/commands.go b/commands.go index 79fdafe7d8..cfe6c38a41 100644 --- a/commands.go +++ b/commands.go @@ -112,9 +112,8 @@ func (cli *DockerCli) CmdInsert(args ...string) error { } func (cli *DockerCli) CmdBuild(args ...string) error { - cmd := Subcmd("build", "[OPTIONS]", "Build an image from a Dockerfile") - fileName := cmd.String("f", "Dockerfile", "Use file as Dockerfile. Can be '-' for stdin") - contextPath := cmd.String("c", "", "Use the specified directory as context for the build") + cmd := Subcmd("build", "[OPTIONS] [CONTEXT]", "Build an image from a Dockerfile") + fileName := cmd.String("f", "Dockerfile", "Use `file` as Dockerfile. Can be '-' for stdin") if err := cmd.Parse(args); err != nil { return nil } @@ -146,14 +145,16 @@ func (cli *DockerCli) CmdBuild(args ...string) error { } multipartBody = io.MultiReader(multipartBody, file) + compression := Bzip2 + // Create a FormFile multipart for the context if needed - if *contextPath != "" { + if cmd.Arg(0) != "" { // FIXME: Use NewTempArchive in order to have the size and avoid too much memory usage? - context, err := Tar(*contextPath, Bzip2) + context, err := Tar(cmd.Arg(0), compression) if err != nil { return err } - if _, err := w.CreateFormFile("Context", *contextPath+".tar.bz2"); err != nil { + if _, err := w.CreateFormFile("Context", cmd.Arg(0)+"."+compression.Extension()); err != nil { return err } multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)")) @@ -165,6 +166,9 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return err } req.Header.Set("Content-Type", w.FormDataContentType()) + if cmd.Arg(0) != "" { + req.Header.Set("X-Docker-Context-Compression", compression.Flag()) + } resp, err := http.DefaultClient.Do(req) if err != nil { From a48799016a43e6badae72e855f9a90592b6cdd98 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:46:52 -0700 Subject: [PATCH 16/42] Fix merge issue --- api.go | 2 +- buildfile.go | 2 +- commands.go | 2 +- server.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api.go b/api.go index e004aa4a3b..7b82135ef6 100644 --- a/api.go +++ b/api.go @@ -626,7 +626,7 @@ func postImagesGetCache(srv *Server, version float64, w http.ResponseWriter, r * return nil } -func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := r.ParseMultipartForm(4096); err != nil { return err } diff --git a/buildfile.go b/buildfile.go index 0cd8aa1822..f1e08b20fc 100644 --- a/buildfile.go +++ b/buildfile.go @@ -63,7 +63,7 @@ func (b *buildFile) CmdFrom(name string) error { remote = name } - if err := b.srv.ImagePull(remote, tag, "", b.out); err != nil { + if err := b.srv.ImagePull(remote, tag, "", b.out, false); err != nil { return err } diff --git a/commands.go b/commands.go index 952a2bb6cf..a79a24bff7 100644 --- a/commands.go +++ b/commands.go @@ -175,7 +175,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { if _, err := w.CreateFormFile("Context", cmd.Arg(0)+"."+compression.Extension()); err != nil { return err } - multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)")) + multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)", false)) } // Send the multipart request with correct content-type diff --git a/server.go b/server.go index 0714cba54d..2455587808 100644 --- a/server.go +++ b/server.go @@ -92,7 +92,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer) (string, e } if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, "Downloading %v/%v (%v)\r", false), path); err != nil { - return err + return "", err } // FIXME: Handle custom repo, tag comment, author img, err = b.Commit(c, "", "", img.Comment, img.Author, nil) From 582a9e0a67598672db35ef26a18027dd6fb222ca Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:47:04 -0700 Subject: [PATCH 17/42] Make docker build flush output each line --- api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.go b/api.go index 7b82135ef6..ca65c8e119 100644 --- a/api.go +++ b/api.go @@ -643,7 +643,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ } } - b := NewBuildFile(srv, w) + b := NewBuildFile(srv, utils.NewWriteFlusher(w)) if _, err := b.Build(file, context); err != nil { return err } From cfb8cbe5214c58690ca99cd44b25bd202c4dbcf7 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:51:21 -0700 Subject: [PATCH 18/42] Small fix --- buildfile.go | 3 +++ commands.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/buildfile.go b/buildfile.go index f1e08b20fc..88dcadbf90 100644 --- a/buildfile.go +++ b/buildfile.go @@ -188,6 +188,9 @@ func (b *buildFile) CmdInsert(args string) error { } func (b *buildFile) CmdAdd(args string) error { + if b.context == "" { + return fmt.Errorf("No context given. Impossible to use ADD") + } tmp := strings.SplitN(args, " ", 2) if len(tmp) != 2 { return fmt.Errorf("Invalid INSERT format") diff --git a/commands.go b/commands.go index a79a24bff7..5d65daeb57 100644 --- a/commands.go +++ b/commands.go @@ -175,7 +175,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { if _, err := w.CreateFormFile("Context", cmd.Arg(0)+"."+compression.Extension()); err != nil { return err } - multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)", false)) + multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)\r", false)) } // Send the multipart request with correct content-type From 387eb5295a9ea75a099dd36adcae18229541f613 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 14:13:20 -0700 Subject: [PATCH 19/42] Removed deprecated SPECS directory --- SPECS/data-volumes.md | 71 ------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 SPECS/data-volumes.md diff --git a/SPECS/data-volumes.md b/SPECS/data-volumes.md deleted file mode 100644 index d800656afc..0000000000 --- a/SPECS/data-volumes.md +++ /dev/null @@ -1,71 +0,0 @@ - -## Spec for data volumes - -Spec owner: Solomon Hykes - -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. -This spec will be deprecated once the feature is fully implemented. - -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 - - -### 1. Creating data volumes - -At container creation, parts of a container's filesystem can be mounted as separate data volumes. Volumes are defined with the -v flag. - -For example: - -```bash -$ docker run -v /var/lib/postgres -v /var/log postgres /usr/bin/postgres -``` - -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. - -2 important notes: - -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. - -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. - - -### 2. Sharing data volumes - -Instead of creating its own volumes, a container can share another container's volumes. For example: - -```bash -$ docker run --volumes-from $OTHER_CONTAINER_ID postgres /usr/local/bin/postgres-backup -``` - -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. - -### 3. Under the hood - -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. - -At creation, volumes are attached to a single container - the source of truth for this mapping will be the container's configuration. - -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. - - -### 4. Backups, transfers and other volume operations - -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... - -Rather than attempting to implement all these scenarios directly, Docker will allow for custom implementations using an extension mechanism. - -### 5. Custom volume handlers - -Docker allows for arbitrary code to be executed against a container's volumes, to implement any custom action: backup, transfer, synchronization across hosts, etc. - -Here's an example: - -```bash -$ DB=$(docker run -d -v /var/lib/postgres -v /var/log postgres /usr/bin/postgres) - -$ BACKUP_JOB=$(docker run -d --volumes-from $DB shykes/backuper /usr/local/bin/backup-postgres --s3creds=$S3CREDS) - -$ docker wait $BACKUP_JOB -``` - -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. - From 326faec6642896954ffbd407eeda7d19da193856 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 14:57:36 -0700 Subject: [PATCH 20/42] De-duplicated contribution instructions. The authoritative instructions are in CONTRIBUTING.md at the root of the repo. --- CONTRIBUTING.md | 5 +- docs/sources/contributing/contributing.rst | 98 +--------------------- 2 files changed, 2 insertions(+), 101 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f461e95303..2e1141c30f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,6 @@ # Contributing to Docker -Want to hack on Docker? Awesome! There are instructions to get you -started on the website: http://docker.io/gettingstarted.html - -They are probably not perfect, please let us know if anything feels +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 wrong or incomplete. ## Contribution guidelines diff --git a/docs/sources/contributing/contributing.rst b/docs/sources/contributing/contributing.rst index c2bd7c80fb..25b4df763a 100644 --- a/docs/sources/contributing/contributing.rst +++ b/docs/sources/contributing/contributing.rst @@ -5,101 +5,5 @@ Contributing to Docker ====================== -Want to hack on Docker? Awesome! There are instructions to get you -started on the website: http://docker.io/gettingstarted.html +Want to hack on Docker? Awesome! The repository includes `all the instructions you need to get started `. -They are probably not perfect, please let us know if anything feels -wrong or incomplete. - -Contribution guidelines ------------------------ - -Pull requests are always welcome -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -We are always thrilled to receive pull requests, and do our best to -process them as fast as possible. Not sure if that typo is worth a pull -request? Do it! We will appreciate it. - -If your pull request is not accepted on the first try, don't be -discouraged! If there's a problem with the implementation, hopefully you -received feedback on what to improve. - -We're trying very hard to keep Docker lean and focused. We don't want it -to do everything for everybody. This means that we might decide against -incorporating a new feature. However, there might be a way to implement -that feature *on top of* docker. - -Discuss your design on the mailing list -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -We recommend discussing your plans `on the mailing -list `__ -before starting to code - especially for more ambitious contributions. -This gives other contributors a chance to point you in the right -direction, give feedback on your design, and maybe point out if someone -else is working on the same thing. - -Create issues... -~~~~~~~~~~~~~~~~ - -Any significant improvement should be documented as `a github -issue `__ before anybody -starts working on it. - -...but check for existing issues first! -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Please take a moment to check that an issue doesn't already exist -documenting your bug report or improvement proposal. If it does, it -never hurts to add a quick "+1" or "I have this problem too". This will -help prioritize the most common problems and requests. - -Conventions -~~~~~~~~~~~ - -Fork the repo and make changes on your fork in a feature branch: - -- If it's a bugfix branch, name it XXX-something where XXX is the number of the - issue -- If it's a feature branch, create an enhancement issue to announce your - intentions, and name it XXX-something where XXX is the number of the issue. - -Submit unit tests for your changes. Go has a great test framework built in; use -it! Take a look at existing tests for inspiration. Run the full test suite on -your branch before submitting a pull request. - -Make sure you include relevant updates or additions to documentation when -creating or modifying features. - -Write clean code. Universally formatted code promotes ease of writing, reading, -and maintenance. Always run ``go fmt`` before committing your changes. Most -editors have plugins that do this automatically, and there's also a git -pre-commit hook: - -.. code-block:: bash - - curl -o .git/hooks/pre-commit https://raw.github.com/edsrzf/gofmt-git-hook/master/fmt-check && chmod +x .git/hooks/pre-commit - - -Pull requests descriptions should be as clear as possible and include a -reference to all the issues that they address. - -Code review comments may be added to your pull request. Discuss, then make the -suggested modifications and push additional commits to your feature branch. Be -sure to post a comment after pushing. The new commits will show up in the pull -request automatically, but the reviewers will not be notified unless you -comment. - -Before the pull request is merged, make sure that you squash your commits into -logical units of work using ``git rebase -i`` and ``git push -f``. After every -commit the test suite should be passing. Include documentation changes in the -same commit so that a revert would remove all traces of the feature or fix. - -Commits that fix or close an issue should include a reference like ``Closes #XXX`` -or ``Fixes #XXX``, which will automatically close the issue when merged. - -Add your name to the AUTHORS file, but make sure the list is sorted and your -name and email address match your git configuration. The AUTHORS file is -regenerated occasionally from the git commit history, so a mismatch may result -in your changes being overwritten. From fe0c0c208c0e816419b668a6fd6567520698c2d2 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:21:06 -0700 Subject: [PATCH 21/42] Send error without headers when using chunks --- api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index ca65c8e119..12abb3da27 100644 --- a/api.go +++ b/api.go @@ -631,7 +631,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ return err } - file, _, err := r.FormFile("Dockerfile") + dockerfile, _, err := r.FormFile("Dockerfile") if err != nil { return err } @@ -644,8 +644,8 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ } b := NewBuildFile(srv, utils.NewWriteFlusher(w)) - if _, err := b.Build(file, context); err != nil { - return err + if _, err := b.Build(dockerfile, context); err != nil { + fmt.Fprintf(w, "Error build: %s\n", err) } return nil } From 2897cb04760d7e4e7e52ccc20e94c94e3743667e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:22:01 -0700 Subject: [PATCH 22/42] Add directory contents instead of while directory for docker build --- buildfile.go | 21 ++++++++++++++++++++- utils/utils.go | 10 ++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/buildfile.go b/buildfile.go index 88dcadbf90..15577b98ef 100644 --- a/buildfile.go +++ b/buildfile.go @@ -213,9 +213,28 @@ func (b *buildFile) CmdAdd(args string) error { return err } - if err := utils.CopyDirectory(path.Join(b.context, orig), path.Join(container.rwPath(), dest)); err != nil { + origPath := path.Join(b.context, orig) + destPath := path.Join(container.rwPath(), dest) + + fi, err := os.Stat(origPath) + if err != nil { return err } + if fi.IsDir() { + files, err := ioutil.ReadDir(path.Join(b.context, orig)) + if err != nil { + return err + } + for _, fi := range files { + if err := utils.CopyDirectory(path.Join(origPath, fi.Name()), path.Join(destPath, fi.Name())); err != nil { + return err + } + } + } else { + if err := utils.CopyDirectory(origPath, destPath); err != nil { + return err + } + } return b.commit(cid) } diff --git a/utils/utils.go b/utils/utils.go index ac0a142ae6..97bdea9e9a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -69,7 +69,7 @@ type progressReader struct { readProgress int // How much has been read so far (bytes) lastUpdate int // How many bytes read at least update template string // Template to print. Default "%v/%v (%v)" - json bool + json bool } func (r *progressReader) Read(p []byte) (n int, err error) { @@ -102,7 +102,7 @@ func (r *progressReader) Close() error { return io.ReadCloser(r.reader).Close() } func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string, json bool) *progressReader { - if template == "" { + if template == "" { template = "%v/%v (%v)\r" } return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template, json} @@ -533,8 +533,8 @@ func GetKernelVersion() (*KernelVersionInfo, error) { } func CopyDirectory(source, dest string) error { - if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil { - return err + if output, err := exec.Command("cp", "-ra", source, dest).CombinedOutput(); err != nil { + return fmt.Errorf("Error copy: %s (%s)", err, output) } return nil } @@ -577,5 +577,3 @@ func FormatProgress(str string, json bool) string { } return "Downloading " + str + "\r" } - - From 2127f8d6ad091d699d3462715305a0f64340eca1 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:22:34 -0700 Subject: [PATCH 23/42] Fill the multipart writer directly instead of using reader --- commands.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/commands.go b/commands.go index 5d65daeb57..bca825925b 100644 --- a/commands.go +++ b/commands.go @@ -158,10 +158,12 @@ func (cli *DockerCli) CmdBuild(args ...string) error { } defer file.Close() } - if _, err := w.CreateFormFile("Dockerfile", *fileName); err != nil { + if wField, err := w.CreateFormFile("Dockerfile", *fileName); err != nil { return err + } else { + io.Copy(wField, file) } - multipartBody = io.MultiReader(multipartBody, file) + multipartBody = io.MultiReader(multipartBody, boundary) compression := Bzip2 @@ -172,20 +174,30 @@ func (cli *DockerCli) CmdBuild(args ...string) error { if err != nil { return err } - if _, err := w.CreateFormFile("Context", cmd.Arg(0)+"."+compression.Extension()); err != nil { + // NOTE: Do this in case '.' or '..' is input + absPath, err := filepath.Abs(cmd.Arg(0)) + if err != nil { return err } - multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)\r", false)) + if wField, err := w.CreateFormFile("Context", filepath.Base(absPath)+"."+compression.Extension()); err != nil { + return err + } else { + // FIXME: Find a way to have a progressbar for the upload too + io.Copy(wField, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Caching Context %v/%v (%v)\r", false)) + } + + multipartBody = io.MultiReader(multipartBody, boundary) } // Send the multipart request with correct content-type - req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), io.MultiReader(multipartBody, boundary)) + req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), multipartBody) if err != nil { return err } req.Header.Set("Content-Type", w.FormDataContentType()) if cmd.Arg(0) != "" { req.Header.Set("X-Docker-Context-Compression", compression.Flag()) + fmt.Println("Uploading Context...") } resp, err := http.DefaultClient.Do(req) From 5b33b2463a27aa3356a4b6200cf4b81dd83c26a0 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:31:06 -0700 Subject: [PATCH 24/42] Readd build tests --- buildfile_test.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++ runtime_test.go | 1 - 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 buildfile_test.go diff --git a/buildfile_test.go b/buildfile_test.go new file mode 100644 index 0000000000..b6f4e62ae9 --- /dev/null +++ b/buildfile_test.go @@ -0,0 +1,72 @@ +package docker + +import ( + "github.com/dotcloud/docker/utils" + "strings" + "testing" +) + +const Dockerfile = ` +# VERSION 0.1 +# DOCKER-VERSION 0.2 + +from ` + unitTestImageName + ` +run sh -c 'echo root:testpass > /tmp/passwd' +run mkdir -p /var/run/sshd +` + +func TestBuild(t *testing.T) { + runtime, err := newTestRuntime() + if err != nil { + t.Fatal(err) + } + defer nuke(runtime) + + srv := &Server{runtime: runtime} + + buildfile := NewBuildFile(srv, &utils.NopWriter{}) + + imgId, err := buildfile.Build(strings.NewReader(Dockerfile), nil) + if err != nil { + t.Fatal(err) + } + + builder := NewBuilder(runtime) + container, err := builder.Create( + &Config{ + Image: imgId, + Cmd: []string{"cat", "/tmp/passwd"}, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container) + + output, err := container.Output() + if err != nil { + t.Fatal(err) + } + if string(output) != "root:testpass\n" { + t.Fatalf("Unexpected output. Read '%s', expected '%s'", output, "root:testpass\n") + } + + container2, err := builder.Create( + &Config{ + Image: imgId, + Cmd: []string{"ls", "-d", "/var/run/sshd"}, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container2) + + output, err = container2.Output() + if err != nil { + t.Fatal(err) + } + if string(output) != "/var/run/sshd\n" { + t.Fatal("/var/run/sshd has not been created") + } +} diff --git a/runtime_test.go b/runtime_test.go index 27db53a884..55671e12b6 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -8,7 +8,6 @@ import ( "io/ioutil" "net" "os" - "os/exec" "os/user" "sync" "testing" From 54af0536232ca71d37f7c6440f1bb17b3ed112db Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:40:22 -0700 Subject: [PATCH 25/42] Make sure the last line of docker build is the image id --- buildfile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildfile.go b/buildfile.go index 15577b98ef..23f2f47172 100644 --- a/buildfile.go +++ b/buildfile.go @@ -355,7 +355,7 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { for i := range b.tmpImages { delete(b.tmpImages, i) } - fmt.Fprintf(b.out, "Build finished. image id: %s\n", b.image) + fmt.Fprintf(b.out, "Build success.\n Image id:\n%s\n", b.image) return b.image, nil } for i := range b.tmpContainers { From cd0de83917e775fcdcd3ce4e592b627b7eeeac64 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 17:12:24 -0700 Subject: [PATCH 26/42] Cereate a new registry object for each request (~session) --- api.go | 15 ++++++++--- registry/registry.go | 3 +++ server.go | 61 ++++++++++++++++++++++---------------------- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/api.go b/api.go index 941e87e6f0..82fb4b4ad3 100644 --- a/api.go +++ b/api.go @@ -60,7 +60,12 @@ func getBoolParam(value string) (bool, error) { } func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - b, err := json.Marshal(srv.registry.GetAuthConfig(false)) + // FIXME: Handle multiple login at once + authConfig, err := auth.LoadConfig(srv.runtime.root) + if err != nil { + return err + } + b, err := json.Marshal(&auth.AuthConfig{Username: authConfig.Username, Email: authConfig.Email}) if err != nil { return err } @@ -69,11 +74,16 @@ func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reques } func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { + // FIXME: Handle multiple login at once config := &auth.AuthConfig{} if err := json.NewDecoder(r.Body).Decode(config); err != nil { return err } - authConfig := srv.registry.GetAuthConfig(true) + + authConfig, err := auth.LoadConfig(srv.runtime.root) + if err != nil { + return err + } if config.Username == authConfig.Username { config.Password = authConfig.Password } @@ -83,7 +93,6 @@ func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reque if err != nil { return err } - srv.registry.ResetClient(newAuthConfig) if status != "" { b, err := json.Marshal(&ApiAuth{Status: status}) diff --git a/registry/registry.go b/registry/registry.go index bd361b5e74..36b01d643a 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -330,6 +330,9 @@ func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validat if validate { suffix = "images" } + + utils.Debugf("Image list pushed to index:\n%s\n", imgListJson) + req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/"+suffix, bytes.NewReader(imgListJson)) if err != nil { return nil, err diff --git a/server.go b/server.go index 3303c7c5a1..7c78db2c90 100644 --- a/server.go +++ b/server.go @@ -49,7 +49,8 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error { } func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) { - results, err := srv.registry.SearchRepositories(term) + + results, err := registry.NewRegistry(srv.runtime.root).SearchRepositories(term) if err != nil { return nil, err } @@ -291,8 +292,8 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error { return nil } -func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string, json bool) error { - history, err := srv.registry.GetRemoteHistory(imgId, registry, token) +func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgId, endpoint string, token []string, json bool) error { + history, err := r.GetRemoteHistory(imgId, endpoint, token) if err != nil { return err } @@ -302,7 +303,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri for _, id := range history { if !srv.runtime.graph.Exists(id) { fmt.Fprintf(out, utils.FormatStatus("Pulling %s metadata", json), id) - imgJson, err := srv.registry.GetRemoteImageJson(id, registry, token) + imgJson, err := r.GetRemoteImageJson(id, endpoint, token) if err != nil { // FIXME: Keep goging in case of error? return err @@ -314,7 +315,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri // Get the layer fmt.Fprintf(out, utils.FormatStatus("Pulling %s fs layer", json), id) - layer, contentLength, err := srv.registry.GetRemoteImageLayer(img.Id, registry, token) + layer, contentLength, err := r.GetRemoteImageLayer(img.Id, endpoint, token) if err != nil { return err } @@ -326,9 +327,9 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri return nil } -func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, json bool) error { +func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, remote, askedTag string, json bool) error { fmt.Fprintf(out, utils.FormatStatus("Pulling repository %s from %s", json), remote, auth.IndexServerAddress()) - repoData, err := srv.registry.GetRepositoryData(remote) + repoData, err := r.GetRepositoryData(remote) if err != nil { return err } @@ -340,7 +341,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, json b } utils.Debugf("Retrieving the tag list") - tagsList, err := srv.registry.GetRemoteTags(repoData.Endpoints, remote, repoData.Tokens) + tagsList, err := r.GetRemoteTags(repoData.Endpoints, remote, repoData.Tokens) if err != nil { return err } @@ -367,7 +368,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, json b fmt.Fprintf(out, utils.FormatStatus("Pulling image %s (%s) from %s", json), img.Id, img.Tag, remote) success := false for _, ep := range repoData.Endpoints { - if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens, json); err != nil { + if err := srv.pullImage(r, out, img.Id, "https://"+ep+"/v1", repoData.Tokens, json); err != nil { fmt.Fprintf(out, utils.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint\n", json), askedTag, err) continue } @@ -393,16 +394,17 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, json b return nil } -func (srv *Server) ImagePull(name, tag, registry string, out io.Writer, json bool) error { +func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, json bool) error { + r := registry.NewRegistry(srv.runtime.root) out = utils.NewWriteFlusher(out) - if registry != "" { - if err := srv.pullImage(out, name, registry, nil, json); err != nil { + if endpoint != "" { + if err := srv.pullImage(r, out, name, endpoint, nil, json); err != nil { return err } return nil } - if err := srv.pullRepository(out, name, tag, json); err != nil { + if err := srv.pullRepository(r, out, name, tag, json); err != nil { return err } @@ -475,21 +477,20 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat return imgList, nil } -func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string) error { +func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, name string, localRepo map[string]string) error { out = utils.NewWriteFlusher(out) fmt.Fprintf(out, "Processing checksums\n") imgList, err := srv.getImageList(localRepo) if err != nil { return err } - fmt.Fprintf(out, "Sending image list\n") + fmt.Fprintf(out, "Sending images list\n") - repoData, err := srv.registry.PushImageJsonIndex(name, imgList, false) + repoData, err := r.PushImageJsonIndex(name, imgList, false) if err != nil { return err } - // FIXME: Send only needed images for _, ep := range repoData.Endpoints { fmt.Fprintf(out, "Pushing repository %s to %s (%d tags)\r\n", name, ep, len(localRepo)) // For each image within the repo, push them @@ -498,24 +499,24 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri fmt.Fprintf(out, "Image %s already on registry, skipping\n", name) continue } - if err := srv.pushImage(out, name, elem.Id, ep, repoData.Tokens); err != nil { + if err := srv.pushImage(r, out, name, elem.Id, ep, repoData.Tokens); err != nil { // FIXME: Continue on error? return err } fmt.Fprintf(out, "Pushing tags for rev [%s] on {%s}\n", elem.Id, ep+"/users/"+name+"/"+elem.Tag) - if err := srv.registry.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil { + if err := r.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil { return err } } } - if _, err := srv.registry.PushImageJsonIndex(name, imgList, true); err != nil { + if _, err := r.PushImageJsonIndex(name, imgList, true); err != nil { return err } return nil } -func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []string) error { +func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgId, ep string, token []string) error { out = utils.NewWriteFlusher(out) jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json")) if err != nil { @@ -534,7 +535,7 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st } // Send the json - if err := srv.registry.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil { + if err := r.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil { if err == registry.ErrAlreadyExists { fmt.Fprintf(out, "Image %s already uploaded ; skipping\n", imgData.Id) return nil @@ -569,20 +570,22 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st } // Send the layer - if err := srv.registry.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, "", false), ep, token); err != nil { + if err := r.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, "", false), ep, token); err != nil { return err } return nil } -func (srv *Server) ImagePush(name, registry string, out io.Writer) error { +func (srv *Server) ImagePush(name, endpoint string, out io.Writer) error { out = utils.NewWriteFlusher(out) img, err := srv.runtime.graph.Get(name) + r := registry.NewRegistry(srv.runtime.root) + if err != nil { fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name])) // If it fails, try to get the repository if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists { - if err := srv.pushRepository(out, name, localRepo); err != nil { + if err := srv.pushRepository(r, out, name, localRepo); err != nil { return err } return nil @@ -591,7 +594,7 @@ func (srv *Server) ImagePush(name, registry string, out io.Writer) error { return err } fmt.Fprintf(out, "The push refers to an image: [%s]\n", name) - if err := srv.pushImage(out, name, img.Id, registry, nil); err != nil { + if err := srv.pushImage(r, out, name, img.Id, endpoint, nil); err != nil { return err } return nil @@ -871,14 +874,12 @@ func NewServer(autoRestart bool) (*Server, error) { return nil, err } srv := &Server{ - runtime: runtime, - registry: registry.NewRegistry(runtime.root), + runtime: runtime, } runtime.srv = srv return srv, nil } type Server struct { - runtime *Runtime - registry *registry.Registry + runtime *Runtime } From b76d6120ac66a853d177f7e53318ab1ee75dca92 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 17:35:10 -0700 Subject: [PATCH 27/42] Update tests with new cookies for registry --- api.go | 11 +++++++++-- api_test.go | 19 +++++++++---------- auth/auth.go | 19 +++++++++++++++---- runtime_test.go | 4 +--- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/api.go b/api.go index 82fb4b4ad3..f044fe9c96 100644 --- a/api.go +++ b/api.go @@ -61,9 +61,13 @@ func getBoolParam(value string) (bool, error) { func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { // FIXME: Handle multiple login at once + // FIXME: return specific error code if config file missing? authConfig, err := auth.LoadConfig(srv.runtime.root) if err != nil { - return err + if err != auth.ErrConfigFileMissing { + return err + } + authConfig = &auth.AuthConfig{} } b, err := json.Marshal(&auth.AuthConfig{Username: authConfig.Username, Email: authConfig.Email}) if err != nil { @@ -82,7 +86,10 @@ func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reque authConfig, err := auth.LoadConfig(srv.runtime.root) if err != nil { - return err + if err != auth.ErrConfigFileMissing { + return err + } + authConfig = &auth.AuthConfig{} } if config.Username == authConfig.Username { config.Password = authConfig.Password diff --git a/api_test.go b/api_test.go index f94ba23fa0..f364c6c895 100644 --- a/api_test.go +++ b/api_test.go @@ -26,8 +26,7 @@ func TestGetAuth(t *testing.T) { defer nuke(runtime) srv := &Server{ - runtime: runtime, - registry: registry.NewRegistry(runtime.root), + runtime: runtime, } r := httptest.NewRecorder() @@ -56,7 +55,7 @@ func TestGetAuth(t *testing.T) { t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code) } - newAuthConfig := srv.registry.GetAuthConfig(false) + newAuthConfig := registry.NewRegistry(runtime.root).GetAuthConfig(false) if newAuthConfig.Username != authConfig.Username || newAuthConfig.Email != authConfig.Email { t.Fatalf("The auth configuration hasn't been set correctly") @@ -247,8 +246,7 @@ func TestGetImagesSearch(t *testing.T) { defer nuke(runtime) srv := &Server{ - runtime: runtime, - registry: registry.NewRegistry(runtime.root), + runtime: runtime, } r := httptest.NewRecorder() @@ -504,15 +502,16 @@ func TestPostAuth(t *testing.T) { defer nuke(runtime) srv := &Server{ - runtime: runtime, - registry: registry.NewRegistry(runtime.root), + runtime: runtime, } - authConfigOrig := &auth.AuthConfig{ + config := &auth.AuthConfig{ Username: "utest", Email: "utest@yopmail.com", } - srv.registry.ResetClient(authConfigOrig) + + authStr := auth.EncodeAuth(config) + auth.SaveConfig(runtime.root, authStr, config.Email) r := httptest.NewRecorder() if err := getAuth(srv, API_VERSION, r, nil, nil); err != nil { @@ -524,7 +523,7 @@ func TestPostAuth(t *testing.T) { t.Fatal(err) } - if authConfig.Username != authConfigOrig.Username || authConfig.Email != authConfigOrig.Email { + if authConfig.Username != config.Username || authConfig.Email != config.Email { t.Errorf("The retrieve auth mismatch with the one set.") } } diff --git a/auth/auth.go b/auth/auth.go index 2b99c95038..9c34604419 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -3,6 +3,7 @@ package auth import ( "encoding/base64" "encoding/json" + "errors" "fmt" "io/ioutil" "net/http" @@ -17,6 +18,12 @@ const CONFIGFILE = ".dockercfg" // the registry server we want to login against const INDEX_SERVER = "https://index.docker.io/v1" +//const INDEX_SERVER = "http://indexstaging-docker.dotcloud.com/" + +var ( + ErrConfigFileMissing error = errors.New("The Auth config file is missing") +) + type AuthConfig struct { Username string `json:"username"` Password string `json:"password"` @@ -75,7 +82,7 @@ func DecodeAuth(authStr string) (*AuthConfig, error) { func LoadConfig(rootPath string) (*AuthConfig, error) { confFile := path.Join(rootPath, CONFIGFILE) if _, err := os.Stat(confFile); err != nil { - return &AuthConfig{}, fmt.Errorf("The Auth config file is missing") + return nil, ErrConfigFileMissing } b, err := ioutil.ReadFile(confFile) if err != nil { @@ -97,7 +104,7 @@ func LoadConfig(rootPath string) (*AuthConfig, error) { } // save the auth config -func saveConfig(rootPath, authStr string, email string) error { +func SaveConfig(rootPath, authStr string, email string) error { confFile := path.Join(rootPath, CONFIGFILE) if len(email) == 0 { os.Remove(confFile) @@ -161,7 +168,9 @@ func Login(authConfig *AuthConfig) (string, error) { status = "Login Succeeded\n" storeConfig = true } else if resp.StatusCode == 401 { - saveConfig(authConfig.rootPath, "", "") + if err := SaveConfig(authConfig.rootPath, "", ""); err != nil { + return "", err + } return "", fmt.Errorf("Wrong login/password, please try again") } else { return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body, @@ -175,7 +184,9 @@ func Login(authConfig *AuthConfig) (string, error) { } if storeConfig { authStr := EncodeAuth(authConfig) - saveConfig(authConfig.rootPath, authStr, authConfig.Email) + if err := SaveConfig(authConfig.rootPath, authStr, authConfig.Email); err != nil { + return "", err + } } return status, nil } diff --git a/runtime_test.go b/runtime_test.go index 6c4ec5ded4..8f62fa80fc 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -2,7 +2,6 @@ package docker import ( "fmt" - "github.com/dotcloud/docker/registry" "github.com/dotcloud/docker/utils" "io" "io/ioutil" @@ -71,8 +70,7 @@ func init() { // Create the "Server" srv := &Server{ - runtime: runtime, - registry: registry.NewRegistry(runtime.root), + runtime: runtime, } // Retrieve the Image if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout, false); err != nil { From 24ddfe3f25f99db5a23f62d411c949b2236288a1 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 19:39:09 -0700 Subject: [PATCH 28/42] Documented who decides what and how. --- AUTHORS | 5 +++ CONTRIBUTING.md | 69 ++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + auth/MAINTAINERS | 1 + contrib/MAINTAINERS | 1 + contrib/docker-build/MAINTAINERS | 1 + docs/MAINTAINERS | 2 + docs/sources/api/MAINTAINERS | 1 + docs/theme/MAINTAINERS | 1 + docs/website/MAINTAINERS | 1 + packaging/MAINTAINERS | 1 + registry/MAINTAINERS | 3 ++ testing/MAINTAINERS | 1 + 13 files changed, 89 insertions(+) create mode 100644 MAINTAINERS create mode 120000 auth/MAINTAINERS create mode 100644 contrib/MAINTAINERS create mode 100644 contrib/docker-build/MAINTAINERS create mode 100644 docs/MAINTAINERS create mode 100644 docs/sources/api/MAINTAINERS create mode 100644 docs/theme/MAINTAINERS create mode 100644 docs/website/MAINTAINERS create mode 100644 packaging/MAINTAINERS create mode 100644 registry/MAINTAINERS create mode 100644 testing/MAINTAINERS diff --git a/AUTHORS b/AUTHORS index e7c6834cf4..fdddedde15 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,8 @@ +# This file lists all individuals having contributed content to the repository. +# If you're submitting a patch, please add your name here in alphabetical order as part of the patch. +# +# For a list of active project maintainers, see the MAINTAINERS file. +# Al Tobey Alexey Shamrin Andrea Luzzardi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2e1141c30f..1b3c63e7d7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -88,3 +88,72 @@ Add your name to the AUTHORS file, but make sure the list is sorted and your name and email address match your git configuration. The AUTHORS file is regenerated occasionally from the git commit history, so a mismatch may result in your changes being overwritten. + + +## Decision process + +### How are decisions made? + +Short answer: with pull requests to the docker repository. + +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, +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.* + +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 +the API specification. A philosophy change is a change to the philosophy manifesto. And so on. + +All decisions affecting docker, big and small, follow the same 3 steps: + +* Step 1: Open a pull request. Anyone can do this. + +* Step 2: Discuss the pull request. Anyone can do this. + +* Step 3: Accept or refuse a pull request. The relevant maintainer does this (see below "Who decides what?") + + +### Who decides what? + +So all decisions are pull requests, and the relevant maintainer makes the decision by accepting or refusing the pull request. +But how do we identify the relevant maintainer for a given pull request? + +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), +with yours truly, Solomon Hykes, in the role of BDFL. +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. + +The relevant maintainer for a pull request is assigned in 3 steps: + +* 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. + +* 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. + +* 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. + + +### I'm a maintainer, should I make pull requests too? + +Primary maintainers are not required to create pull requests when changing their own subdirectory, but secondary maintainers are. + +### Who assigns maintainers? + +Solomon. + +### How can I become a maintainer? + +Step 1: learn the component inside out +Step 2: make yourself useful by contributing code, bugfixes, support etc. +Step 3: volunteer on the irc channel (#docker@freenode) + +Don't forget: being a maintainer is a time investment. Make sure you will have time to make yourself available. +You don't have to be a maintainer to make a difference on the project! + +### What are a maintainer's responsibility? + +It is every maintainer's responsibility to: + a) be aware of which pull requests they must review, and do so quickly + b) communicate clearly and transparently with other maintainers + c) be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. + d) make sure they respect the philosophy and design of the project + +### How is this process changed? + +Just like everything else: by making a pull request :) diff --git a/MAINTAINERS b/MAINTAINERS new file mode 100644 index 0000000000..a892409328 --- /dev/null +++ b/MAINTAINERS @@ -0,0 +1,2 @@ +Solomon Hykes +Guillaume Charmes diff --git a/auth/MAINTAINERS b/auth/MAINTAINERS new file mode 120000 index 0000000000..dcaec6ec44 --- /dev/null +++ b/auth/MAINTAINERS @@ -0,0 +1 @@ +../registry/MAINTAINERS \ No newline at end of file diff --git a/contrib/MAINTAINERS b/contrib/MAINTAINERS new file mode 100644 index 0000000000..0b7931f907 --- /dev/null +++ b/contrib/MAINTAINERS @@ -0,0 +1 @@ +# Maintainer wanted! Enroll on #docker@freenode diff --git a/contrib/docker-build/MAINTAINERS b/contrib/docker-build/MAINTAINERS new file mode 100644 index 0000000000..e1c6f2ccfc --- /dev/null +++ b/contrib/docker-build/MAINTAINERS @@ -0,0 +1 @@ +Solomon Hykes diff --git a/docs/MAINTAINERS b/docs/MAINTAINERS new file mode 100644 index 0000000000..f079e58481 --- /dev/null +++ b/docs/MAINTAINERS @@ -0,0 +1,2 @@ +Andy Rothfusz +Ken Cochrane diff --git a/docs/sources/api/MAINTAINERS b/docs/sources/api/MAINTAINERS new file mode 100644 index 0000000000..e1c6f2ccfc --- /dev/null +++ b/docs/sources/api/MAINTAINERS @@ -0,0 +1 @@ +Solomon Hykes diff --git a/docs/theme/MAINTAINERS b/docs/theme/MAINTAINERS new file mode 100644 index 0000000000..6df367c073 --- /dev/null +++ b/docs/theme/MAINTAINERS @@ -0,0 +1 @@ +Thatcher Penskens diff --git a/docs/website/MAINTAINERS b/docs/website/MAINTAINERS new file mode 100644 index 0000000000..6df367c073 --- /dev/null +++ b/docs/website/MAINTAINERS @@ -0,0 +1 @@ +Thatcher Penskens diff --git a/packaging/MAINTAINERS b/packaging/MAINTAINERS new file mode 100644 index 0000000000..228bd562e5 --- /dev/null +++ b/packaging/MAINTAINERS @@ -0,0 +1 @@ +Daniel Mizyrycki diff --git a/registry/MAINTAINERS b/registry/MAINTAINERS new file mode 100644 index 0000000000..b11dfc061b --- /dev/null +++ b/registry/MAINTAINERS @@ -0,0 +1,3 @@ +Sam Alba +Joffrey Fuhrer +Ken Cochrane diff --git a/testing/MAINTAINERS b/testing/MAINTAINERS new file mode 100644 index 0000000000..228bd562e5 --- /dev/null +++ b/testing/MAINTAINERS @@ -0,0 +1 @@ +Daniel Mizyrycki From 7181edf4b2fe17791cc4f843271d9c7fce0f14f3 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 20:44:41 -0700 Subject: [PATCH 29/42] getmaintainer.sh: parse MAINTAINERS file to determine who should review changes to a particular file or directory --- hack/getmaintainer.sh | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 hack/getmaintainer.sh diff --git a/hack/getmaintainer.sh b/hack/getmaintainer.sh new file mode 100755 index 0000000000..2c24bacc89 --- /dev/null +++ b/hack/getmaintainer.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +if [ $# -ne 1 ]; then + echo >&2 "Usage: $0 PATH" + echo >&2 "Show the primary and secondary maintainers for a given path" + exit 1 +fi + +set -e + +DEST=$1 +DESTFILE="" +if [ ! -d $DEST ]; then + DESTFILE=$(basename $DEST) + DEST=$(dirname $DEST) +fi + +MAINTAINERS=() +cd $DEST +while true; do + if [ -e ./MAINTAINERS ]; then + { + while read line; do + re='^([^:]*): *(.*)$' + file=$(echo $line | sed -E -n "s/$re/\1/p") + if [ ! -z "$file" ]; then + if [ "$file" = "$DESTFILE" ]; then + echo "Override: $line" + maintainer=$(echo $line | sed -E -n "s/$re/\2/p") + MAINTAINERS=("$maintainer" "${MAINTAINERS[@]}") + fi + else + MAINTAINERS+=("$line"); + fi + done; + } < MAINTAINERS + fi + if [ -d .git ]; then + break + fi + if [ "$(pwd)" = "/" ]; then + break + fi + cd .. +done + +PRIMARY="${MAINTAINERS[0]}" +PRIMARY_FIRSTNAME=$(echo $PRIMARY | cut -d' ' -f1) + +firstname() { + echo $1 | cut -d' ' -f1 +} + +echo "--- $PRIMARY is the PRIMARY MAINTAINER of $1. Assign pull requests to him." +echo "$(firstname $PRIMARY) may assign pull requests to the following secondary maintainers:" +for SECONDARY in "${MAINTAINERS[@]:1}"; do + echo "--- $SECONDARY" +done From aa42c6f2a284c1095ba65866aa8c28f3e5c31fcd Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 20:45:12 -0700 Subject: [PATCH 30/42] Added Victor and Daniel as maintainers for api.go and Vagrantfile, respectively --- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index a892409328..6203feeb03 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1,2 +1,4 @@ Solomon Hykes Guillaume Charmes +api.go: Victor Vieux +Vagrantfile: Daniel Mizyrycki From 286ce266b4415ae27d5d9cc177ad12db44845a84 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 20:55:07 -0700 Subject: [PATCH 31/42] allmaintainers.sh: print a flat list of all maintainers of a directory (including sub-directories) --- hack/allmaintainers.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 hack/allmaintainers.sh diff --git a/hack/allmaintainers.sh b/hack/allmaintainers.sh new file mode 100755 index 0000000000..1ea5a9f743 --- /dev/null +++ b/hack/allmaintainers.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +find $1 -name MAINTAINERS -exec cat {} ';' | sed -E -e 's/^[^:]*: *(.*)$/\1/' | grep -E -v -e '^ *$' -e '^ *#.*$' | sort -u From 3bac27f2405c746c068dbe31f8f205472d0f1b03 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 22:26:42 -0600 Subject: [PATCH 32/42] Fixed formatting of CONTRIBUTING.md --- CONTRIBUTING.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1b3c63e7d7..84c854007d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -139,9 +139,9 @@ Solomon. ### How can I become a maintainer? -Step 1: learn the component inside out -Step 2: make yourself useful by contributing code, bugfixes, support etc. -Step 3: volunteer on the irc channel (#docker@freenode) +* Step 1: learn the component inside out +* Step 2: make yourself useful by contributing code, bugfixes, support etc. +* Step 3: volunteer on the irc channel (#docker@freenode) Don't forget: being a maintainer is a time investment. Make sure you will have time to make yourself available. You don't have to be a maintainer to make a difference on the project! @@ -149,10 +149,11 @@ You don't have to be a maintainer to make a difference on the project! ### What are a maintainer's responsibility? It is every maintainer's responsibility to: - a) be aware of which pull requests they must review, and do so quickly - b) communicate clearly and transparently with other maintainers - c) be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. - d) make sure they respect the philosophy and design of the project + +# Be aware of which pull requests they must review, and do so quickly +# Communicate clearly and transparently with other maintainers +# Be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. +# Make sure they respect the philosophy and design of the project ### How is this process changed? From dc1fa0745f779d8c9a513dea71021d263b89ca5f Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 22:33:48 -0600 Subject: [PATCH 33/42] Improved wording of a maintainer's responsibilities --- CONTRIBUTING.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 84c854007d..7d90e28ca8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -150,10 +150,10 @@ You don't have to be a maintainer to make a difference on the project! It is every maintainer's responsibility to: -# Be aware of which pull requests they must review, and do so quickly -# Communicate clearly and transparently with other maintainers -# Be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. -# Make sure they respect the philosophy and design of the project +* 1) Expose a clear roadmap for improving their component. +* 2) Deliver prompt feedback and decisions on pull requests. +* 3) Be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. +* 4) Make sure their component respects the philosophy, design and roadmap of the project. ### How is this process changed? From 11550c60639af2af1e8cb2e76e27510722421863 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 21:38:35 -0700 Subject: [PATCH 34/42] Removed debug output in 'docker version' --- commands.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/commands.go b/commands.go index 2af7e548fc..1e7dd0632c 100644 --- a/commands.go +++ b/commands.go @@ -366,12 +366,10 @@ func (cli *DockerCli) CmdWait(args ...string) error { // 'docker version': show version information func (cli *DockerCli) CmdVersion(args ...string) error { cmd := Subcmd("version", "", "Show the docker version information.") - fmt.Println(len(args)) if err := cmd.Parse(args); err != nil { return nil } - fmt.Println(cmd.NArg()) if cmd.NArg() > 0 { cmd.Usage() return nil From c00d1a6ebe8dd607b1876e505e1761c2a548aa53 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 29 May 2013 11:40:54 +0000 Subject: [PATCH 35/42] improve attach --- commands.go | 93 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 28 deletions(-) diff --git a/commands.go b/commands.go index 6c4dcd14d6..09595e9c38 100644 --- a/commands.go +++ b/commands.go @@ -925,7 +925,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error { v.Set("stdout", "1") v.Set("stderr", "1") - if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), false); err != nil { + if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), false, nil, os.Stdout); err != nil { return err } return nil @@ -951,16 +951,33 @@ func (cli *DockerCli) CmdAttach(args ...string) error { if err != nil { return err } - + connections := 1 + if !container.Config.Tty { + connections += 1 + } + c := make(chan error, 2) + cli.monitorTtySize(cmd.Arg(0)) + if !container.Config.Tty { + go func() { + c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr) + }() + } v := url.Values{} v.Set("stream", "1") - v.Set("stdout", "1") - v.Set("stderr", "1") v.Set("stdin", "1") - - cli.monitorTtySize(cmd.Arg(0)) - if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty); err != nil { - return err + v.Set("stdout", "1") + if container.Config.Tty { + v.Set("stderr", "1") + } + go func() { + c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout) + }() + for connections > 0 { + err := <-c + if err != nil { + return err + } + connections -= 1 } return nil } @@ -1124,19 +1141,12 @@ func (cli *DockerCli) CmdRun(args ...string) error { fmt.Fprintln(os.Stderr, "WARNING: ", warning) } - v := url.Values{} - v.Set("logs", "1") - v.Set("stream", "1") - - if config.AttachStdin { - v.Set("stdin", "1") + connections := 0 + if config.AttachStdin || config.AttachStdout { + connections += 1 } - if config.AttachStdout { - v.Set("stdout", "1") - } - if config.AttachStderr { - v.Set("stderr", "1") - + if !config.Tty && config.AttachStderr { + connections += 1 } //start the container @@ -1145,10 +1155,38 @@ func (cli *DockerCli) CmdRun(args ...string) error { return err } - if config.AttachStdin || config.AttachStdout || config.AttachStderr { + if connections > 0 { + c := make(chan error, connections) cli.monitorTtySize(out.Id) - if err := cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty); err != nil { - return err + + if !config.Tty && config.AttachStderr { + go func() { + c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr) + }() + } + + v := url.Values{} + v.Set("logs", "1") + v.Set("stream", "1") + + if config.AttachStdin { + v.Set("stdin", "1") + } + if config.AttachStdout { + v.Set("stdout", "1") + } + if config.Tty && config.AttachStderr { + v.Set("stderr", "1") + } + go func() { + c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout) + }() + for connections > 0 { + err := <-c + if err != nil { + return err + } + connections -= 1 } } if !config.AttachStdout && !config.AttachStderr { @@ -1284,7 +1322,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e return nil } -func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error { +func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.File, out io.Writer) error { req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", API_VERSION, path), nil) if err != nil { return err @@ -1302,20 +1340,19 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error { defer rwc.Close() receiveStdout := utils.Go(func() error { - _, err := io.Copy(os.Stdout, br) + _, err := io.Copy(out, br) return err }) - if setRawTerminal && term.IsTerminal(int(os.Stdin.Fd())) && os.Getenv("NORAW") == "" { + if in != nil && setRawTerminal && term.IsTerminal(int(in.Fd())) && os.Getenv("NORAW") == "" { if oldState, err := term.SetRawTerminal(); err != nil { return err } else { defer term.RestoreTerminal(oldState) } } - sendStdin := utils.Go(func() error { - _, err := io.Copy(rwc, os.Stdin) + _, err := io.Copy(rwc, in) if err := rwc.(*net.TCPConn).CloseWrite(); err != nil { fmt.Fprintf(os.Stderr, "Couldn't send EOF: %s\n", err) } From 044bdc1b5fc748e98e7baaa7e95ce216cc667323 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 29 May 2013 13:42:20 +0000 Subject: [PATCH 36/42] fix ps output --- commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 2af7e548fc..e34c40f8cc 100644 --- a/commands.go +++ b/commands.go @@ -871,9 +871,9 @@ func (cli *DockerCli) CmdPs(args ...string) error { for _, out := range outs { if !*quiet { if *noTrunc { - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports) + 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) } else { - 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), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports) + 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) } } else { if *noTrunc { From e33ba9b36daa5e72e33d65b316059cddc756e0e9 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 29 May 2013 14:14:51 +0000 Subject: [PATCH 37/42] split stdout and stderr in run if not -t --- commands.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/commands.go b/commands.go index 899b847ae9..38a30610f7 100644 --- a/commands.go +++ b/commands.go @@ -1016,29 +1016,32 @@ func (cli *DockerCli) CmdAttach(args ...string) error { if err != nil { return err } + + splitStderr := container.Config.Tty + connections := 1 - if !container.Config.Tty { + if splitStderr { connections += 1 } - c := make(chan error, 2) + chErrors := make(chan error, connections) cli.monitorTtySize(cmd.Arg(0)) - if !container.Config.Tty { + if splitStderr { go func() { - c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr) + chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr) }() } v := url.Values{} v.Set("stream", "1") v.Set("stdin", "1") v.Set("stdout", "1") - if container.Config.Tty { + if !splitStderr { v.Set("stderr", "1") } go func() { - c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout) + chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout) }() for connections > 0 { - err := <-c + err := <-chErrors if err != nil { return err } @@ -1206,11 +1209,13 @@ func (cli *DockerCli) CmdRun(args ...string) error { fmt.Fprintln(os.Stderr, "WARNING: ", warning) } + splitStderr := !config.Tty + connections := 0 - if config.AttachStdin || config.AttachStdout { + if config.AttachStdin || config.AttachStdout || (!splitStderr && config.AttachStderr) { connections += 1 } - if !config.Tty && config.AttachStderr { + if splitStderr && config.AttachStderr { connections += 1 } @@ -1221,12 +1226,12 @@ func (cli *DockerCli) CmdRun(args ...string) error { } if connections > 0 { - c := make(chan error, connections) + chErrors := make(chan error, connections) cli.monitorTtySize(out.Id) - if !config.Tty && config.AttachStderr { + if splitStderr && config.AttachStderr { go func() { - c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr) + chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr) }() } @@ -1240,14 +1245,14 @@ func (cli *DockerCli) CmdRun(args ...string) error { if config.AttachStdout { v.Set("stdout", "1") } - if config.Tty && config.AttachStderr { + if !splitStderr && config.AttachStderr { v.Set("stderr", "1") } go func() { - c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout) + chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout) }() for connections > 0 { - err := <-c + err := <-chErrors if err != nil { return err } From b2084a9c599d91fa1460116ef0c8d509d3353103 Mon Sep 17 00:00:00 2001 From: Renato Riccieri Santos Zannon Date: Thu, 30 May 2013 01:56:08 -0300 Subject: [PATCH 38/42] Add IP forwarding config to archlinux guide I had this small issue when following this guide on my Arch box, and I don't think it is specific to any configuration I have. --- docs/sources/installation/archlinux.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/sources/installation/archlinux.rst b/docs/sources/installation/archlinux.rst index 9e3766eb26..722c150194 100644 --- a/docs/sources/installation/archlinux.rst +++ b/docs/sources/installation/archlinux.rst @@ -67,3 +67,21 @@ To start on system boot: :: sudo systemctl enable docker + +Network Configuration +--------------------- + +IPv4 packet forwarding is disabled by default on Arch, so internet access from inside +the container may not work. + +To enable the forwarding, run as root on the host system: + +:: + + sysctl net.ipv4.ip_forward=1 + +And, to make it persistent across reboots, enable it on the host's **/etc/sysctl.conf**: + +:: + + net.ipv4.ip_forward=1 From 2a53717e8ff01df7c58485f89845bad31e50f497 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 30 May 2013 13:45:39 +0000 Subject: [PATCH 39/42] if address already in use in unit tests, try a different port --- runtime_test.go | 53 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/runtime_test.go b/runtime_test.go index 384cbd1eb8..adb5e55bc7 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -5,9 +5,12 @@ import ( "github.com/dotcloud/docker/utils" "io" "io/ioutil" + "log" "net" "os" "os/user" + "strconv" + "strings" "sync" "testing" "time" @@ -277,24 +280,50 @@ func TestGet(t *testing.T) { } +func findAvailalblePort(runtime *Runtime, port int) (*Container, error) { + strPort := strconv.Itoa(port) + container, err := NewBuilder(runtime).Create(&Config{ + Image: GetTestImage(runtime).Id, + Cmd: []string{"sh", "-c", "echo well hello there | nc -l -p " + strPort}, + PortSpecs: []string{strPort}, + }, + ) + if err != nil { + return nil, err + } + if err := container.Start(); err != nil { + if strings.Contains(err.Error(), "address already in use") { + return nil, nil + } + return nil, err + } + return container, nil +} + // Run a container with a TCP port allocated, and test that it can receive connections on localhost func TestAllocatePortLocalhost(t *testing.T) { runtime, err := newTestRuntime() if err != nil { t.Fatal(err) } - container, err := NewBuilder(runtime).Create(&Config{ - Image: GetTestImage(runtime).Id, - Cmd: []string{"sh", "-c", "echo well hello there | nc -l -p 5555"}, - PortSpecs: []string{"5555"}, - }, - ) - if err != nil { - t.Fatal(err) - } - if err := container.Start(); err != nil { - t.Fatal(err) + port := 5554 + + var container *Container + for { + port += 1 + log.Println("Trying port", port) + t.Log("Trying port", port) + container, err = findAvailalblePort(runtime, port) + if container != nil { + break + } + if err != nil { + t.Fatal(err) + } + log.Println("Port", port, "already in use") + t.Log("Port", port, "already in use") } + defer container.Kill() setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() { @@ -308,7 +337,7 @@ func TestAllocatePortLocalhost(t *testing.T) { conn, err := net.Dial("tcp", fmt.Sprintf( - "localhost:%s", container.NetworkSettings.PortMapping["5555"], + "localhost:%s", container.NetworkSettings.PortMapping[strconv.Itoa(port)], ), ) if err != nil { From 2c14d3949dcad3a98980929e0cb2d2326db7d8fe Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 30 May 2013 14:08:26 +0000 Subject: [PATCH 40/42] always display help in the same order --- commands.go | 60 ++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/commands.go b/commands.go index 97a249e54a..3ce5708aa1 100644 --- a/commands.go +++ b/commands.go @@ -73,37 +73,37 @@ func (cli *DockerCli) CmdHelp(args ...string) error { } } 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) - for cmd, description := range map[string]string{ - "attach": "Attach to a running container", - "build": "Build a container from a Dockerfile", - "commit": "Create a new image from a container's changes", - "diff": "Inspect changes on a container's filesystem", - "export": "Stream the contents of a container as a tar archive", - "history": "Show the history of an image", - "images": "List images", - "import": "Create a new filesystem image from the contents of a tarball", - "info": "Display system-wide information", - "insert": "Insert a file in an image", - "inspect": "Return low-level information on a container", - "kill": "Kill a running container", - "login": "Register or Login to the docker registry server", - "logs": "Fetch the logs of a container", - "port": "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT", - "ps": "List containers", - "pull": "Pull an image or a repository from the docker registry server", - "push": "Push an image or a repository to the docker registry server", - "restart": "Restart a running container", - "rm": "Remove a container", - "rmi": "Remove an image", - "run": "Run a command in a new container", - "search": "Search for an image in the docker index", - "start": "Start a stopped container", - "stop": "Stop a running container", - "tag": "Tag an image into a repository", - "version": "Show the docker version information", - "wait": "Block until a container stops, then print its exit code", + for _, command := range [][2]string{ + {"attach", "Attach to a running container"}, + {"build", "Build a container from a Dockerfile"}, + {"commit", "Create a new image from a container's changes"}, + {"diff", "Inspect changes on a container's filesystem"}, + {"export", "Stream the contents of a container as a tar archive"}, + {"history", "Show the history of an image"}, + {"images", "List images"}, + {"import", "Create a new filesystem image from the contents of a tarball"}, + {"info", "Display system-wide information"}, + {"insert", "Insert a file in an image"}, + {"inspect", "Return low-level information on a container"}, + {"kill", "Kill a running container"}, + {"login", "Register or Login to the docker registry server"}, + {"logs", "Fetch the logs of a container"}, + {"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"}, + {"ps", "List containers"}, + {"pull", "Pull an image or a repository from the docker registry server"}, + {"push", "Push an image or a repository to the docker registry server"}, + {"restart", "Restart a running container"}, + {"rm", "Remove a container"}, + {"rmi", "Remove an image"}, + {"run", "Run a command in a new container"}, + {"search", "Search for an image in the docker index"}, + {"start", "Start a stopped container"}, + {"stop", "Stop a running container"}, + {"tag", "Tag an image into a repository"}, + {"version", "Show the docker version information"}, + {"wait", "Block until a container stops}, then print its exit code"}, } { - help += fmt.Sprintf(" %-10.10s%s\n", cmd, description) + help += fmt.Sprintf(" %-10.10s%s\n", command[0], command[1]) } fmt.Println(help) return nil From 2ed1092dad9d2dec30945b06572befbba003ed1d Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 30 May 2013 11:26:47 -0700 Subject: [PATCH 41/42] * Documentation: removed 'building blocks' for now. --- docs/sources/concepts/buildingblocks.rst | 25 ------------------------ docs/sources/concepts/index.rst | 1 - 2 files changed, 26 deletions(-) delete mode 100644 docs/sources/concepts/buildingblocks.rst diff --git a/docs/sources/concepts/buildingblocks.rst b/docs/sources/concepts/buildingblocks.rst deleted file mode 100644 index 5f752ea47b..0000000000 --- a/docs/sources/concepts/buildingblocks.rst +++ /dev/null @@ -1,25 +0,0 @@ -:title: Building Blocks -:description: An introduction to docker and standard containers? -:keywords: containers, lxc, concepts, explanation - - -Building blocks -=============== - -.. _images: - -Images ------- -An original container image. These are stored on disk and are comparable with what you normally expect from a stopped virtual machine image. Images are stored (and retrieved from) repository - -Images are stored on your local file system under /var/lib/docker/graph - - -.. _containers: - -Containers ----------- -A container is a local version of an image. It can be running or stopped, The equivalent would be a virtual machine instance. - -Containers are stored on your local file system under /var/lib/docker/containers - diff --git a/docs/sources/concepts/index.rst b/docs/sources/concepts/index.rst index ba1f9f4718..8b02d15d33 100644 --- a/docs/sources/concepts/index.rst +++ b/docs/sources/concepts/index.rst @@ -13,5 +13,4 @@ Contents: :maxdepth: 1 ../index - buildingblocks From fc788956c5b1e3afb802d3fad1788377eea4e55a Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 30 May 2013 11:31:49 -0700 Subject: [PATCH 42/42] Make Victor Vieux a core maintainer --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 6203feeb03..dc0d1a19f6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1,4 +1,5 @@ Solomon Hykes Guillaume Charmes +Victor Vieux api.go: Victor Vieux Vagrantfile: Daniel Mizyrycki