diff --git a/cli/server/init.go b/cli/server/init.go index f423844b7..d9a44d676 100644 --- a/cli/server/init.go +++ b/cli/server/init.go @@ -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() - } - - if string(ipv4) == "" { - return fmt.Errorf("unable to retrieve ipv4 address for %s", host) + 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), + } + // 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