Merge branch 'v1.4' into master

This commit is contained in:
Fernandez Ludovic 2017-11-28 14:03:55 +01:00
commit 3d452fd5b9
4 changed files with 79 additions and 4 deletions

View file

@ -1,9 +1,15 @@
## Previous documentation ## Current versions documentation
- [Latest stable](https://docs.traefik.io) - [Latest stable](https://docs.traefik.io)
- [Experimental](https://master--traefik-docs.netlify.com/) - [Experimental](https://master--traefik-docs.netlify.com/)
## Future version documentation
- [v1.5 RC](http://v1-5.archive.docs.traefik.io/)
## Previous versions documentation
- [v1.4 aka Roquefort](http://v1-4.archive.docs.traefik.io/) - [v1.4 aka Roquefort](http://v1-4.archive.docs.traefik.io/)
- [v1.3 aka Raclette](http://v1-3.archive.docs.traefik.io/) - [v1.3 aka Raclette](http://v1-3.archive.docs.traefik.io/)
@ -14,4 +20,4 @@
## More ## More
[Change log](https://github.com/containous/traefik/blob/master/CHANGELOG.md) [Change log](https://github.com/containous/traefik/blob/master/CHANGELOG.md)

View file

@ -49,6 +49,14 @@ func (s *DockerSuite) startContainerWithLabels(c *check.C, image string, labels
}) })
} }
func (s *DockerSuite) startContainerWithNameAndLabels(c *check.C, name string, image string, labels map[string]string, args ...string) string {
return s.startContainerWithConfig(c, image, d.ContainerConfig{
Name: name,
Cmd: args,
Labels: labels,
})
}
func (s *DockerSuite) startContainerWithConfig(c *check.C, image string, config d.ContainerConfig) string { func (s *DockerSuite) startContainerWithConfig(c *check.C, image string, config d.ContainerConfig) string {
if config.Name == "" { if config.Name == "" {
config.Name = namesgenerator.GetRandomName(10) config.Name = namesgenerator.GetRandomName(10)
@ -60,6 +68,11 @@ func (s *DockerSuite) startContainerWithConfig(c *check.C, image string, config
return strings.SplitAfter(container.Name, "/")[1] return strings.SplitAfter(container.Name, "/")[1]
} }
func (s *DockerSuite) stopAndRemoveContainerByName(c *check.C, name string) {
s.project.Stop(c, name)
s.project.Remove(c, name)
}
func (s *DockerSuite) SetUpSuite(c *check.C) { func (s *DockerSuite) SetUpSuite(c *check.C) {
project := docker.NewProjectFromEnv(c) project := docker.NewProjectFromEnv(c)
s.project = project s.project = project
@ -229,3 +242,53 @@ func (s *DockerSuite) TestDockerContainersWithServiceLabels(c *check.C) {
c.Assert(json.Unmarshal(body, &version), checker.IsNil) c.Assert(json.Unmarshal(body, &version), checker.IsNil)
c.Assert(version["Version"], checker.Equals, "swarm/1.0.0") c.Assert(version["Version"], checker.Equals, "swarm/1.0.0")
} }
func (s *DockerSuite) TestRestartDockerContainers(c *check.C) {
file := s.adaptFileForHost(c, "fixtures/docker/simple.toml")
defer os.Remove(file)
// Start a container with some labels
labels := map[string]string{
types.LabelPrefix + "frontend.rule": "Host:my.super.host",
types.LabelPort: "2375",
}
s.startContainerWithNameAndLabels(c, "powpow", "swarm:1.0.0", labels, "manage", "token://blabla")
// Start traefik
cmd, display := s.traefikCmd(withConfigFile(file))
defer display(c)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/version", nil)
c.Assert(err, checker.IsNil)
req.Host = "my.super.host"
// FIXME Need to wait than 500 milliseconds more (for swarm or traefik to boot up ?)
resp, err := try.ResponseUntilStatusCode(req, 1500*time.Millisecond, http.StatusOK)
c.Assert(err, checker.IsNil)
body, err := ioutil.ReadAll(resp.Body)
c.Assert(err, checker.IsNil)
var version map[string]interface{}
c.Assert(json.Unmarshal(body, &version), checker.IsNil)
c.Assert(version["Version"], checker.Equals, "swarm/1.0.0")
err = try.GetRequest("http://127.0.0.1:8080/api/providers/docker/backends", 60*time.Second, try.BodyContains("powpow"))
c.Assert(err, checker.IsNil)
s.stopAndRemoveContainerByName(c, "powpow")
defer s.project.Remove(c, "powpow")
time.Sleep(5 * time.Second)
err = try.GetRequest("http://127.0.0.1:8080/api/providers/docker/backends", 10*time.Second, try.BodyContains("powpow"))
c.Assert(err, checker.NotNil)
s.startContainerWithNameAndLabels(c, "powpow", "swarm:1.0.0", labels, "manage", "token://blabla")
err = try.GetRequest("http://127.0.0.1:8080/api/providers/docker/backends", 60*time.Second, try.BodyContains("powpow"))
c.Assert(err, checker.IsNil)
}

View file

@ -6,6 +6,8 @@ logLevel = "DEBUG"
[entryPoints.http] [entryPoints.http]
address = ":8000" address = ":8000"
[web]
[docker] [docker]
# It's dynamagic ! # It's dynamagic !

View file

@ -673,8 +673,12 @@ func listContainers(ctx context.Context, dockerClient client.ContainerAPIClient)
if err != nil { if err != nil {
log.Warnf("Failed to inspect container %s, error: %s", container.ID, err) log.Warnf("Failed to inspect container %s, error: %s", container.ID, err)
} else { } else {
dockerData := parseContainer(containerInspected) // This condition is here to avoid to have empty IP https://github.com/containous/traefik/issues/2459
containersInspected = append(containersInspected, dockerData) // We register only container which are running
if containerInspected.ContainerJSONBase != nil && containerInspected.ContainerJSONBase.State != nil && containerInspected.ContainerJSONBase.State.Running {
dockerData := parseContainer(containerInspected)
containersInspected = append(containersInspected, dockerData)
}
} }
} }
return containersInspected, nil return containersInspected, nil