fix: look up ipv4 from host correctly
We use a custom resolver now instead of relying on the baked-in Golang resolver which has issues. We use a friendly librehoster DNS resolver and not Google because fuck that.
This commit is contained in:
parent
efb9d6f6a5
commit
9378db1979
@ -5,11 +5,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/client"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -36,20 +38,31 @@ later for more advanced use cases.
|
||||
return err
|
||||
}
|
||||
|
||||
var ipv4 net.IP
|
||||
ips, _ := net.LookupIP(host)
|
||||
for _, ip := range ips {
|
||||
ipv4 = ip.To4()
|
||||
resolver := &net.Resolver{
|
||||
PreferGo: false,
|
||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
d := net.Dialer{
|
||||
Timeout: time.Millisecond * time.Duration(10000),
|
||||
}
|
||||
|
||||
if string(ipv4) == "" {
|
||||
return fmt.Errorf("unable to retrieve ipv4 address for %s", host)
|
||||
// comrade librehosters DNS resolver https://snopyta.org/service/dns/
|
||||
return d.DialContext(ctx, "udp", "95.216.24.230:53")
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ips, err := resolver.LookupIPAddr(ctx, host)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if len(ips) == 0 {
|
||||
return fmt.Errorf("unable to retrieve ipv4 address for %s", host)
|
||||
}
|
||||
ipv4 := ips[0].IP.To4().String()
|
||||
|
||||
initReq := swarm.InitRequest{
|
||||
ListenAddr: "0.0.0.0:2377",
|
||||
AdvertiseAddr: string(ipv4),
|
||||
AdvertiseAddr: ipv4,
|
||||
}
|
||||
if _, err := cl.SwarmInit(ctx, initReq); err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user