Code Monkey home page Code Monkey logo

traefik-avahi-helper's Introduction

traefik-avahi-helper

A helper container to expose proxied containers as mDNS CNAMEs that are being proxied by the offical Traefik docker container.

It reads the same container labels as the Traefik container e.g.

traefik.http.routers.r1.rule=Host(`r1.docker.local`)

This will create a CNAME entry of r1.docker.local

Installing

docker pull hardillb/traefik-avahi-helper

Currently there are AMD64 and ARM64 based builds.

Running

To work this needs the following 2 volumes mounting:

-v /var/run/docker.sock:/var/run/docker.sock

This allows the container to monitor docker

-v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket

And this allows the container to send d-bus commands to the host OS's Avahi daemon

$ docker run -d -v /var/run/docker.sock:/var/run/docker.sock -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket hardillb/traefik-avahi-helper 

AppArmor

If you are running on system with AppArmor installed you may get errors about not being able to send d-bus messages. To fix this add --privileged to the command line.

This is a temp workaround until I can work out a suitable policy to apply.

Acknowledgement

This uses and borrows heavily from mdns-publisher

traefik-avahi-helper's People

Contributors

cas-- avatar hardillb avatar indykoning avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

traefik-avahi-helper's Issues

Idea: hostnames discovery via traefik api

Thank you for the nice project! I use it just a couple of days but absolutely love it! ๐Ÿ‘

One idea: some of my traefik services are not inside the docker container, but just a proxy to some different services. So this might be helpful to actually look for hostnames in traefik and publish it via mdns.

Typo?

The README references docker run "--priviledged" but I believe it should be docker run "--privileged", or at least it is on Ubuntu

/tmp/docker.stock vs. /var/run/docker.stock in README

Where the volumes are listed it says /var/run/docker.sock:/tmp/docker.sock while in the command below /var/run/docker.sock:/var/run/docker.sock is used. I guess second is right because the other does not work, so it should be a quick fix to make everybody happy again.

Problem with multible Host rules

Thx for fixing the other bug so quickly, found an other one for you in my setup:

When there are multiple host rules in on label, it tries to add all the rules as one string as a domain which obvious does not work.

Here the error log:

> [email protected] start /usr/src/app
> node index.js

[
  'syncthing.myname.local',
  'traefik.myname.local`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard',
  'git.myname.local'
]
starting cname.py
Traceback (most recent call last):
  File "cname.py", line 93, in <module>
    main()
  File "cname.py", line 81, in main
    status = publisher.publish_cname(cname, True)
  File "/usr/local/lib/python3.8/site-packages/mpublisher/mpublisher.py", line 117, in publish_cname
    group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), cname.encode("ascii"),
  File "/usr/local/lib/python3.8/site-packages/dbus/proxies.py", line 72, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/local/lib/python3.8/site-packages/dbus/proxies.py", line 141, in __call__
    return self._connection.call_blocking(self._named_service,
  File "/usr/local/lib/python3.8/site-packages/dbus/connection.py", line 652, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.Avahi.NotSupportedError: Not supported

The used label:

- "traefik.http.routers.dashboard.rule=Host(`traefik.myname.local`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"

You could also imagine that people would use two domains in there rules and like both to be added. Or one .local and a public domain and then only the .local domain should be added. Maybe search for .local in the string given by r2 in index.js to identify the correct rule/domain(s).

Error when traefik label isn't in capital Letters

In my traefik labels which define the domain 'host' is not written in capital Letters, there for I get flowing error:

(node:18) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of null
    at /usr/src/app/index.js:21:49
    at Array.forEach (<anonymous>)
    at /usr/src/app/index.js:19:12
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:18) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:18) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

After have a look in the code, I think it is because of the regex in line 8 of index.js. It matches only to 'HOST' but not to 'Host'.

const re2 = /HOST\(\`(.*)\`\)/

Maybe it could be fixed with the modified version below but I haven't tested it nor have I experience with js:

const re2 = /(HOST|Host)\(\`(.*)\`\)/

Of course I can change all my labels but as the traefik documentary often uses 'Host' for example "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)" (https://doc.traefik.io/traefik/getting-started/quick-start/) I guess I am not the only one who doesn't use capital letters. I don't know which other ways (all small for example) are supported by traefik, maybe making the hole regex case-insensitive would be a solution to more cases.

service not creating CNAMEs at startup

I have a very simple stack, consisting solely of traefik and traefik-avahi-helper.

version: "3"
services:
  avahi:
    image: hardillb/traefik-avahi-helper
    container_name: avahi
    privileged: true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /run/dbus/system_bus_socket:/run/dbus/system_bus_socket

  traefik:
    image: traefik:latest
    container_name: traefik
    restart: unless-stopped
    command: --api.insecure=true --providers.docker
    ports:
      - 80:80
      - 443:443
    labels:
      - traefik.http.routers.traefik.rule=Host(`traefik.local`)
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

On docker-compose up -d, the avahi log always shows:

> [email protected] start
> node index.js
[]
starting cname.py
INFO: All CNAMEs published

and I can't resolve traefik.local, but if I make any change to the traefik service:

-      - 80:80
+      - 0.0.0.0:80:80

and docker-compose up -d, again, traefik.local is published!

Removing [ 'traefik.local' ]
restarting cname.py with /usr/src/app/cnames
starting cname.py
INFO: All CNAMEs published
Adding [ 'traefik.local' ]
restarting cname.py with /usr/src/app/cnames
starting cname.py
INFO: All CNAMEs published

It has nothing to do with the change from TCPv4+TCPv6 to TCPv4, as if I docker-compose down;docker-compose up -d without further changes, the CNAME will once again not be published.

I've tried making traefik depends_on traefik-avahi-helper, and vice versa.
I've tried stopping the traefik-avahi-helper container and restarting it. Nothing seems to make a difference.

What am I missing?

cnames are not promoted

I don't get any errors, the container is running fine. It also extract the correct domains from the labels but in the end, the cnames are not promoted by avahi to other machines neither the own. The container is running wthout problems.

log from container:

> [email protected] start /usr/src/app
> node index.js

[ 'syncthing.mymachine.local', 'traefik.mymachine.local', 'git.mymachine.local' ]
starting cname.py
INFO: All CNAMEs published

My docker-compose file:

version: "3.3"

services:

  traefik-avahi-helper:
    image: hardillb/traefik-avahi-helper
    container_name: "traefik-avahi-helper"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "/run/dbus/system_bus_socket:/run/dbus/system_bus_socket"
    restart: always

I am running avahi-daemon 0.7 on a raspberry pi 4 with rabian.
Are any other libraries required?

The same results on my laptop with ubuntu 20.04.1, avahi-daemon 0.7. Here the container runs with privileged keyword.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.