lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
3.02k stars 173 forks source link

Question: using the admin API alongside CDP? #670

Closed amosbastian closed 2 weeks ago

amosbastian commented 2 weeks ago

I'm using Dokku to deploys my apps and using their Caddy proxy, which is caddy-docker-proxy. One of my projects is a SaaS where users can add a custom domain.

In the past when I wasn't using caddy-docker-proxy and just had Caddy running in a container, I'd use the admin API to add entries, and this was working fine.

So, my question is basically if I can do the same while using caddy-docker-proxy? I'm assuming it won't be recommended to mix using labels and the admin API, and if so, what would you recommend instead?

francislavoie commented 2 weeks ago

Duplicate, see my comment here https://github.com/lucaslorentz/caddy-docker-proxy/issues/624#issuecomment-2433464833

But no, you should not try to modify the config using the API if you're using CDP, because next time CDP makes a change it will wipe away your own change. You should do it via CDP's labels, or via a base Caddyfile (see env var options in the README).

amosbastian commented 2 weeks ago

Duplicate, see my comment here #624 (comment)

But no, you should not try to modify the config using the API if you're using CDP, because next time CDP makes a change it will wipe away your own change. You should do it via CDP's labels, or via a base Caddyfile (see env var options in the README).

I need to modify the Caddyfile to add new entries, so I don't see how using a base Caddyfile is a solution here? I guess I should just get rid of CDP since it seems like it doesn't support my use case

francislavoie commented 2 weeks ago

It depends what you mean by "entries". What config are you trying to add exactly?

amosbastian commented 2 weeks ago

It depends what you mean by "entries". What config are you trying to add exactly?

As explained above, basically users can add a custom domain, so then I'll call the admin API and it will add a route like this

{
  "admin": { "listen": ":2019" },
  "apps": {
    "http": {
      "servers": {
        "test": {
          "listen": [":443"],
          "routes": [
            {
              "handle": [
                {
                  "handler": "reverse_proxy",
                  "rewrite": { "uri": "/test{http.request.uri}" },
                  "upstreams": [{ "dial": "localhost:1234" }]
                }
              ],
              "match": [{ "host": ["example.com"] }],
              "terminal": true
            }
          ]
        },
        "local": {}
      }
    }
  }
}