From 800d9006883228365a375800254871397cb1a011 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 27 Jun 2013 15:25:31 -0700 Subject: [PATCH 1/9] Ignore stderr while doing tests --- commands.go | 2 +- commands_test.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index 3ce8c8eb9..dda7f13d4 100644 --- a/commands.go +++ b/commands.go @@ -1270,7 +1270,7 @@ func (cli *DockerCli) CmdRun(args ...string) error { } for _, warning := range runResult.Warnings { - fmt.Fprintln(cli.err, "WARNING: ", warning) + fmt.Fprintf(cli.err, "WARNING: %s\n", warning) } //start the container diff --git a/commands_test.go b/commands_test.go index 87c4c02a5..483c5e70c 100644 --- a/commands_test.go +++ b/commands_test.go @@ -132,11 +132,12 @@ func TestImages(t *testing.T) { } */ + // TestRunHostname checks that 'docker run -h' correctly sets a custom hostname func TestRunHostname(t *testing.T) { stdout, stdoutPipe := io.Pipe() - cli := NewDockerCli(nil, stdoutPipe, nil, testDaemonProto, testDaemonAddr) + cli := NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) defer cleanup(globalRuntime) c := make(chan struct{}) @@ -329,7 +330,7 @@ func TestRunAttachStdin(t *testing.T) { stdin, stdinPipe := io.Pipe() stdout, stdoutPipe := io.Pipe() - cli := NewDockerCli(stdin, stdoutPipe, nil, testDaemonProto, testDaemonAddr) + cli := NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) defer cleanup(globalRuntime) ch := make(chan struct{}) From f3d29695608d9ea9a3f92bcf872c62e158106919 Mon Sep 17 00:00:00 2001 From: Kimbro Staken Date: Mon, 8 Jul 2013 00:11:45 -0700 Subject: [PATCH 2/9] Override Entrypoint picked up from the base image that breaks run commands in builder --- buildfile.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/buildfile.go b/buildfile.go index 570a4eb72..df413a61f 100644 --- a/buildfile.go +++ b/buildfile.go @@ -108,7 +108,7 @@ func (b *buildFile) CmdRun(args string) error { } else { utils.Debugf("[BUILDER] Cache miss") } - + cid, err := b.run() if err != nil { return err @@ -279,6 +279,13 @@ func (b *buildFile) run() (string, error) { b.tmpContainers[c.ID] = struct{}{} fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(c.ID)) + // override the entry point that may have been picked up from the base image + c.Path = b.config.Cmd[0] + c.Args = b.config.Cmd[1:] + if err := c.ToDisk(); err != nil { + return "", err + } + //start the container hostConfig := &HostConfig{} if err := c.Start(hostConfig); err != nil { From 1d1d81b0bc52c6aff652f5515fd792f76e40f7c2 Mon Sep 17 00:00:00 2001 From: Kimbro Staken Date: Mon, 8 Jul 2013 00:18:47 -0700 Subject: [PATCH 3/9] Cleanup white space --- buildfile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildfile.go b/buildfile.go index df413a61f..303baac31 100644 --- a/buildfile.go +++ b/buildfile.go @@ -108,7 +108,7 @@ func (b *buildFile) CmdRun(args string) error { } else { utils.Debugf("[BUILDER] Cache miss") } - + cid, err := b.run() if err != nil { return err From e43ef364cb99585d3285f51f7ab308f8a77fe09e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 8 Jul 2013 15:23:04 -0700 Subject: [PATCH 4/9] Remove all network dependencies from the test suite --- api_test.go | 70 ----------------------------------------------- buildfile_test.go | 2 +- runtime_test.go | 22 +++++++++------ 3 files changed, 14 insertions(+), 80 deletions(-) diff --git a/api_test.go b/api_test.go index 6eb2584b0..d111f258c 100644 --- a/api_test.go +++ b/api_test.go @@ -5,7 +5,6 @@ import ( "bufio" "bytes" "encoding/json" - "github.com/dotcloud/docker/auth" "github.com/dotcloud/docker/utils" "io" "net" @@ -41,44 +40,6 @@ func TestGetBoolParam(t *testing.T) { } } -func TestPostAuth(t *testing.T) { - runtime, err := newTestRuntime() - if err != nil { - t.Fatal(err) - } - defer nuke(runtime) - - srv := &Server{ - runtime: runtime, - } - - r := httptest.NewRecorder() - - authConfig := &auth.AuthConfig{ - Username: "utest", - Password: "utest", - Email: "utest@yopmail.com", - } - - authConfigJSON, err := json.Marshal(authConfig) - if err != nil { - t.Fatal(err) - } - - req, err := http.NewRequest("POST", "/auth", bytes.NewReader(authConfigJSON)) - if err != nil { - t.Fatal(err) - } - - if err := postAuth(srv, APIVERSION, r, req, nil); err != nil { - t.Fatal(err) - } - - if r.Code != http.StatusOK && r.Code != 0 { - t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code) - } -} - func TestGetVersion(t *testing.T) { runtime, err := newTestRuntime() if err != nil { @@ -286,37 +247,6 @@ func TestGetImagesViz(t *testing.T) { } } -func TestGetImagesSearch(t *testing.T) { - runtime, err := newTestRuntime() - if err != nil { - t.Fatal(err) - } - defer nuke(runtime) - - srv := &Server{ - runtime: runtime, - } - - r := httptest.NewRecorder() - - req, err := http.NewRequest("GET", "/images/search?term=redis", nil) - if err != nil { - t.Fatal(err) - } - - if err := getImagesSearch(srv, APIVERSION, r, req, nil); err != nil { - t.Fatal(err) - } - - results := []APISearch{} - if err := json.Unmarshal(r.Body.Bytes(), &results); err != nil { - t.Fatal(err) - } - if len(results) < 2 { - t.Errorf("Expected at least 2 lines, %d found", len(results)) - } -} - func TestGetImagesHistory(t *testing.T) { runtime, err := newTestRuntime() if err != nil { diff --git a/buildfile_test.go b/buildfile_test.go index b7cc7be8e..8913284e8 100644 --- a/buildfile_test.go +++ b/buildfile_test.go @@ -84,7 +84,7 @@ run [ "$FOO" = "BAR" ] { ` -from docker-ut +from %s ENTRYPOINT /bin/echo CMD Hello world `, diff --git a/runtime_test.go b/runtime_test.go index d003426f2..07616ebce 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -17,11 +17,12 @@ import ( ) const ( - unitTestImageName = "docker-unit-tests" - unitTestImageID = "e9aa60c60128cad1" - unitTestStoreBase = "/var/lib/docker/unit-tests" - testDaemonAddr = "127.0.0.1:4270" - testDaemonProto = "tcp" + unitTestImageName = "docker-unit-tests" + unitTestImageID = "e9aa60c60128cad1" + unitTestNetworkBridge = "testdockbr0" + unitTestStoreBase = "/var/lib/docker/unit-tests" + testDaemonAddr = "127.0.0.1:4270" + testDaemonProto = "tcp" ) var globalRuntime *Runtime @@ -76,7 +77,7 @@ func init() { log.Fatal("docker tests need to be run as root") } - NetworkBridgeIface = "testdockbr0" + NetworkBridgeIface = unitTestNetworkBridge // Make it our Store root runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false) @@ -92,9 +93,12 @@ func init() { pullingPool: make(map[string]struct{}), pushingPool: make(map[string]struct{}), } - // Retrieve the Image - if err := srv.ImagePull(unitTestImageName, "", os.Stdout, utils.NewStreamFormatter(false), nil); err != nil { - panic(err) + // If the unit test is not found, try to download it. + if img, err := runtime.repositories.LookupImage(unitTestImageName); err != nil || img.ID != unitTestImageID { + // Retrieve the Image + if err := srv.ImagePull(unitTestImageName, "", os.Stdout, utils.NewStreamFormatter(false), nil); err != nil { + panic(err) + } } // Spawn a Daemon go func() { From 2b5553144a9249bbfed9be2a181b051a66350cb1 Mon Sep 17 00:00:00 2001 From: Kimbro Staken Date: Mon, 8 Jul 2013 16:03:18 -0700 Subject: [PATCH 5/9] Removing the save to disk as it was not really necessary --- buildfile.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/buildfile.go b/buildfile.go index 303baac31..75e31dba7 100644 --- a/buildfile.go +++ b/buildfile.go @@ -281,10 +281,7 @@ func (b *buildFile) run() (string, error) { // override the entry point that may have been picked up from the base image c.Path = b.config.Cmd[0] - c.Args = b.config.Cmd[1:] - if err := c.ToDisk(); err != nil { - return "", err - } + c.Args = b.config.Cmd[1:] //start the container hostConfig := &HostConfig{} From f64dbdbe3a147f58d04b6c39c6469fdd97427098 Mon Sep 17 00:00:00 2001 From: Kimbro Staken Date: Mon, 8 Jul 2013 00:11:45 -0700 Subject: [PATCH 6/9] Override Entrypoint picked up from the base image that breaks run commands in builder --- buildfile.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/buildfile.go b/buildfile.go index 570a4eb72..75e31dba7 100644 --- a/buildfile.go +++ b/buildfile.go @@ -279,6 +279,10 @@ func (b *buildFile) run() (string, error) { b.tmpContainers[c.ID] = struct{}{} fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(c.ID)) + // override the entry point that may have been picked up from the base image + c.Path = b.config.Cmd[0] + c.Args = b.config.Cmd[1:] + //start the container hostConfig := &HostConfig{} if err := c.Start(hostConfig); err != nil { From 9f1fc40a64fd6863dec5298099041493fee87db5 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 21 Jun 2013 19:42:17 -0700 Subject: [PATCH 7/9] * Hack: standardized docker's build environment in a Dockerfile --- Dockerfile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..46f9b585c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# This file describes the standard way to build Docker, using docker +docker-version 0.4.2 +from ubuntu:12.04 +maintainer Solomon Hykes +# Build dependencies +run apt-get install -y -q curl +run apt-get install -y -q git +# Install Go +run curl -s https://go.googlecode.com/files/go1.1.1.linux-amd64.tar.gz | tar -v -C /usr/local -xz +env PATH /usr/local/go/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin +env GOPATH /go +env CGO_ENABLED 0 +run cd /tmp && echo 'package main' > t.go && go test -a -i -v +# Download dependencies +run PKG=github.com/kr/pty REV=27435c699; git clone http://$PKG /go/src/$PKG && cd /go/src/$PKG && git checkout -f $REV +run PKG=github.com/gorilla/context/ REV=708054d61e5; git clone http://$PKG /go/src/$PKG && cd /go/src/$PKG && git checkout -f $REV +run PKG=github.com/gorilla/mux/ REV=9b36453141c; git clone http://$PKG /go/src/$PKG && cd /go/src/$PKG && git checkout -f $REV +# Run dependencies +run apt-get install -y iptables +# lxc requires updating ubuntu sources +run echo 'deb http://archive.ubuntu.com/ubuntu precise main universe' > /etc/apt/sources.list +run apt-get update +run apt-get install -y lxc +run apt-get install -y aufs-tools +# Upload docker source +add . /go/src/github.com/dotcloud/docker +# Build the binary +run cd /go/src/github.com/dotcloud/docker/docker && go install -ldflags "-X main.GITCOMMIT '??' -d -w" +env PATH /usr/local/go/bin:/go/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin +cmd ["docker"] From 05d7f85af9e5813ddb1c066e44c802dc33790547 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 9 Jul 2013 10:55:28 +0000 Subject: [PATCH 8/9] fix typo --- commands.go | 2 +- graph.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 0bd7965f7..0add994f6 100644 --- a/commands.go +++ b/commands.go @@ -72,7 +72,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error { return nil } } - help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -H=[tcp://%s:%d]: tcp://host:port to bind/connect to or unix://path/to/socker to use\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", DEFAULTHTTPHOST, DEFAULTHTTPPORT) + help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -H=[tcp://%s:%d]: tcp://host:port to bind/connect to or unix://path/to/socket to use\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", DEFAULTHTTPHOST, DEFAULTHTTPPORT) for _, command := range [][]string{ {"attach", "Attach to a running container"}, {"build", "Build a container from a Dockerfile"}, diff --git a/graph.go b/graph.go index 1417aade0..42d1bdbd4 100644 --- a/graph.go +++ b/graph.go @@ -162,7 +162,7 @@ func (graph *Graph) Register(layerData Archive, store bool, img *Image) error { // The archive is stored on disk and will be automatically deleted as soon as has been read. // If output is not nil, a human-readable progress bar will be written to it. // FIXME: does this belong in Graph? How about MktempFile, let the caller use it for archives? -func (graph *Graph) TempLayerArchive(id string, compression Compression, sf *utils.StreamFormatter, output io.Writer) (*TempArchive, error) { +func (graph *Graph) TempLayerArchive(id string, compression Compression, sf *utils.StreamFormatter, output io.Writer) (*TempArchive, error) { image, err := graph.Get(id) if err != nil { return nil, err From 91520838fc72f4004d65844b8e57df85473808a1 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 9 Jul 2013 10:48:33 -0700 Subject: [PATCH 9/9] Make sure container is not marked as ghost when it starts --- state.go | 1 + 1 file changed, 1 insertion(+) diff --git a/state.go b/state.go index 117659bf5..6480b9b42 100644 --- a/state.go +++ b/state.go @@ -29,6 +29,7 @@ func (s *State) String() string { func (s *State) setRunning(pid int) { s.Running = true + s.Ghost = false s.ExitCode = 0 s.Pid = pid s.StartedAt = time.Now()