mholt / caddy-dynamicdns

Caddy app that keeps your DNS records (A/AAAA) pointed at itself.
Apache License 2.0
250 stars 25 forks source link

Variable for public ip #42

Closed WEBzaytsev closed 1 year ago

WEBzaytsev commented 1 year ago

I use docker for my home lab. Does the module have the ability to use a variable ip to specify it in docker compose?

mholt commented 1 year ago

If the configured IP source (it defaults to public IP sources) returns the IP address docker assigns, then yes. I don't know about Docker though. Maybe @francislavoie could answer this.

francislavoie commented 1 year ago

You mean like a static IP instead of fetching it on-demand? Yeah we could do that, we'd just need to add a new static IPSource module, and it could use placeholders to use environment variables, so like ip_source static {env.STATIC_IP} or whatever.

WEBzaytsev commented 1 year ago

I just want to get the current ip from a variable My caddy file goes to the external resource https://icanhazip.com and finds out the external ip there (since my home server does not have a permanent ip (which is what I use your application for)) I would like to understand if there is a variable in the plugin that I can use to specify my external ip. That my ISP gave me. For further use in my docker-compose file.

More specifics. I'm running an instance of sftpgo and it needs a passive ip in the environment variable "SFTPGO_FTPDBINDINGS0__FORCE_PASSIVE_IP" to enable normal ftp

The problem is that when you reboot the router the ip machine changes and it is inconvenient to change it again, and also creates downtime and delays in the work of the home lab

francislavoie commented 1 year ago

Oh, so you don't want to set a static IP for caddy-dynamicdns to use, you want caddy-dynamicdns to write the current known IP somewhere to be used by another service?

You could just scan the logs using jq, we write the current known IP to the logs. Or you could just use https://icanhazip.com/ yourself in a script of your own.

Caddy doesn't know anything about Docker (there's no Docker integration by default), so it wouldn't be possible for Caddy to set an env var on another container. Doing that would require Caddy being able to stop then set env vars and restart another container. That's totally out of scope.

But maybe I'm misunderstanding the ask. Could you try to clarify further?

mholt commented 1 year ago

I just want to get the current ip from a variable

Which IP though? A given device has potentially a lot of IP addresses.

WEBzaytsev commented 1 year ago

Yes, I want caddy-dynamicdns to write the current ip variable. For example I use "provider cloudflare {env.CLOUDFLARE_API_TOKEN}" in the caddyfile, but I can also use "CLOUDFLARE_API_TOKEN" in any of my "environments" in docker compose (https://i.imgur.com/rSETcr0.png)

WEBzaytsev commented 1 year ago

I just want to get the current ip from a variable

Which IP though? A given device has potentially a lot of IP addresses.

In my case there is always one external ip, it's just dynamic

francislavoie commented 1 year ago

Yes, I want caddy-dynamicdns to write the current ip variable.

Like I said, we already are, in the logs. There's no other place for Caddy to write it. I don't think this ask makes sense, really.

mholt commented 1 year ago

Do you mean, like, you want a new placeholder available for you to use in your config? Like {dynamicdns.ips.0} or something?

WEBzaytsev commented 1 year ago

Do you mean, like, you want a new placeholder available for you to use in your config? Like {dynamicdns.ips.0} or something?

The current ip is written in the logs. But not available for use as {env.CLOUDFLARE_API_TOKEN} I cannot use the current ip in my caddyfile as {env.}

francislavoie commented 1 year ago

It's not possible for Caddy running in a container to write an environment variable on another container.

WEBzaytsev commented 1 year ago

Yes, it is. But it can just write the environment variable. https://stackoverflow.com/a/37680288

WEBzaytsev commented 1 year ago

Or something along those lines. "Continue through the creation process until your API token has been created. Copy the API token and add it to your environment variables with the following command: echo "export CLOUDFLARE_AUTH_TOKEN=TOKEN_HERE" >> ~/.bashrc source ~/.bashrc "

WEBzaytsev commented 1 year ago

if there is for example a CLOUDFLARE_API_TOKEN variable I can use it in any of my docker-compose

WEBzaytsev commented 1 year ago

the caddy-ddns logs have old_ip(s?) and new_ip(s?) But I can't use them in any way, not even in the caddyfile

francislavoie commented 1 year ago

Caddy is running inside a container. It can't write a file that will exist outside the container for another container to pick up. Not to mention Caddy cannot trigger the other container to restart to pick up the change in environment variables. That's totally impossible unless Caddy specifically knows how to talk to Docker. And that's completely out of scope of this project.

This is a pretty unreasonable ask. Like I've said before, you can do this yourself. Write a bash script that watches Caddy's logs for the specific log message where Caddy writes out the IP addresses it's using. Or even better, do curl https://icanhazip.com to get essentially the same answer.