diff --git a/docs/content/docs/docker.md b/docs/content/docs/docker.md index 1064411..a63f063 100644 --- a/docs/content/docs/docker.md +++ b/docs/content/docs/docker.md @@ -167,4 +167,14 @@ labels: tsdproxy.tlsvalidate: "false" ``` +### tsdproxy.dash.visible + +Defaults to true, set to false to hide on Dashboard. + +```yaml +labels: + tsdproxy.enable: "true" + tsdproxy.dash.visible: "false" +``` + {{% /steps %}} diff --git a/docs/content/docs/files.md b/docs/content/docs/files.md index 5f6ef57..bacce89 100644 --- a/docs/content/docs/files.md +++ b/docs/content/docs/files.md @@ -59,7 +59,7 @@ This configuration will create two groups of proxies: - All access logs are enabled - music.ts.net, video.ts.net and photos.ts.net. - On the same host with different ports - - Sse 'default' Tailscale provider + - Use 'default' Tailscale provider - Don't enable access logs ### Provider Configuration options @@ -78,13 +78,15 @@ Files: music: # Name of the proxy URL: http://192.168.1.10:3789 # url of service to proxy ProxyProvider: default # (optional) name of the proxy provider - TLSValidate: false # (optional, default true) disable TLS validationTailscale + TLSValidate: false # (optional, default true) disable TLS validation Tailscale: # (optional) Tailscale configuration for this proxy - AuthKey: asdasdas # Tailscale authkey + AuthKey: asdasdas # (optional) Tailscale authkey Ephemeral: true # (optional) Enable ephemeral mode RunWebClient: false # (optional) Run web client Verbose: false # (optional) Run in verbose mode Funnel: false # (optional) Run in funnel mode + Dashboard: + Visible: false # (optional) doesn't show proxy in dashboard ``` {{% /steps %}} diff --git a/internal/targetproviders/docker/docker.go b/internal/targetproviders/docker/docker.go index fe8d372..bd30092 100644 --- a/internal/targetproviders/docker/docker.go +++ b/internal/targetproviders/docker/docker.go @@ -73,10 +73,7 @@ func (c *Client) Close() { } } -// GetAllProxies implements TargetProvider GetAllProxies method. -func (c *Client) GetAllProxies() (map[string]*proxyconfig.Config, error) { - ctx := context.Background() - proxies := map[string]*proxyconfig.Config{} +func (c *Client) startAllProxies(ctx context.Context, eventsChan chan targetproviders.TargetEvent, errChan chan error) { // Filter containers with enable set to true // containerFilter := filters.NewArgs() @@ -87,33 +84,13 @@ func (c *Client) GetAllProxies() (map[string]*proxyconfig.Config, error) { All: false, }) if err != nil { - return nil, fmt.Errorf("error listing containers: %w", err) + errChan <- fmt.Errorf("error listing containers: %w", err) + return } - var wg sync.WaitGroup for _, container := range containers { - // create the proxy configs in parallel. - wg.Add(1) - - go func() { - defer wg.Done() - - ctn, err := c.docker.ContainerInspect(ctx, container.ID) - if err != nil { - c.log.Error().Err(err).Str("containerID", container.ID).Msg("error inspecting container") - } else { - pcfg, err := c.newProxyConfig(ctn) - if err == nil { - proxies[pcfg.Hostname] = pcfg - } else { - c.log.Error().Err(err).Msg("error initializing proxy for container") - } - } - }() + eventsChan <- c.getStartEvent(container.ID) } - wg.Wait() - - return proxies, nil } // newProxyConfig method returns a new proxyconfig.Config @@ -147,7 +124,9 @@ func (c *Client) DeleteProxy(id string) error { if _, ok := c.containers[id]; !ok { return fmt.Errorf("container %s not found", id) } + c.deleteContainer(id) + return nil } @@ -187,6 +166,8 @@ func (c *Client) WatchEvents(ctx context.Context, eventsChan chan targetprovider } } }() + + go c.startAllProxies(ctx, eventsChan, errChan) } // getStartEvent method returns a targetproviders.TargetEvent for a container start @@ -203,6 +184,7 @@ func (c *Client) getStartEvent(id string) targetproviders.TargetEvent { // getStopEvent method returns a targetproviders.TargetEvent for a container stop func (c *Client) getStopEvent(id string) targetproviders.TargetEvent { c.log.Info().Msgf("Container %s stopped", id) + return targetproviders.TargetEvent{ TargetProvider: c, ID: id, @@ -214,6 +196,7 @@ func (c *Client) getStopEvent(id string) targetproviders.TargetEvent { func (c *Client) addContainer(cont *container, name string) { c.mutex.Lock() defer c.mutex.Unlock() + c.containers[name] = cont }