woodpecker-docker-buildx/plugin/coredns.go
Lauris BH a2d26878e7 Add internal DNS server if no custom DNS is set (#45)
Fixes #44

Co-authored-by: Lauris BH <lauris@nix.lv>
Reviewed-on: https://codeberg.org/woodpecker-plugins/plugin-docker-buildx/pulls/45
Reviewed-by: 6543 <6543@obermui.de>
Co-authored-by: Lauris BH <lafriks@noreply.codeberg.org>
Co-committed-by: Lauris BH <lafriks@noreply.codeberg.org>
2022-11-23 14:01:45 +00:00

49 lines
773 B
Go

package plugin
import (
"io"
"net"
"os"
"os/exec"
)
func (p Plugin) startCoredns() {
cmd := exec.Command("coredns", "-conf", "/etc/coredns/Corefile")
if p.settings.Daemon.Debug {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
} else {
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
}
go func() {
trace(cmd)
cmd.Run()
}()
}
func getContainerIP() (string, error) {
ifaces, err := net.Interfaces()
if err != nil {
return "", err
}
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
return "", err
}
for _, addr := range addrs {
switch v := addr.(type) {
case *net.IPNet:
if v.IP.IsLoopback() {
continue
}
if v.IP.To4() != nil {
return v.IP.String(), nil
}
}
}
}
return "", nil
}