jittering / traefik-kop

A dynamic docker->redis->traefik discovery agent
MIT License
179 stars 13 forks source link

Default Rule #18

Closed Svenum closed 1 year ago

Svenum commented 1 year ago

Is it possible to add a defaultRule? Like the docker provider:

defaultRule: "Host(`srv-{{ index .Labels \"com.docker.compose.service\"}}.example.com`)"

Would be very helpfull.

chetan commented 1 year ago

@Svenum I don't understand what you mean here. Where would this rule be added and what are you trying to achieve? I guess you are looking for the equivalent of the traefik provider-level config referenced here?

Svenum commented 1 year ago

Yes, I am looking for something like the defaultRule from the Docker provider in Traefik. image I want, that I don't have to add to every container the label with the rule. traefik.http.routers.ngnix.rule

chetan commented 1 year ago

Hi @Svenum,

I pushed a new pre-release build which solves this as well as #17. You can try it out via this tag: ghcr.io/jittering/traefik-kop:0.12.2-next-amd64. You can see the arm tags on the packages page if you need those instead.

See the new docker-config and label options in the branch readme file.

Please report back and let me know if it works for you so I can go ahead and cut a new release.

Svenum commented 1 year ago

This is working with one Docker (onlyoffice is going through everytime even if more then one bind_ips are used), but with two i get this error:

time="2022-10-11T16:05:49Z" level=info msg="creating new redis store at 172.16.0.12:6379 for hostname 353ace10ab1d"
time="2022-10-11T16:05:49Z" level=info msg="Starting provider aggregator *traefikkop.MultiProvider"
time="2022-10-11T16:05:49Z" level=info msg="starting polling provider with 1m0s interval"
time="2022-10-11T16:05:49Z" level=info msg="Starting provider *docker.Provider"
time="2022-10-11T16:05:49Z" level=info msg="refreshing traefik-kop configuration"
time="2022-10-11T16:05:49Z" level=info msg="publishing http://172.16.0.16:80" service-type=http service=onlyoffice@docker
time="2022-10-11T16:05:49Z" level=info msg="publishing https://172.16.0.14:443" service=nextcloud@docker service-type=http
time="2022-10-11T16:05:49Z" level=info msg="refreshing traefik-kop configuration"
time="2022-10-11T16:05:49Z" level=info msg="publishing https://172.16.0.14:443" service=nextcloud@docker service-type=http
time="2022-10-11T16:05:49Z" level=info msg="publishing http://172.16.0.16:80" service-type=http service=onlyoffice@docker
time="2022-10-11T16:06:49Z" level=error msg="Error in Go routine: runtime error: invalid memory address or nil pointer dereference"
time="2022-10-11T16:06:49Z" level=error msg="Stack: goroutine 40 [running]:\nruntime/debug.Stack()\n\t/usr/local/Cellar/go/1.19.2/libexec/src/runtime/debug/stack.go:24 +0x65\ngithub.com/traefik/traefik/v2/pkg/safe.defaultRecoverGoroutine({0x247e9c0?, 0x41cfa80})\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/safe/routine.go:66 +0xa5\ngithub.com/traefik/traefik/v2/pkg/safe.OperationWithRecover.func1.1()\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/safe/routine.go:74 +0x35\npanic({0x247e9c0, 0x41cfa80})\n\t/usr/local/Cellar/go/1.19.2/libexec/src/runtime/panic.go:884 +0x212\ntext/template.errRecover(0xc001207230)\n\t/usr/local/Cellar/go/1.19.2/libexec/src/text/template/exec.go:164 +0x165\npanic({0x247e9c0, 0x41cfa80})\n\t/usr/local/Cellar/go/1.19.2/libexec/src/runtime/panic.go:884 +0x212\ntext/template.(*Template).execute(0x0, {0x2e19780?, 0xc00115f710?}, {0x2540800?, 0xc00120b3b0?})\n\t/usr/local/Cellar/go/1.19.2/libexec/src/text/template/exec.go:215 +0x22c\ntext/template.(*Template).Execute(...)\n\t/usr/local/Cellar/go/1.19.2/libexec/src/text/template/exec.go:201\ngithub.com/traefik/traefik/v2/pkg/provider.BuildRouterConfiguration({0x2e3cda0, 0xc00115e090}, 0xc00115f500, {0xc001153c30?, 0xc001152e40?}, 0x10?, {0x2540800, 0xc00120b3b0})\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/provider/configuration.go:404 +0x2d1\ngithub.com/traefik/traefik/v2/pkg/provider/docker.(*Provider).buildConfiguration(0xc000392000, {0x2e3cda0, 0xc00115e090}, {0xc001019680, 0x8, 0xc000fe6f00?})\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/provider/docker/config.go:83 +0x765\ngithub.com/traefik/traefik/v2/pkg/provider/docker.(*Provider).Provide.func1.1()\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/provider/docker/docker.go:231 +0x6fc\ngithub.com/traefik/traefik/v2/pkg/safe.OperationWithRecover.func1()\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/safe/routine.go:78 +0x63\ngithub.com/cenkalti/backoff/v4.RetryNotifyWithTimer(0xc00115a370, {0x14b4260e5990, 0xc0005a0b40}, 0xc001207f20, {0x0?, 0x0?})\n\t/Users/chetan/.go/pkg/mod/github.com/cenkalti/backoff/v4@v4.1.1/retry.go:55 +0x12a\ngithub.com/cenkalti/backoff/v4.RetryNotify(...)\n\t/Users/chetan/.go/pkg/mod/github.com/cenkalti/backoff/v4@v4.1.1/retry.go:34\ngithub.com/traefik/traefik/v2/pkg/provider/docker.(*Provider).Provide.func1({0x2e3ccf8?, 0xc00029a580?})\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/provider/docker/docker.go:331 +0x2fb\ngithub.com/traefik/traefik/v2/pkg/safe.(*Pool).GoCtx.func1()\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/safe/routine.go:36 +0x66\ngithub.com/traefik/traefik/v2/pkg/safe.GoWithRecover.func1()\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/safe/routine.go:59 +0x5b\ncreated by github.com/traefik/traefik/v2/pkg/safe.GoWithRecover\n\t/Users/chetan/.go/pkg/mod/github.com/traefik/traefik/v2@v2.8.4/pkg/safe/routine.go:53 +0x72\n"
time="2022-10-11T16:06:49Z" level=error msg="Provider connection error panic in operation: %!w(<nil>), retrying in 628.273767ms" providerName=docker

