From 65b2fd1698ee8fa4e3b753e02fdff44d0973d884 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 Upstream-commit: 800d9006883228365a375800254871397cb1a011 Component: engine --- components/engine/commands.go | 2 +- components/engine/commands_test.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 3ce8c8eb98..dda7f13d46 100644 --- a/components/engine/commands.go +++ b/components/engine/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/components/engine/commands_test.go b/components/engine/commands_test.go index 87c4c02a52..483c5e70c9 100644 --- a/components/engine/commands_test.go +++ b/components/engine/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 3ca4c119d1a90534943b4327519d19a3c94aeb27 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 Upstream-commit: f3d29695608d9ea9a3f92bcf872c62e158106919 Component: engine --- components/engine/buildfile.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 570a4eb72c..df413a61fc 100644 --- a/components/engine/buildfile.go +++ b/components/engine/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 1a5cae3fdb0657a9bc95e66e211bed899282800b 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 Upstream-commit: 1d1d81b0bc52c6aff652f5515fd792f76e40f7c2 Component: engine --- components/engine/buildfile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index df413a61fc..303baac318 100644 --- a/components/engine/buildfile.go +++ b/components/engine/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 32424f76bf18ed2761083ea40973064022e42872 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 Upstream-commit: e43ef364cb99585d3285f51f7ab308f8a77fe09e Component: engine --- components/engine/api_test.go | 70 ----------------------------- components/engine/buildfile_test.go | 2 +- components/engine/runtime_test.go | 22 +++++---- 3 files changed, 14 insertions(+), 80 deletions(-) diff --git a/components/engine/api_test.go b/components/engine/api_test.go index 6eb2584b01..d111f258c3 100644 --- a/components/engine/api_test.go +++ b/components/engine/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/components/engine/buildfile_test.go b/components/engine/buildfile_test.go index b7cc7be8ec..8913284e8f 100644 --- a/components/engine/buildfile_test.go +++ b/components/engine/buildfile_test.go @@ -84,7 +84,7 @@ run [ "$FOO" = "BAR" ] { ` -from docker-ut +from %s ENTRYPOINT /bin/echo CMD Hello world `, diff --git a/components/engine/runtime_test.go b/components/engine/runtime_test.go index d003426f25..07616ebce0 100644 --- a/components/engine/runtime_test.go +++ b/components/engine/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 13025daedd786eec8021015a39ca9870fba71dc0 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 Upstream-commit: 2b5553144a9249bbfed9be2a181b051a66350cb1 Component: engine --- components/engine/buildfile.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 303baac318..75e31dba70 100644 --- a/components/engine/buildfile.go +++ b/components/engine/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 f371bd9fe85e28d28b18fb50bd88e4afff4bee15 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 Upstream-commit: f64dbdbe3a147f58d04b6c39c6469fdd97427098 Component: engine --- components/engine/buildfile.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 570a4eb72c..75e31dba70 100644 --- a/components/engine/buildfile.go +++ b/components/engine/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 f46f2cd5f6f80e397ee1a551a158cde45327cb89 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 Upstream-commit: 9f1fc40a64fd6863dec5298099041493fee87db5 Component: engine --- components/engine/Dockerfile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 components/engine/Dockerfile diff --git a/components/engine/Dockerfile b/components/engine/Dockerfile new file mode 100644 index 0000000000..46f9b585c8 --- /dev/null +++ b/components/engine/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 80e25aa27463c5e6525e77722c72108b8fa9c012 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 Upstream-commit: 05d7f85af9e5813ddb1c066e44c802dc33790547 Component: engine --- components/engine/commands.go | 2 +- components/engine/graph.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 0bd7965f7f..0add994f68 100644 --- a/components/engine/commands.go +++ b/components/engine/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/components/engine/graph.go b/components/engine/graph.go index 1417aade0d..42d1bdbd4c 100644 --- a/components/engine/graph.go +++ b/components/engine/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 3cfd5fdb16c3c1ac9e5b6b7a2c6b9563c9ab3cf3 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 Upstream-commit: 91520838fc72f4004d65844b8e57df85473808a1 Component: engine --- components/engine/state.go | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/state.go b/components/engine/state.go index 117659bf5b..6480b9b428 100644 --- a/components/engine/state.go +++ b/components/engine/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()