1
0
mirror of https://github.com/umputun/reproxy.git synced 2024-11-24 08:12:31 +02:00

fix ping path from docker labels, clarify docs about path (not url) for the destination

This commit is contained in:
Umputun 2021-04-10 02:44:40 -05:00
parent 5f3647b066
commit 6bcb791bc5
5 changed files with 16 additions and 6 deletions

View File

@ -58,14 +58,14 @@ This is a dynamic provider and file change will be applied automatically.
### Docker
Docker provider works with no extra configuration and by default redirects all requests like `https://server/api/<container_name>/(.*)` to the internal IP of given container and the exposed port. Only active (running) containers will be detected.
Docker provider works with no extra configuration and by default redirects all requests like `https://server/api/<container_name>/(.*)` to the internal IP of the given container and the exposed port. Only active (running) containers will be detected.
This default can be changed with labels:
- `reproxy.server` - server (hostname) to match
- `reproxy.route` - source route (location)
- `reproxy.dest` - destination URL
- `reproxy.ping` - ping url for the destination container
- `reproxy.dest` - destination path. Note: this is not full url, but just the path which will be appended to container's ip:port
- `reproxy.ping` - ping path for the destination container.
By default all containers with exposed port will be considered as routing destinations. There are 2 ways to restrict it:

View File

@ -137,6 +137,8 @@ func (s *Service) mergeLists() (res []URLMapper) {
func (s *Service) extendRule(m URLMapper) URLMapper {
src := m.SrcMatch.String()
// TODO: Probably should be ok in practice but we better figure a nicer way to do it
if strings.Contains(m.Dst, "$1") || strings.Contains(src, "(") || !strings.HasSuffix(src, "/") {
return m
}

View File

@ -88,7 +88,7 @@ func (d *Docker) List() ([]discovery.URLMapper, error) {
srcRegex, err := regexp.Compile(srcURL)
if v, ok := c.Labels["reproxy.ping"]; ok {
pingURL = v
pingURL = fmt.Sprintf("http://%s:%d%s", c.IP, c.Port, v)
}
if err != nil {

View File

@ -22,7 +22,7 @@ func TestDocker_List(t *testing.T) {
{PrivatePort: 12345},
},
Labels: map[string]string{"reproxy.route": "^/api/123/(.*)", "reproxy.dest": "/blah/$1",
"reproxy.server": "example.com", "reproxy.ping": "http://localhost/ping"},
"reproxy.server": "example.com", "reproxy.ping": "/ping"},
},
{Names: []string{"c2"}, State: "running",
Networks: dc.NetworkList{
@ -53,7 +53,7 @@ func TestDocker_List(t *testing.T) {
assert.Equal(t, "^/api/123/(.*)", res[0].SrcMatch.String())
assert.Equal(t, "http://127.0.0.2:12345/blah/$1", res[0].Dst)
assert.Equal(t, "example.com", res[0].Server)
assert.Equal(t, "http://localhost/ping", res[0].PingURL)
assert.Equal(t, "http://127.0.0.2:12345/ping", res[0].PingURL)
assert.Equal(t, "^/api/c2/(.*)", res[1].SrcMatch.String())
assert.Equal(t, "http://127.0.0.3:12346/$1", res[1].Dst)

View File

@ -28,3 +28,11 @@ services:
ports:
- "9092"
command: python3 -m http.server 9092
whoami:
image: 'containous/whoami'
container_name: whoami
labels:
reproxy.server: '*'
reproxy.route: '^/whoami/(.*)'
reproxy.dest: '/$$1'