tiredofit / docker-traefik-cloudflare-companion

Automatically Create CNAME records for containers served by Traefik
MIT License
384 stars 64 forks source link

External Service Support #59

Closed kadaan closed 2 years ago

kadaan commented 2 years ago

This is a first stab at adding support for external services. This is done by adding an optional Traefik poll loop which looks for HTTP routers that are not using the Socker provider. If they have a Host rule, it will be extracted and similar logic to check_container_t2 will be performed.

Discovery of routes and update of cloudflare now happen in two different phases. First we discover all routes. Then we take this route list and compare to the list of already synced routes, anything new is pushed to cloudflare. If the route is pushed to cloudflare successfully, we record that route in our synced routes. Docker routes are given priority.

For the initial load we load all docker routes and non-docker routes. We start a recurrent task that will inspect Traefik for new routes. We also start the docker event stream monitor.

To enable polling of Traefik for routes you need to:

  1. Include the TRAEFIK_MODE=TRUE environment variable
  2. Include the TRAEFIK_URL=http://xxx.xxx.xxx.xxx:8080 environment variable

Optionally:

NOTE: The exclude filters override the include filters.


The DRY_RUN environment variable has been added. When set to TRUE it will run through all the normal logic, but not actually perform the cloudflare updates.

The scheduling service on the container has also been disabled, it was not needed.

kadaan commented 2 years ago

@tiredofit Feedback?

tiredofit commented 2 years ago

Very nice stuff, I'm always in awe at others programming skills vs my "hacks". My only suggestion here is to be a bit more explicit with the environment variables TRAEFIK_MODE and TRAEFIK_URL. Suggest that they stay as close as possible to the method of what is being done here ie ENABLE_TRAEFIK_POLL=TRUE and TRAEFIK_POLL_URL and then we'll just need to be clear in the README on its usage and that its for specific purposes. How does that sound?

kadaan commented 2 years ago

@tiredofit Added documentation and did the renames suggested. Also gated the traefik polling on TRAEFIK_VERSION=2

kadaan commented 2 years ago

@tiredofit One change to think about is that before we would always add/update CloudFlare, but now we only do it if the host is not in our bookkeeping. This means that if you delete the CNAME in CloudFlare we will not add it back unless cloudflare-companion is restart. This was possible before because you listed to events to know what to do. Now, with polling, we don't have the luxury of only getting a stream of change and we don't want to update CloudFlare every 60s.

tiredofit commented 2 years ago

Many thanks for this contribution.

tiredofit commented 2 years ago

Tagged and released as 6.8.0