fix: allow setting a custom ip address as the ip pf the dokku server

This will provide the ability to override cases where the detected ip address is invalid for whatever reason.
This commit is contained in:
Jose Diaz-Gonzalez committed 2024-01-23 03:26:32 -05:00
1 parent c6838b645e
commit 204517074b
4 files changed
+72 -56

No files matched your search

+31
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net"
"os"
"sort"
"strconv"
@@ -502,6 +503,36 @@ func getProcessResources(appName string, processType string) (ProcessResourcesMa
return processResources, nil
}
func getServerIP() (string, error) {
serverIP := ""
networkInterface := getGlobalNetworkInterface()
ifaces, err := net.Interfaces()
if err != nil {
return "", fmt.Errorf("Unable to get network interfaces: %w", err)
}
for _, iface := range ifaces {
if iface.Name == networkInterface {
addr, err := iface.Addrs()
if err != nil {
return "", fmt.Errorf("Unable to get network addresses for interface %s: %w", networkInterface, err)
}
for _, a := range addr {
if ipnet, ok := a.(*net.IPNet); ok {
if ipnet.IP.To4() != nil {
serverIP = ipnet.IP.String()
}
}
}
}
}
if len(serverIP) == 0 {
return "", fmt.Errorf(fmt.Sprintf("Unable to determine server ip address from network-interface %s", networkInterface))
}
return serverIP, nil
}
func getStartCommand(input StartCommandInput) (StartCommandOutput, error) {
command := extractStartCommand(input)
fields, err := shell.Fields(command, func(name string) string {