mirror of
https://github.com/umputun/reproxy.git
synced 2025-09-16 08:46:17 +02:00
add support of docker route prefix
This commit is contained in:
@@ -76,7 +76,7 @@ This is a dynamic provider and file change will be applied automatically.
|
||||
|
||||
### Docker
|
||||
|
||||
Docker provider supports a fully automatic discovery (with `--docker.auto`) with no extra configuration and by default redirects all requests like `https://server/<container_name>/(.*)` to the internal IP of the given container and the exposed port. Only active (running) containers will be detected.
|
||||
Docker provider supports a fully automatic discovery (with `--docker.auto`) with no extra configuration and by default redirects all requests like `http://<container_name>:<container_port>/(.*)` 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:
|
||||
|
||||
@@ -95,6 +95,8 @@ With `--docker.auto`, all containers with exposed port will be considered as rou
|
||||
- Allow only a particular docker network with `--docker.network`
|
||||
- Set the label `reproxy.enabled=false` or `reproxy.enabled=no` or `reproxy.enabled=0`
|
||||
|
||||
If no `reproxy.route` defined, the default is `http://<container_name>:<container_port>/(.*)`. In case if all proxied source have the same pattern, for example `/api/(.*)` user can define the common prefix (in this case `/api`) for all container-based routes. This can be done with `--docker.prefix` parameter.
|
||||
|
||||
This is a dynamic provider and any change in container's status will be applied automatically.
|
||||
|
||||
## SSL support
|
||||
@@ -183,7 +185,7 @@ ssl:
|
||||
assets:
|
||||
-a, --assets.location= assets location [$ASSETS_LOCATION]
|
||||
--assets.root= assets web root (default: /) [$ASSETS_ROOT]
|
||||
--assets.cache= cache duration for assets (default: 0s) [$ASSETS_CACHE]
|
||||
--assets.cache= cache duration for assets [$ASSETS_CACHE]
|
||||
|
||||
logger:
|
||||
--logger.stdout enable stdout logging [$LOGGER_STDOUT]
|
||||
@@ -198,6 +200,7 @@ docker:
|
||||
--docker.network= docker network [$DOCKER_NETWORK]
|
||||
--docker.exclude= excluded containers [$DOCKER_EXCLUDE]
|
||||
--docker.auto enable automatic routing (without labels) [$DOCKER_AUTO]
|
||||
--docker.prefix= prefix for docker source routes [$DOCKER_PREFIX]
|
||||
|
||||
file:
|
||||
--file.enabled enable file provider [$FILE_ENABLED]
|
||||
|
@@ -29,6 +29,7 @@ type Docker struct {
|
||||
DockerClient DockerClient
|
||||
Excludes []string
|
||||
AutoAPI bool
|
||||
APIPrefix string
|
||||
RefreshInterval time.Duration
|
||||
}
|
||||
|
||||
@@ -70,10 +71,15 @@ func (d *Docker) List() ([]discovery.URLMapper, error) {
|
||||
res := make([]discovery.URLMapper, 0, len(containers))
|
||||
for _, c := range containers {
|
||||
enabled, explicit := false, false
|
||||
srcURL := fmt.Sprintf("^/%s/(.*)", c.Name)
|
||||
srcURL := fmt.Sprintf("^/%s/(.*)", c.Name) // default destination
|
||||
if d.APIPrefix != "" {
|
||||
prefix := strings.TrimLeft(d.APIPrefix, "/")
|
||||
prefix = strings.TrimRight(prefix, "/")
|
||||
srcURL = fmt.Sprintf("^/%s/%s/(.*)", prefix, c.Name) // default destination with api prefix
|
||||
}
|
||||
|
||||
if d.AutoAPI {
|
||||
enabled = true
|
||||
srcURL = fmt.Sprintf("^/api/%s/(.*)", c.Name)
|
||||
}
|
||||
|
||||
port, err := d.matchedPort(c)
|
||||
|
@@ -93,7 +93,7 @@ func TestDocker_ListWithAutoAPI(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
d := Docker{DockerClient: dclient, AutoAPI: true}
|
||||
d := Docker{DockerClient: dclient, AutoAPI: true, APIPrefix: "/api"}
|
||||
res, err := d.List()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 3, len(res))
|
||||
|
13
app/main.go
13
app/main.go
@@ -54,11 +54,12 @@ var opts struct {
|
||||
} `group:"logger" namespace:"logger" env-namespace:"LOGGER"`
|
||||
|
||||
Docker struct {
|
||||
Enabled bool `long:"enabled" env:"ENABLED" description:"enable docker provider"`
|
||||
Host string `long:"host" env:"HOST" default:"unix:///var/run/docker.sock" description:"docker host"`
|
||||
Network string `long:"network" env:"NETWORK" default:"" description:"docker network"`
|
||||
Excluded []string `long:"exclude" env:"EXCLUDE" description:"excluded containers" env-delim:","`
|
||||
AutoAPI bool `long:"auto" env:"AUTO" description:"enable automatic routing (without labels)"`
|
||||
Enabled bool `long:"enabled" env:"ENABLED" description:"enable docker provider"`
|
||||
Host string `long:"host" env:"HOST" default:"unix:///var/run/docker.sock" description:"docker host"`
|
||||
Network string `long:"network" env:"NETWORK" default:"" description:"docker network"`
|
||||
Excluded []string `long:"exclude" env:"EXCLUDE" description:"excluded containers" env-delim:","`
|
||||
AutoAPI bool `long:"auto" env:"AUTO" description:"enable automatic routing (without labels)"`
|
||||
APIPrefix string `long:"prefix" env:"PREFIX" description:"prefix for docker source routes"`
|
||||
} `group:"docker" namespace:"docker" env-namespace:"DOCKER"`
|
||||
|
||||
File struct {
|
||||
@@ -251,7 +252,7 @@ func makeProviders() ([]discovery.Provider, error) {
|
||||
const refreshInterval = time.Second * 10 // seems like a reasonable default
|
||||
|
||||
res = append(res, &provider.Docker{DockerClient: client, Excludes: opts.Docker.Excluded,
|
||||
AutoAPI: opts.Docker.AutoAPI, RefreshInterval: refreshInterval})
|
||||
AutoAPI: opts.Docker.AutoAPI, APIPrefix: opts.Docker.APIPrefix, RefreshInterval: refreshInterval})
|
||||
}
|
||||
|
||||
if len(res) == 0 && opts.Assets.Location == "" {
|
||||
|
Reference in New Issue
Block a user