1
0
Fork 0

Adds default rule system on Docker provider.

Co-authored-by: Julien Salleyron <julien@containo.us>
This commit is contained in:
Ludovic Fernandez 2019-01-21 19:06:02 +01:00 committed by Traefiker Bot
parent b54c956c5e
commit 04958c6951
20 changed files with 506 additions and 168 deletions

View file

@ -40,7 +40,14 @@ func (s *DockerComposeSuite) TestComposeScale(c *check.C) {
s.composeProject.Scale(c, composeService, serviceCount)
file := s.adaptFileForHost(c, "fixtures/docker/minimal.toml")
tempObjects := struct {
DockerHost string
DefaultRule string
}{
DockerHost: s.getDockerHost(),
DefaultRule: "Host:{{ normalize .Name }}.docker.localhost",
}
file := s.adaptFile(c, "fixtures/docker/minimal.toml", tempObjects)
defer os.Remove(file)
cmd, display := s.traefikCmd(withConfigFile(file))

View file

@ -79,11 +79,19 @@ func (s *DockerSuite) SetUpSuite(c *check.C) {
}
func (s *DockerSuite) TearDownTest(c *check.C) {
s.project.Clean(c, os.Getenv("CIRCLECI") != "")
s.project.Clean(c, os.Getenv("CIRCLECI") != "") // FIXME
}
func (s *DockerSuite) TestSimpleConfiguration(c *check.C) {
file := s.adaptFileForHost(c, "fixtures/docker/simple.toml")
tempObjects := struct {
DockerHost string
DefaultRule string
}{
DockerHost: s.getDockerHost(),
DefaultRule: "Host:{{ normalize .Name }}.docker.localhost",
}
file := s.adaptFile(c, "fixtures/docker/simple.toml", tempObjects)
defer os.Remove(file)
cmd, display := s.traefikCmd(withConfigFile(file))
@ -99,7 +107,15 @@ func (s *DockerSuite) TestSimpleConfiguration(c *check.C) {
}
func (s *DockerSuite) TestDefaultDockerContainers(c *check.C) {
file := s.adaptFileForHost(c, "fixtures/docker/simple.toml")
tempObjects := struct {
DockerHost string
DefaultRule string
}{
DockerHost: s.getDockerHost(),
DefaultRule: "Host:{{ normalize .Name }}.docker.localhost",
}
file := s.adaptFile(c, "fixtures/docker/simple.toml", tempObjects)
defer os.Remove(file)
name := s.startContainer(c, "swarm:1.0.0", "manage", "token://blablabla")
@ -129,7 +145,15 @@ func (s *DockerSuite) TestDefaultDockerContainers(c *check.C) {
}
func (s *DockerSuite) TestDockerContainersWithLabels(c *check.C) {
file := s.adaptFileForHost(c, "fixtures/docker/simple.toml")
tempObjects := struct {
DockerHost string
DefaultRule string
}{
DockerHost: s.getDockerHost(),
DefaultRule: "Host:{{ normalize .Name }}.docker.localhost",
}
file := s.adaptFile(c, "fixtures/docker/simple.toml", tempObjects)
defer os.Remove(file)
// Start a container with some labels
@ -177,7 +201,15 @@ func (s *DockerSuite) TestDockerContainersWithLabels(c *check.C) {
}
func (s *DockerSuite) TestDockerContainersWithOneMissingLabels(c *check.C) {
file := s.adaptFileForHost(c, "fixtures/docker/simple.toml")
tempObjects := struct {
DockerHost string
DefaultRule string
}{
DockerHost: s.getDockerHost(),
DefaultRule: "Host:{{ normalize .Name }}.docker.localhost",
}
file := s.adaptFile(c, "fixtures/docker/simple.toml", tempObjects)
defer os.Remove(file)
// Start a container with some labels
@ -199,13 +231,21 @@ func (s *DockerSuite) TestDockerContainersWithOneMissingLabels(c *check.C) {
// FIXME Need to wait than 500 milliseconds more (for swarm or traefik to boot up ?)
// TODO validate : run on 80
// Expected a 404 as we did not comfigure anything
// Expected a 404 as we did not configure anything
err = try.Request(req, 1500*time.Millisecond, try.StatusCodeIs(http.StatusNotFound))
c.Assert(err, checker.IsNil)
}
func (s *DockerSuite) TestRestartDockerContainers(c *check.C) {
file := s.adaptFileForHost(c, "fixtures/docker/simple.toml")
tempObjects := struct {
DockerHost string
DefaultRule string
}{
DockerHost: s.getDockerHost(),
DefaultRule: "Host:{{ normalize .Name }}.docker.localhost",
}
file := s.adaptFile(c, "fixtures/docker/simple.toml", tempObjects)
defer os.Remove(file)
// Start a container with some labels

View file

@ -26,7 +26,6 @@ func (s *ErrorPagesSuite) SetUpSuite(c *check.C) {
}
func (s *ErrorPagesSuite) TestSimpleConfiguration(c *check.C) {
file := s.adaptFile(c, "fixtures/error_pages/simple.toml", struct {
Server1 string
Server2 string

View file

@ -25,5 +25,5 @@ checkNewVersion = false
[providers]
[providers.docker]
exposedByDefault = false
domain = "docker.local"
defaultRule = "{{ normalize .Name }}.docker.local"
watch = true

View file

@ -10,6 +10,6 @@ logLevel = "DEBUG"
[providers]
[providers.docker]
endpoint = "{{.DockerHost}}"
domain = "docker.localhost"
endpoint = "{{ .DockerHost }}"
defaultRule = "{{ .DefaultRule }}"
exposedByDefault = false

View file

@ -9,6 +9,6 @@ logLevel = "DEBUG"
[providers]
[providers.docker]
endpoint = "{{.DockerHost}}"
domain = "docker.localhost"
endpoint = "{{ .DockerHost }}"
defaultRule = "{{ .DefaultRule }}"
exposedByDefault = true

View file

@ -10,11 +10,9 @@ logLevel = "DEBUG"
[routers]
[routers.router1]
middlewares = ["error"]
service = "service1"
[routers.router1.routes.test_1]
rule = "Host:test.local"
rule = "Host:test.local"
service = "service1"
middlewares = ["error"]
[middlewares]
[middlewares.error.errors]

View file

@ -10,11 +10,9 @@ logLevel = "DEBUG"
[routers]
[routers.router1]
middlewares = ["error"]
service = "service1"
[routers.router1.routes.test_1]
rule = "Host:test.local"
service = "service1"
middlewares = ["error"]
[middlewares]
[middlewares.error.errors]

View file

@ -10,7 +10,7 @@ logLevel = "DEBUG"
[providers]
[providers.docker]
exposedByDefault = false
domain = "docker.local"
defaultRule = "{{ normalize .Name }}.docker.local"
watch = true
[hostResolver]

View file

@ -21,5 +21,5 @@ checkNewVersion = false
[providers]
[providers.docker]
exposedByDefault = false
domain = "docker.local"
defaultRule = "{{ normalize .Name }}.docker.local"
watch = true

View file

@ -142,14 +142,13 @@ func (s *BaseSuite) displayTraefikLog(c *check.C, output *bytes.Buffer) {
}
}
func (s *BaseSuite) adaptFileForHost(c *check.C, path string) string {
func (s *BaseSuite) getDockerHost() string {
dockerHost := os.Getenv("DOCKER_HOST")
if dockerHost == "" {
// Default docker socket
dockerHost = "unix:///var/run/docker.sock"
}
tempObjects := struct{ DockerHost string }{dockerHost}
return s.adaptFile(c, path, tempObjects)
return dockerHost
}
func (s *BaseSuite) adaptFile(c *check.C, path string, tempObjects interface{}) string {