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

@LinuxServer-CI
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

@FoxxMD
Copy link
Author

FoxxMD commented Jul 14, 2024

Other than needing to fast-forward with the current tree there is no other feedback I have received. The changes are feature complete as far as I'm concerned. I've been using this on my own servers for weeks. I guess I'll mention some previous contributors since no one is looking at this? @aptalca @nemchik ?

@LinuxServer-CI
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

@FoxxMD
Copy link
Author

FoxxMD commented Aug 15, 2024

The PR is still ready other than needing to be synced with the upstream. Can someone please take a look?

@aptalca
Copy link
Member

aptalca commented Aug 15, 2024

Thanks for the PR, but unfortunately this is not something I (the maintainer) can take on in terms of support and future maintenance.

The changes are very extensive, and it even adds a wrapper while the benefit is not that great. I do see the benefit, but very few people would actually need this, which makes this a niche feature.

I'm afraid the cost to benefit ratio is way too high for me.

I'll leave it open in case another team member is interested in taking over maintenance and is ok with merging this in.

@dacagi
Copy link

dacagi commented Aug 18, 2024

I would actually love to have this feature. I have been most of the day looking for a way to autodiscover from my two hosts. Most people may start with running on a single Raspberry, but once you start to self-host there's no stop. It's worse than Pringles.

I understand the whole project is about a single host, but it has already grown to even configuring Uptime. Why not reaching out to another host on the network? TCP communication instead of only socket is already available.

I just arrived and don't know much about the internals, but this would be a nic(h)e feature. I haven't found any other project that allows this without getting into container orchestration swarms and so on. It would really make SWAG shine.

Thanks FoxxMD for the huge work, I may give your version a try.

@4-FLOSS-Free-Libre-Open-Source-Software
Copy link

Time saver for anyone with more than a single device.

@FoxxMD
Copy link
Author

FoxxMD commented Sep 13, 2024

Just FYI my fork can be used even though this isn't merged. I've pushed an image to docker (or the LSIO pr image could be used):

services:
  swag:
   #...
    environment:
      DOCKER_MODS: "linuxserver/mods:universal-docker|foxxmd/auto-proxy-multi"

@LinuxServer-CI
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

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

Successfully merging this pull request may close these issues.

5 participants