How to configure Nomad job for Selenium Grid

387 views Asked by At

I'm trying to setup a Selenium Grid in Hashicorp Nomad but I don't know how to make the networking work. What I want is to have one selenium-hub and 8 chrome-nodes. I found that I can only have multiple allocations of the node-task if I put the node-task into its own group.

Running it locally, I would start the grid like this:

docker network create grid
docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:4
docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -v /dev/shm:/dev/shm selenium/node-chrome:4
docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -v /dev/shm:/dev/shm selenium/node-chrome:4
...

How do I need to configure Network for this to work?

My current job looks like this:

job "selenium" {
  datacenters = ["dc1"]
  type = "service"
  group "selenium_hub" {
    network {

    }
    task "selenium_hub" {
      driver = "docker"
      config {
        image = "selenium/hub:4"
      }
    }
  }
  group "selenium_nodes" {
    count = 8
    network {

    }
    task "selenium_node" {
      driver = "docker"
      env {
        SE_EVENT_BUS_HOST = "selenium-hub"
        SE_EVENT_BUS_PUBLISH_PORT = "4442"
        SE_EVENT_BUS_SUBSCRIBE_PORT = "4443"
      }
      config {
        image = "selenium/node-chrome:4"
      }
    }
  }  
}
1

There are 1 answers

0
Reikhard On

If anyone comes across this, I've got it working like this:

job "selenium" { 
  datacenters = ["dc1"]
  type = "service"
  group "selenium_hub" {
    network {
      mode = "host"
    }
    task "selenium_hub" {
      driver = "docker"
      config {
        image = "selenium/hub:3.141.59-20201010"
        network_mode = "host"
      }
    }
  }
  group "selenium_nodes" {
    count = 8
    network {
        mode = "host"
        port "http" {}
    }
    task "selenium_node" {
      driver = "docker"
      env {
        HUB_HOST = "localhost"
        SE_OPTS = "-port ${NOMAD_PORT_http}"
      }
      config {
        network_mode = "host"
        image = "selenium/node-chrome:3.141.59-20201010"
      }
    }
  }  
}

I used Selenium 3 instead of 4 because we also had other issues with 4. Since I've used host network and all nodes use the port 5555 I needed to pass a dynamic port (http) to Selenium via SE_OPTS environment variable.