Skip to content

Commit 34c1774

Browse files
committed
Support Docker bridge networking and Kubo URL env
Add detection of the container's own bridge IP for proxy targets and environment-driven Kubo API address handling. blox/kubo_proxy.go: add a new detection step that iterates local interfaces (skipping lo, docker*, br-*, veth) to find the container's bridge IPv4 and return it as the proxy target; keep existing docker0/br-* detection and fallback to 127.0.0.1. Adds an informational log when a container bridge IP is detected. cmd/blox/main.go: read KUBO_API_URL (default http://127.0.0.1:5001), parse host:port, resolve host via DNS to an IP (to support Docker DNS names like "kubo"), construct the IP-based multiaddr, and pass the kubo address into the blox options via WithKuboAPIAddr. Also adds a strings import. These changes enable running go-fula inside bridge-networked containers and using docker-compose service names for the Kubo API.
1 parent 7d178ab commit 34c1774

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

blox/kubo_proxy.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ func getProtocols() []p2pProtocol {
6767
// Detection order:
6868
// 1. docker0 interface IPv4 address (Docker default bridge gateway)
6969
// 2. Any Docker Compose bridge (br-<hash>) IPv4 address
70-
// 3. Fallback to 127.0.0.1 (works when kubo is also on host network)
70+
// 3. Container's own bridge IP (when go-fula runs inside a bridge-networked container)
71+
// 4. Fallback to 127.0.0.1 (works when kubo is also on host network)
7172
func resolveProxyTargetIP() string {
7273
// 1. Try docker0 (default Docker bridge)
7374
if ip := getIPv4FromInterface("docker0"); ip != "" {
@@ -88,7 +89,29 @@ func resolveProxyTargetIP() string {
8889
}
8990
}
9091

91-
// 3. Fallback
92+
// 3. Container's own bridge IP (Docker bridge networking mode).
93+
// When go-fula runs inside a container on a bridge network,
94+
// docker0/br-* don't exist inside the container. Use the container's
95+
// own IPv4 on its bridge interface (typically eth0), which is reachable
96+
// from other containers on the same Docker Compose network.
97+
if ifaces == nil {
98+
ifaces, _ = net.Interfaces()
99+
}
100+
if ifaces != nil {
101+
for _, iface := range ifaces {
102+
if iface.Name == "lo" || strings.HasPrefix(iface.Name, "docker") ||
103+
strings.HasPrefix(iface.Name, "br-") || strings.HasPrefix(iface.Name, "veth") {
104+
continue
105+
}
106+
if ip := getIPv4FromInterface(iface.Name); ip != "" {
107+
log.Infow("Detected container bridge IP for proxy target (bridge networking mode)",
108+
"iface", iface.Name, "ip", ip)
109+
return ip
110+
}
111+
}
112+
}
113+
114+
// 4. Fallback
92115
log.Debug("No Docker bridge interface found, using 127.0.0.1 for proxy target")
93116
return "127.0.0.1"
94117
}

cmd/blox/main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path"
2121
"path/filepath"
2222
"strconv"
23+
"strings"
2324
"sync"
2425
"syscall"
2526
"time"
@@ -1089,7 +1090,23 @@ func action(ctx *cli.Context) error {
10891090
linkSystem := cidlink.DefaultLinkSystem()
10901091
linkSystem.StorageReadOpener = CustomStorageReadOpenerNone
10911092
linkSystem.StorageWriteOpener = CustomStorageWriteOpenerNone
1092-
nodeMultiAddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/5001")
1093+
1094+
// Read kubo API address from env (set in docker-compose.pc.yml for bridge networking)
1095+
kuboURL := os.Getenv("KUBO_API_URL")
1096+
if kuboURL == "" {
1097+
kuboURL = "http://127.0.0.1:5001"
1098+
}
1099+
kuboHostPort := strings.TrimPrefix(kuboURL, "http://")
1100+
kuboHost, kuboPort, err := net.SplitHostPort(kuboHostPort)
1101+
if err != nil {
1102+
kuboHost = kuboHostPort
1103+
kuboPort = "5001"
1104+
}
1105+
// Resolve hostname to IP for multiaddr (Docker DNS names like "kubo" → container IP)
1106+
if ips, err := net.LookupHost(kuboHost); err == nil && len(ips) > 0 {
1107+
kuboHost = ips[0]
1108+
}
1109+
nodeMultiAddr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%s", kuboHost, kuboPort))
10931110
if err != nil {
10941111
panic(fmt.Errorf("invalid multiaddress: %w", err))
10951112
}
@@ -1136,6 +1153,7 @@ func action(ctx *cli.Context) error {
11361153
blox.WithIpfsClient(node),
11371154
blox.WithPoolHostMode(app.poolHost),
11381155
blox.WithIpfsClusterAPI(ipfsClusterApi),
1156+
blox.WithKuboAPIAddr(kuboHostPort),
11391157
)
11401158
if err != nil {
11411159
return err

0 commit comments

Comments
 (0)