mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-24 12:50:41 +00:00
fix: use internal dns for docker if no default is set (#228)
This commit is contained in:
parent
6a78c8217c
commit
f6ce6cca84
@ -27,7 +27,7 @@ ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.10.4}"
|
|||||||
ENV DOCKER_HOST=unix:///var/run/docker.sock
|
ENV DOCKER_HOST=unix:///var/run/docker.sock
|
||||||
|
|
||||||
RUN apk --update add --virtual .build-deps curl && \
|
RUN apk --update add --virtual .build-deps curl && \
|
||||||
apk --update add --no-cache git && \
|
apk --update add --no-cache git coredns && \
|
||||||
mkdir -p /usr/lib/docker/cli-plugins/ && \
|
mkdir -p /usr/lib/docker/cli-plugins/ && \
|
||||||
curl -SsL -o /usr/lib/docker/cli-plugins/docker-buildx \
|
curl -SsL -o /usr/lib/docker/cli-plugins/docker-buildx \
|
||||||
"https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION##v}/buildx-v${BUILDX_VERSION##v}.${TARGETOS:-linux}-${TARGETARCH:-amd64}" && \
|
"https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION##v}/buildx-v${BUILDX_VERSION##v}.${TARGETOS:-linux}-${TARGETARCH:-amd64}" && \
|
||||||
@ -36,5 +36,6 @@ RUN apk --update add --virtual .build-deps curl && \
|
|||||||
rm -rf /var/cache/apk/* && \
|
rm -rf /var/cache/apk/* && \
|
||||||
rm -rf /tmp/*
|
rm -rf /tmp/*
|
||||||
|
|
||||||
|
COPY --from=build /src/Corefile /etc/coredns/Corefile
|
||||||
COPY --from=build /src/dist/drone-docker-buildx /bin/drone-docker-buildx
|
COPY --from=build /src/dist/drone-docker-buildx /bin/drone-docker-buildx
|
||||||
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "drone-docker-buildx"]
|
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "drone-docker-buildx"]
|
||||||
|
40
plugin/coredns.go
Normal file
40
plugin/coredns.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
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) {
|
||||||
|
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
|
||||||
|
}
|
@ -111,9 +111,29 @@ func (p *Plugin) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute provides the implementation of the plugin.
|
// Execute provides the implementation of the plugin.
|
||||||
|
//
|
||||||
|
//nolint:gocognit
|
||||||
func (p *Plugin) Execute() error {
|
func (p *Plugin) Execute() error {
|
||||||
// start the Docker daemon server
|
// start the Docker daemon server
|
||||||
|
//nolint: nestif
|
||||||
if !p.settings.Daemon.Disabled {
|
if !p.settings.Daemon.Disabled {
|
||||||
|
// If no custom DNS value set start internal DNS server
|
||||||
|
if len(p.settings.Daemon.DNS.Value()) == 0 {
|
||||||
|
ip, err := getContainerIP()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Warnf("error detecting IP address: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ip != "" {
|
||||||
|
logrus.Debugf("discovered IP address: %v", ip)
|
||||||
|
p.startCoredns()
|
||||||
|
|
||||||
|
if err := p.settings.Daemon.DNS.Set(ip); err != nil {
|
||||||
|
return fmt.Errorf("error setting daemon dns: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p.startDaemon()
|
p.startDaemon()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user