support reproxy.enabled label, enforce this label for reproxy container itself #16

This commit is contained in:
Umputun 2021-04-11 01:37:45 -05:00
parent 825a3c3c7f
commit 9462170cd1
5 changed files with 20 additions and 2 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
access.log
var/
dist/
docker-compose-private.yml

View File

@ -21,7 +21,7 @@ FROM umputun/baseimage:app-latest
COPY --from=backend /build/reproxy /srv/reproxy
RUN chmod +x /srv/reproxy
LABEL reproxy.enabled="false"
WORKDIR /srv
CMD ["/srv/reproxy"]

View File

@ -68,10 +68,11 @@ This default can be changed with labels:
- `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:
By default all containers with exposed port will be considered as routing destinations. There are 3 ways to restrict it:
- Exclude some containers explicitly with `--docker.exclude`, i.e. `--docker.exclude=c1 --docker.exclude=c2 ...`
- Allow only a particular docker network with `--docker.network`
- Set the label `reproxy.enabled=false` or `reproxy.enabled=no`
This is a dynamic provider and any change in container's status will be applied automatically.

View File

@ -162,6 +162,13 @@ func (d *Docker) listContainers() (res []containerInfo, err error) {
continue
}
if v, ok := c.Labels["reproxy.enabled"]; ok {
if strings.EqualFold(v, "false") || strings.EqualFold(v, "no") {
log.Printf("[DEBUG] skip container %s due to reproxy.enabled=%s", containerName, v)
continue
}
}
var ip string
for k, v := range c.Networks.Networks {
if d.Network == "" || k == d.Network { // match on network name if defined

View File

@ -41,6 +41,15 @@ func TestDocker_List(t *testing.T) {
{PrivatePort: 12345},
},
},
{Names: []string{"c5"}, State: "running",
Networks: dc.NetworkList{
Networks: map[string]dc.ContainerNetwork{"bridge": {IPAddress: "127.0.0.122"}},
},
Ports: []dc.APIPort{
{PrivatePort: 2345},
},
Labels: map[string]string{"reproxy.enabled": "false"},
},
}, nil
},
}