Skip to content

Commit cdeb5ec

Browse files
committed
Better docstrings
1 parent 8689525 commit cdeb5ec

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

internal/docker/builder.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ func printPortBindingsOfAllComplementContainers(docker *client.Client, contextSt
539539
log.Printf("=============== %s : END ALL COMPLEMENT DOCKER PORT BINDINGS ===============\n\n\n", contextStr)
540540
}
541541

542+
// Transform the homeserver ports into the base URL and federation base URL.
542543
func endpoints(p nat.PortMap, hsPortBindingIP string, csPort, ssPort int) (baseURL, fedBaseURL string, err error) {
543544
csapiPortBinding, err := findPortBinding(p, hsPortBindingIP, csPort)
544545
if err != nil {
@@ -554,7 +555,12 @@ func endpoints(p nat.PortMap, hsPortBindingIP string, csPort, ssPort int) (baseU
554555
return
555556
}
556557

557-
// Find a matching port binding for the given host/port in the nat.PortMap.
558+
// Find a matching port binding for the given host/port in the `nat.PortMap`.
559+
//
560+
// This function will return the first port binding that matches the given host IP. If a
561+
// `0.0.0.0` binding is found, we will assume that it is listening on all interfaces,
562+
// including the `hsPortBindingIP`, and return a binding with the `hsPortBindingIP` as
563+
// the host IP.
558564
func findPortBinding(p nat.PortMap, hsPortBindingIP string, port int) (portBinding nat.PortBinding, err error) {
559565
portString := fmt.Sprintf("%d/tcp", port)
560566
portBindings, ok := p[nat.Port(portString)]

internal/docker/deployer.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ func assertHostnameEqual(inputUrl string, expectedHostname string) error {
529529
return nil
530530
}
531531

532+
// Returns URL's that are accessible from the host machine (outside the container) for
533+
// the homeserver's client API and federation API.
532534
func getHostAccessibleHomeserverUrls(ctx context.Context, docker *client.Client, containerID string, hsPortBindingIP string) (baseURL string, fedBaseURL string, err error) {
533535
inspectResponse, err := inspectPortsOnContainer(ctx, docker, containerID)
534536
if err != nil {
@@ -537,10 +539,10 @@ func getHostAccessibleHomeserverUrls(ctx context.Context, docker *client.Client,
537539

538540
baseURL, fedBaseURL, err = endpoints(inspectResponse.NetworkSettings.Ports, hsPortBindingIP, 8008, 8448)
539541

540-
// Sanity check that the URL's match the expected binding hostname. It's important
541-
// that we use the canonical publically accessible hostname for the homeserver as ...
542-
// such as important cookies that are set during a SSO/OIDC login process (cookies are
543-
// scoped to the domain).
542+
// Sanity check that the URL's match the expected configured binding hostname. It's
543+
// also important that we use the canonical publicly accessible hostname for the
544+
// homeserver for some situations like SSO/OIDC login where important cookies are set
545+
// for the domain.
544546
err = assertHostnameEqual(baseURL, hsPortBindingIP)
545547
if err != nil {
546548
return "", "", fmt.Errorf("failed to assert baseURL has the correct hostname: %w", err)
@@ -574,7 +576,8 @@ func waitForPorts(ctx context.Context, docker *client.Client, containerID string
574576
type ContainerInspectionError struct {
575577
// Error message
576578
msg string
577-
// Whether this error should stop retrying to inspect the container.
579+
// Indicates whether the caller should stop retrying to inspect the container because
580+
// it has already exited.
578581
Fatal bool
579582
}
580583

0 commit comments

Comments
 (0)