hmalphettes / docker-route53-dyndns

Automated DynDNS for Docker containers using docker-gen and Route53
11 stars 10 forks source link

Assumes hosted zone is xxx.yyy #5

Closed seertenedos closed 7 years ago

seertenedos commented 8 years ago

I have a hosted zone that is xxx.id.au and i assume there are many other 3rd level domains out there. Any chance you could modify this to compare the VIRTUAL_HOST to the list of hosted zones and find the match based on the VIRTUAL_HOST ending with the hosted zone?

If it is too hard i will buy another domain name because this container makes things so much easier. fantastic idea.

hmalphettes commented 8 years ago

@seertenedos that should be easy... especially if I dont write a test for it :)

Anyways we could try a custom template in a custom_cli53routes.tmpl file with those extra lines:

zone={{ $ "Env.ZONE" }}
[ -z "$zone" ] && zone=$ZONE
if [ -n "$zone" ]; then
  tenant=$(echo "${host%.$zone}")
else
  tenant=$(echo "${host%.*.*}")
  zone=$(echo "${host#$tenant.}")
fi

You would need to run your webapp with the extra ZONE env variable:

- e ZONE=xxx.id.au \
- e VIRTUAL_HOST=example.xxx.id.au \
your/webapp ...

or you could define the ZONE in which all your containers are hosted by running the dyns-router container with the ZONE

You can test the output of the template by mounting it in the container:

docker run -ti ... \
- v custom_cli53routes.tmpl:/app/cli53routes.tmpl \
hmalphettes/docker-route53-dyndns bash
# Then inside the container run `docker-gen` to test the output:
docker-gen /app/cli53routes.tmpl

If it all works as expected, let us know and we can put this into the default template provided in this repository.

seertenedos commented 8 years ago

I tried with this config http://pastebin.com/3E8q2Tx6 but i get the following error template error: template: cli53routes.tmpl:9:8: executing "cli53routes.tmpl" at <$>: can't give argument to non-function $

seertenedos commented 8 years ago

http://pastebin.com/fVcP693X seems slightly better but still trying to track the error 1/24/2016 9:36:17 AM2016/01/23 22:36:17 Error running notify command: /bin/bash /tmp/cli53routes, exit status 2 1/24/2016 9:36:17 AM2016/01/23 22:36:17 /tmp/cli53routes: line 5: $'\r': command not found 1/24/2016 9:36:17 AM/tmp/cli53routes: line 6: $'\r': command not found 1/24/2016 9:36:17 AM/tmp/cli53routes: line 29: syntax error: unexpected end of file

seertenedos commented 8 years ago

http://pastebin.com/swm762Hb seems to be closer to a working version but now i think the error is not something different. The new error seems to be due to the first few lines of the script because i am not running this on AWS VM's. Basically there is a whole html 404 page been added as the public ip. it seems the first part of the script does nto correctly detect when you are not on AWS so it does not use the curl -s icanhazip.com to get the IP. i tested and that command would give me the correct ip if called.

seertenedos commented 8 years ago

This version on pastebin works. http://pastebin.com/EWbEH6Ga i know the line endings are wrong but i have no idea how to fix them. did a tweak to the logic to work out if it needs to go to the internet to get the public ip as well