Using drone global networks aka DRONE_NETWORK

You mentioned in the latest release notes that DRONE_NETWORKS has been fixed I have setup an external in docker compose that brings up drone and selenium I have also set DRONE_NETWORK in my env to be selenium should all drone tests now have access to the containers on this network with no extra work ?

networks:
  selenium:
    external:
      name: selenium

Obviously my goal is to have selenium running permanently and be available to my tests, do I need to change anything in my drone.yaml files ?

Also this is not mentioned in the docs https://docs.drone.io/server/reference/

Declare DRONE_RUNNER_NETWORKS=selenium on the agent. You don’t need to add anything extra to your .drone.yml, just refer to the service on the selenium network by name.

That’s got me half way there, selenium now loads up a browser but does not seem to be able to resolve the drone services.

accessing react:3000 in a browser does not seem to get access to the drone containers.

Been doing a bit more digging, entering the drone or selenium container I can ping between drone and selenium I can not how ever ping any of the containers that drone has launched by name.

jumping inside a drone container I can ping selenium and other services, seems like the drone containers are not being registered on the selenium network.

Anyone got any ideas ?

Thinking about this a bit more it makes a bit more sense, guessing drone could never work like this because your test suites can be running more than once so the names would conflict, Guess you need to work out the current ip inside the container and pass that on to selenium.

anyone else work around something like this ?

so the crux of the problem is that drone with DRONE_RUNNER_NETWORKS connects a second interface so when you try and work out the ip you get the address for the first interface and not the second.

the drone tests can connect to the selenium server but because trying to resolves any of the hosts returns an ip on the first interface selenium is not on the same range and cant resolve.

Trying to find a way to resolve a hostname but get the ip from the other network currently.

When all else fails resort to hacky solutions :smiley:

In each container we can run this to dump all addresses into a file which we can then access and parse in the other containers.

- ip -o -4 addr show | awk -F '[ /]+' '/global/ {print "container-name-here " $2 " " $4}' >> interfaces.txt

You can then scan out the ip for a container using this command, specifying the interface.

- export SITE_DOMAIN=http://$(cat interfaces.txt | grep 'container-name-here eth1' | awk -F '[ ]' '{print $3}'):3000/

This is likely not deterministic as you have no idea what range is attached to which interface so eth0 and eth1 can switch.

will try and work a way around this but still open to better ideas, also any way you can get information about containers from with in a container or write a plugin that could get this kind of information ?

So final script which I have placed in my project for now.

NAME=$1
LOOKUP=$2
RANGE=$(getent ahostsv4 $LOOKUP | awk '{print $1}' | head -1 | awk -F '[.]' '{print $1 "." $2}')
IP=$(ip -o -4 addr show | awk -F '[ /]+' '/global/ {print $4}' | grep $RANGE)
OUTPUT="$NAME $IP"
echo $OUTPUT
echo $OUTPUT >> interfaces.txt

calling this in drone in this manner

- ./ipdb.sh "<<container-name>>" "<<service-like-selenium-on-seperate-network>>"

This will resolve the service to get an ip address knock of the last two octets and use the first two to grep out the matching ip for the current container and push <> matching ip into a file called interfaces.txt.

- export SITE_DOMAIN=http://$(cat interfaces.txt | grep '<<container-name>>' | awk -F '[ ]' '{print $2}'):3000/

you can then grep out the correct ip in other steps to use with services on external networks like selenium, would love a better solution but for now this work and solves the problem.

Curious if this could be made a plugin but likely it could not easily because you need to run the commands in each container to get the relevant details.