This is my compose file:

networks:
    br0:
        external: true
    proxy_default:
        external: true

services:
    nextcloud:
        ports:
            - "443:443"
        networks:
            br0:
                ipv4_address: 172.16.0.14
            proxy_default:
        volumes:
            - /mnt/user/Nextcloud:/data
            - /mnt/user/appdata/nextcloud:/config
        environment:
            NEXTCLOUD_UPLOAD_LIMIT: "10G"
            PUID: 99
            GUID: 100
            UMASK: 022
        image: "lscr.io/linuxserver/nextcloud:latest"
        labels:
            traefik.enable: true
            traefik.http.routers.nextcloud.entryPoints: https
            traefik.http.services.nextcloud.loadbalancer.server.scheme: https
            traefik.http.services.nextcloud.loadbalancer.server.port: 443
            kop.nextcloud.bind.ip: 172.16.0.14

    postgresql:
        volumes:
            - /mnt/cache/appdata/postgresql13:/var/lib/postgresql/data
        environment:
            POSTGRES_PASSWORD: "asdfsdf"
            POSTGRES_USER: nextcloud
            POSTGRES_DB: nextcloud
        networks:
            proxy_default:
        image: "registry.hub.docker.com/library/postgres:13"

    onlyoffice:
        volumes:
            - /mnt/user/appdata/onlyofficeds/logs:/var/log/onlyoffice
            - /mnt/user/appdata/onlyofficeds/Data:/var/www/onlyoffice/Data
            - /mnt/user/appdata/onlyofficeds/lib:/var/lib/onlyoffice
            - /mnt/user/appdata/onlyofficeds/database:/var/lib/postgresql
            - /mnt/user/appdata/onlyofficeds/fonts:/usr/share/fonts/
        ports:
            - "443:443"
            - "80:80"
            - "5222:5222"
        networks:
            br0:
                ipv4_address: 172.16.0.16
            proxy_default:
        image: "onlyoffice/documentserver"
        labels:
            traefik.enable: true
            traefik.http.routers.onlyoffice.entryPoints: https
            traefik.http.services.onlyoffice.loadbalancer.server.scheme: http
            traefik.http.services.onlyoffice.loadbalancer.server.port: 80
            kop.onlyoffice.bind.ip: 172.16.0.16

And my traefik-kop compose file:

services:
  traefik-kop:
    image: "ghcr.io/jittering/traefik-kop:0.12.2-next-amd64"
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      REDIS_ADDR: 172.16.0.12:6379
      BIND_IP: 172.16.0.11
      DOCKER_CONFIG: |
        ---
        docker:
          defaultRule: Host(`srv-{{.Name}}.intra.holypenguin.net`)
Svenum commented 1 year ago

If I restart traefik and redis everythin is working right! But the error from kop is still there. Thanks for that fast implementation!

chetan commented 1 year ago

@Svenum thanks for providing a test case. I'll give it a go when I've got some time and see if I can reproduce.

That said, it looks the error is something to do with the default rule config. Can you try running kop with DEBUG: "1" env var and check the output on startup? I can also add a dump of the docker provider config as an extra bit for debugging.

edit: actually, traefik already prints the provider config on startup. Can you verify that the default rule shown there is what you expect?

chetan commented 1 year ago

You can also try the very latest build here, just to ensure you got the write image: ghcr.io/jittering/traefik-kop:0.12.2-next-22aaa3b-amd64

Svenum commented 1 year ago

The Default rule and the bind_ip Label Work fine but i geht this Error anyway. I'll try the latest build tomorrow.

chetan commented 1 year ago

@Svenum figured out the issue and made a fix. Releasing v0.13 shortly.