dragonflyoss / Dragonfly

This repository has be archived and moved to the new repository https://github.com/dragonflyoss/Dragonfly2.
https://d7y.io
Apache License 2.0
6k stars 774 forks source link

Rewrite urls in dfdaemon #1394

Open jordanrinke opened 4 years ago

jordanrinke commented 4 years ago

Why you need it?

We have multiple transparent docker proxy caches internal to our network, but they are potentially different based on the site, provider etc. It would be useful if we could add a regex rewrite rule to transparently point to our local caches for draongfly, it would reduce our WAN traffic, and maximize our LCR choices while maintaining standard image paths/names in the manifests applied across all clusters. We use squid+https://github.com/rchunping/squid-urlrewrite to do this now, sitting in front of the supernode. If dfdaemon did the rewriting, we could eliminate squid/rewriting entirely and leverage just dragonfly.

How it could be?

Additional config in yaml to specify a url match pattern, and replace pattern. The format used in squid-urlrewrite works well for us currently.

Other related information

inoc603 commented 4 years ago

Currently we only have very simple matching and modification rules in dfdaemon, which can modify the protocol (http or https) and host. Will this meet your need?

proxies: 
# redirect all image layer requests to host registry-cache
- regx: blobs/sha256.*
  # hostname to redirect to
  redirect: registry-cache

Sorry that the redirect field seems to be missing from the docs for now. We'll fix that soon.

jordanrinke commented 4 years ago

This may work, I will read the code and test with it. Thanks.