mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-22 10:10:39 +00:00
39 lines
703 B
Go
39 lines
703 B
Go
|
package plugin
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
)
|
||
|
|
||
|
func GetContainerIP() (string, error) {
|
||
|
netInterfaceAddrList, err := net.InterfaceAddrs()
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
for _, netInterfaceAddr := range netInterfaceAddrList {
|
||
|
netIP, ok := netInterfaceAddr.(*net.IPNet)
|
||
|
if ok && !netIP.IP.IsLoopback() && netIP.IP.To4() != nil {
|
||
|
return netIP.IP.String(), nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return "", nil
|
||
|
}
|
||
|
|
||
|
func WriteDockerConf(path, conf string) error {
|
||
|
confPath := filepath.Join(path, ".docker", "config.json")
|
||
|
|
||
|
if err := os.MkdirAll(confPath, strictFilePerm); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
err := os.WriteFile(path, []byte(conf), strictFilePerm)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|