From 6cc5558d4f87c61e40973c5953ed7c4a3f74db6d Mon Sep 17 00:00:00 2001 From: Tommi2Day Date: Sat, 31 Aug 2024 17:33:30 +0200 Subject: [PATCH] netlib: next try --- .github/workflows/main.yml | 3 ++- netlib/dns_docker_test.go | 32 +++++++++----------------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3270c2b..25468ba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,8 @@ on: [push] # SKIP_COMMIT: true jobs: test: - runs-on: ubuntu-22.04 + #runs-on: ubuntu-22.04 + runs-on: ubuntu-latest services: docker: image: docker:dind diff --git a/netlib/dns_docker_test.go b/netlib/dns_docker_test.go index 52b59b5..6cd412e 100644 --- a/netlib/dns_docker_test.go +++ b/netlib/dns_docker_test.go @@ -19,16 +19,14 @@ const netlibNetworkName = "netlib-dns" const netlibNetworkPrefix = "172.25.0" const netlibDomain = "netlib.lan" const netlibTestAddr = tDB -const netlibRepoTag = "9.20" +const netlibRepoTag = "9.18" var netlibDNSContainerName string var netlibDNSContainer *dockertest.Resource var netlibDNSNetwork *dockertest.Network var netlibDNSNetworkCreated = false -var netlibDNSServer = "127.0.0.1" - -const netlibDNSPort = 9053 -const netlibDNSSecPort = 9953 +var netlibDNSServer = "" +var netlibDNSPort = 0 // prepareNetlibDNSContainer create a Bind9 Docker Container func prepareNetlibDNSContainer() (container *dockertest.Resource, err error) { @@ -36,11 +34,6 @@ func prepareNetlibDNSContainer() (container *dockertest.Resource, err error) { err = fmt.Errorf("skipping DNS Container in CI environment") return } - // align hostname in CI - host := os.Getenv("DNS_HOST") - if host != "" { - netlibDNSServer = host - } netlibDNSContainerName = os.Getenv("DNS_CONTAINER_NAME") if netlibDNSContainerName == "" { netlibDNSContainerName = "netlib-bind9" @@ -99,17 +92,6 @@ func prepareNetlibDNSContainer() (container *dockertest.Resource, err error) { Name: netlibDNSContainerName, Networks: []*dockertest.Network{netlibDNSNetwork}, ExposedPorts: []string{"53/tcp", "53/udp", "953/tcp"}, - PortBindings: map[docker.Port][]docker.PortBinding{ - "53/tcp": { - {HostIP: "0.0.0.0", HostPort: fmt.Sprintf("%d/tcp", netlibDNSPort)}, - }, - "53/udp": { - {HostIP: "0.0.0.0", HostPort: fmt.Sprintf("%d/udp", netlibDNSPort)}, - }, - "953/tcp": { - {HostIP: "0.0.0.0", HostPort: fmt.Sprintf("%d/tcp", netlibDNSSecPort)}, - }, - }, }, func(config *docker.HostConfig) { // set AutoRemove to true so that stopped container goes away by itself config.AutoRemove = true @@ -127,6 +109,11 @@ func prepareNetlibDNSContainer() (container *dockertest.Resource, err error) { return } pool.MaxWait = netlibDNSContainerTimeout * time.Second + netlibDNSServer, netlibDNSPort = common.GetContainerHostAndPort(container, "53/tcp") + if netlibDNSPort == 0 || netlibDNSServer == "" { + err = fmt.Errorf("could not get host/port of dns container") + return + } fmt.Printf("Wait to successfully connect to DNS to %s:%d (max %ds)...\n", netlibDNSServer, netlibDNSPort, netlibDNSContainerTimeout) start := time.Now() var c net.Conn @@ -153,8 +140,7 @@ func prepareNetlibDNSContainer() (container *dockertest.Resource, err error) { dns := NewResolver(netlibDNSServer, netlibDNSPort, true) ips, e := dns.Resolver.LookupHost(context.Background(), netlibTestAddr) if e != nil || len(ips) == 0 { - err = fmt.Errorf("could not resolve DNS for %s on %s:%d: %v", netlibTestAddr, netlibDNSServer, netlibDNSPort, e) - destroyDNSContainer(container) + fmt.Printf("Could not resolve DNS for %s on %s:%d: %v", netlibTestAddr, netlibDNSServer, netlibDNSPort, e) return } fmt.Println("DNS Container is ready, host", netlibTestAddr, "resolved to", ips[0])