Skip to content

Commit adf4394

Browse files
committed
add port derivation logic
1 parent fff3d0c commit adf4394

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

internal/discovery/docker.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,32 @@ func (w *DockerWatcher) DiscoverServiceInfo(svc DiscoveredService, onDiscovered
354354
svc.Service = &services[0]
355355
}
356356

357+
log.Printf("docker: before port selection for %s: port=%d, service=%v", svc.Subdomain, svc.Port, svc.Service)
358+
derivedPort := w.derivePorts(&svc, services)
359+
if derivedPort == 0 {
360+
log.Printf("docker: no port derived for %s, continuing to use %d", svc.Subdomain, svc.Port)
361+
} else {
362+
log.Printf("docker: after port selection for %s: port=%d, service=%v", svc.Subdomain, svc.Port, svc.Service)
363+
}
357364
log.Printf("docker: discovered %d services for %s", len(services), svc.Subdomain)
358365
onDiscovered(svc)
359366
}()
360367
}
368+
369+
func (*DockerWatcher) derivePorts(svc *DiscoveredService, services []ServiceInfo) int {
370+
port := 0
371+
372+
if len(svc.Docker.Ports) > 1 {
373+
for _, s := range services {
374+
if s.Protocol == "http" || s.Protocol == "https" {
375+
oldPort := svc.Port
376+
svc.Port = s.Port
377+
svc.Service = &s
378+
log.Printf("docker: using HTTP port %d instead of %d for %s", s.Port, oldPort, svc.Subdomain)
379+
port = svc.Port
380+
break
381+
}
382+
}
383+
}
384+
return port
385+
}

0 commit comments

Comments
 (0)