Skip to content

Commit

Permalink
netlib: next try
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommi2Day committed Aug 31, 2024
1 parent 77c7ad4 commit 6cc5558
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 9 additions & 23 deletions netlib/dns_docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,21 @@ 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) {
if os.Getenv("SKIP_DNS") != "" {
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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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])
Expand Down

0 comments on commit 6cc5558

Please sign in to comment.