From d49db6afaf126b96d7590ced45c16c14a32e57fd Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 17 Feb 2016 15:45:45 -0800 Subject: [PATCH 1/4] add test Signed-off-by: Victor Vieux --- test/integration/compose/up.bats | 16 ++++++++++++++++ test/integration/testdata/compose/simple.yml | 2 ++ 2 files changed, 18 insertions(+) diff --git a/test/integration/compose/up.bats b/test/integration/compose/up.bats index 8b49bd35a3..3e1ffac757 100644 --- a/test/integration/compose/up.bats +++ b/test/integration/compose/up.bats @@ -32,3 +32,19 @@ function teardown() { # check memory-swappiness [[ "${output}" == *"\"MemorySwappiness\": -1"* ]] } + +@test "docker-compose up - check port" { + start_docker_with_busybox 2 + swarm_manage + FILE=$TESTDATA/compose/simple.yml + + docker-compose_swarm -f $FILE up -d + + run docker_swarm ps -q + [ "${#lines[@]}" -eq 2 ] + + run docker_swarm ps + # check memory-swappiness +echo $output + [[ "${output}" == *"->80/tcp"* ]] +} diff --git a/test/integration/testdata/compose/simple.yml b/test/integration/testdata/compose/simple.yml index 681ee398c1..8a0954bcfa 100644 --- a/test/integration/testdata/compose/simple.yml +++ b/test/integration/testdata/compose/simple.yml @@ -1,5 +1,7 @@ service1: image: busybox + ports: + - "80" command: sleep 100 service2: From c42142e40883774b34d8407224983ca807af6769 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 17 Feb 2016 15:45:49 -0800 Subject: [PATCH 2/4] Revert "Passing HostConfig for /start endpoint" This reverts commit 6ff0d29c9d10afbe0fd2ebab7f954c4c74e261e4. Signed-off-by: Victor Vieux --- api/handlers.go | 22 +--------------------- cluster/cluster.go | 2 +- cluster/engine.go | 4 ++-- cluster/mesos/cluster.go | 4 ++-- cluster/swarm/cluster.go | 4 ++-- cluster/watchdog.go | 2 +- 6 files changed, 9 insertions(+), 29 deletions(-) diff --git a/api/handlers.go b/api/handlers.go index 4591a5ceaa..09a9c0bd41 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -740,26 +740,6 @@ func getEvents(c *context, w http.ResponseWriter, r *http.Request) { // POST /containers/{name:.*}/start func postContainersStart(c *context, w http.ResponseWriter, r *http.Request) { - hostConfig := &dockerclient.HostConfig{ - MemorySwappiness: -1, - } - - buf, err := ioutil.ReadAll(r.Body) - if err != nil { - httpError(w, err.Error(), http.StatusBadRequest) - return - } - r.Body.Close() - - if len(buf) == 0 { - hostConfig = nil - } else { - if err := json.Unmarshal(buf, hostConfig); err != nil { - httpError(w, err.Error(), http.StatusBadRequest) - return - } - } - name := mux.Vars(r)["name"] container := c.cluster.Container(name) if container == nil { @@ -767,7 +747,7 @@ func postContainersStart(c *context, w http.ResponseWriter, r *http.Request) { return } - if err := c.cluster.StartContainer(container, hostConfig); err != nil { + if err := c.cluster.StartContainer(container); err != nil { httpError(w, err.Error(), http.StatusInternalServerError) return } diff --git a/cluster/cluster.go b/cluster/cluster.go index 21a36bc7d6..041ee7fca2 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -27,7 +27,7 @@ type Cluster interface { Containers() Containers // Start a container - StartContainer(container *Container, hostConfig *dockerclient.HostConfig) error + StartContainer(container *Container) error // Return container the matching `IDOrName` // TODO: remove this method from the interface as we can use diff --git a/cluster/engine.go b/cluster/engine.go index ea538b70bb..213594bfc2 100644 --- a/cluster/engine.go +++ b/cluster/engine.go @@ -1038,8 +1038,8 @@ func (e *Engine) cleanupContainers() { } // StartContainer starts a container -func (e *Engine) StartContainer(id string, hostConfig *dockerclient.HostConfig) error { - err := e.client.StartContainer(id, hostConfig) +func (e *Engine) StartContainer(id string) error { + err := e.client.StartContainer(id, nil) e.CheckConnectionErr(err) if err != nil { return err diff --git a/cluster/mesos/cluster.go b/cluster/mesos/cluster.go index 80822486ea..4905844fc0 100644 --- a/cluster/mesos/cluster.go +++ b/cluster/mesos/cluster.go @@ -179,10 +179,10 @@ func (c *Cluster) UnregisterEventHandler(h cluster.EventHandler) { } // StartContainer starts a container -func (c *Cluster) StartContainer(container *cluster.Container, hostConfig *dockerclient.HostConfig) error { +func (c *Cluster) StartContainer(container *cluster.Container) error { // if the container was started less than a second ago in detach mode, do not start it if time.Now().Unix()-container.Created > 1 || container.Config.Labels[cluster.SwarmLabelNamespace+".mesos.detach"] != "true" { - return container.Engine.StartContainer(container.Id, hostConfig) + return container.Engine.StartContainer(container.Id) } return nil } diff --git a/cluster/swarm/cluster.go b/cluster/swarm/cluster.go index 62a542dfaf..9d7e847cc3 100644 --- a/cluster/swarm/cluster.go +++ b/cluster/swarm/cluster.go @@ -125,8 +125,8 @@ func (c *Cluster) generateUniqueID() string { } // StartContainer starts a container -func (c *Cluster) StartContainer(container *cluster.Container, hostConfig *dockerclient.HostConfig) error { - return container.Engine.StartContainer(container.Id, hostConfig) +func (c *Cluster) StartContainer(container *cluster.Container) error { + return container.Engine.StartContainer(container.Id) } // CreateContainer aka schedule a brand new container into the cluster. diff --git a/cluster/watchdog.go b/cluster/watchdog.go index 3ef52d7811..25efd7b3df 100644 --- a/cluster/watchdog.go +++ b/cluster/watchdog.go @@ -83,7 +83,7 @@ func (w *Watchdog) rescheduleContainers(e *Engine) { log.Infof("Rescheduled container %s from %s to %s as %s", c.Id, c.Engine.Name, newContainer.Engine.Name, newContainer.Id) if c.Info.State.Running { log.Infof("Container %s was running, starting container %s", c.Id, newContainer.Id) - if err := w.cluster.StartContainer(newContainer, nil); err != nil { + if err := w.cluster.StartContainer(newContainer); err != nil { log.Errorf("Failed to start rescheduled container %s", newContainer.Id) } } From f3a1d58fe3e9a2efd0d5f4505d3ba5645393eb4a Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 17 Feb 2016 15:46:51 -0800 Subject: [PATCH 3/4] Revert "Testcase start container with hostconfig" This reverts commit 3dff7aa96a2ede92631828a54aae0f26a71f9efc. Signed-off-by: Victor Vieux --- test/integration/api/start.bats | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/test/integration/api/start.bats b/test/integration/api/start.bats index e432190b86..4f46ad2737 100644 --- a/test/integration/api/start.bats +++ b/test/integration/api/start.bats @@ -25,26 +25,3 @@ function teardown() { # Verify [ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ] } - -@test "docker start with hostConfig" { - start_docker_with_busybox 2 - swarm_manage - # create - docker_swarm create --name test_container busybox sleep 1000 - - # make sure created container exists - # new created container has no status - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - - # start - curl -s -H "Content-Type: application/json" -X POST -d '{"PublishAllPorts": true}' ${SWARM_HOSTS[0]}/v1.23/containers/test_container/start - - # Verify - [ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ] - - # Inspect HostConfig of container, should have PublishAllPorts set to true - run docker_swarm inspect test_container - [[ "${output}" == *'"PublishAllPorts": true'* ]] -} From 358ac5729ad6421d43519752432e01290ee7450a Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 17 Feb 2016 16:09:35 -0800 Subject: [PATCH 4/4] remove debug Signed-off-by: Victor Vieux --- test/integration/compose/up.bats | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/compose/up.bats b/test/integration/compose/up.bats index 3e1ffac757..c45389252a 100644 --- a/test/integration/compose/up.bats +++ b/test/integration/compose/up.bats @@ -45,6 +45,5 @@ function teardown() { run docker_swarm ps # check memory-swappiness -echo $output [[ "${output}" == *"->80/tcp"* ]] }