Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple docker hosts #916

Open
wants to merge 6 commits into
base: swag-auto-proxy
Choose a base branch
from

Conversation

FoxxMD
Copy link

@FoxxMD FoxxMD commented Jun 11, 2024

  • generate configs using both docker.sock and DOCKER_HOST data
  • parse multiple hosts from DOCKER_HOST
  • enable generating swag_url with host friendly name inserted
  • enable setting TLD globally or per-host
  • maintain backwards compatibility with current functionality

Replicated from the updated readme:

Multiple Hosts:

If both DOCKER_HOST and docker.sock volumes are provided this mod will detect containers using both connections. As noted in the requirements, containers detected via docker.sock must be in the same user defined network or have swag_address label set.

Multiple remote hosts can be used via DOCKER_HOST by separating hosts with a comma. Additional per-host settings can be assigned by separating with a pipe |. The syntax for per-host configuration:

host:port|friendly_name|default_tld
DOCKER_HOST=192.168.0.100:2375|serverA,192.168.0.110:2375|serverB|local.test,192.168.0.130:2375
  • Host: 192.168.0.100:2375 -- Friendly Name: serverA -- TLD: *
  • Host: 192.168.0.110:2375 -- Friendly Name: serverB -- TLD: local.test
  • Host: 192.168.0.130:2375 -- Friendly Name: host3 -- TLD: *

Upstream IP and Port

When using a remote docker host from DOCKER_HOST auto-proxy assumes the detected containers are not on the same network as SWAG:

  • If the detected containers do not have the swag_address label set then the Host IP will be used.
  • If the detected containers do not have the swag_port label set then auto-proxy looks for exposed container ports and uses the corresponding host port as the upstream port. Container ports are checked in this order:
    • 80
    • 8080
    • The first mapped port, if any

Subdomains and TLD

If a detected container does not have the swag_url label set then the subdomain and TLD can be programmatically generated.

The default TLD used in nginx server_name directive can be set using AUTO_PROXY_HOST_TLD. This can also be set per-host using the syntax described in DOCKER_HOST for default_tld.

The subdomain used for a container can optionally be modified to include the Host's friendly_name described in the DOCKER_HOST syntax by setting AUTO_PROXY_HOST_INSERT to either prefix or suffix

Examples using a container named overseer:

  • Using only AUTO_PROXY_HOST_INSERT to modify subdomain
    • DOCKER_HOST=192.168.0.100:2375|serverA
    • AUTO_PROXY_HOST_TLD (not set, defaults to *)
    • AUTO_PROXY_HOST_INSERT
      • (unset) => nginx server_name overseer.*
      • prefix => nginx server_name serverA-overseer.*
      • suffix => nginx server_name overseer-serverA.*
  • Using AUTO_PROXY_HOST_INSERT prefix and AUTO_PROXY_HOST_TLD
    • DOCKER_HOST=192.168.0.100:2375|serverA
    • AUTO_PROXY_HOST_TLD=test.home
    • AUTO_PROXY_HOST_INSERT=prefix
      • server_name serverA-overseer.test.home
  • Using AUTO_PROXY_HOST_INSERT prefix and default_tld
    • DOCKER_HOST=192.168.0.100:2375|serverA|myserver.home
    • AUTO_PROXY_HOST_INSERT=prefix
      • server_name serverA-overseer.myserver.home
  • Using AUTO_PROXY_HOST_TLD only
    • DOCKER_HOST=192.168.0.100:2375
    • AUTO_PROXY_HOST_TLD=myserver.home
      • server_name overseer.myserver.home

* generate configs using both docker.sock and DOCKER_HOST data
* parse multiple hosts from DOCKER_HOST
* enable generating swag_url with host friendly name inserted
* maintain backwards compatibility with current functionality
@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_916

* Keep existing behavior if no upstream host
* When using upstream host look for 80, 8080, or first exposed container port and use HostPort for upstream
@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_916

@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_916

1 similar comment
@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_916

Prefix insert/tld ENVs with AUTO_PROXY to make it clear they are related to this mod
@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_916

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants