Skip to content

Commit 79e5b92

Browse files
committed
add port derivation logic
1 parent fff3d0c commit 79e5b92

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

internal/discovery/docker.go

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

357+
w.derivePorts(svc, services)
357358
log.Printf("docker: discovered %d services for %s", len(services), svc.Subdomain)
358359
onDiscovered(svc)
359360
}()
360361
}
362+
363+
func (*DockerWatcher) derivePorts(svc DiscoveredService, services []ServiceInfo) {
364+
log.Printf("docker: before port selection for %s: port=%d, service=%v", svc.Subdomain, svc.Port, svc.Service)
365+
366+
if len(svc.Docker.Ports) > 1 {
367+
isCurrentHTTP := svc.Service != nil && (svc.Service.Protocol == "http" || svc.Service.Protocol == "https")
368+
if !isCurrentHTTP {
369+
for _, s := range services {
370+
if s.Protocol == "http" || s.Protocol == "https" {
371+
oldPort := svc.Port
372+
svc.Port = s.Port
373+
svc.Service = &s
374+
log.Printf("docker: using HTTP port %d instead of %d for %s", s.Port, oldPort, svc.Subdomain)
375+
break a
376+
}
377+
}
378+
}
379+
}
380+
381+
log.Printf("docker: after port selection for %s: port=%d, service=%v", svc.Subdomain, svc.Port, svc.Service)
382+
}

0 commit comments

Comments
 (0)