How to access a service from another service in Pipelines ?

Hi all,

I use a selenium grid to run end-to-end tests, so I use 3 services in BitBucket Pipelines :

  • selenium/hub
  • selenium/node-chrome
  • selenium/node-firefox

I understand that the hub service will be accessible at localhost:4444 from the main container, but what about the other service containers ?

I tried the following values for HUB_PORT_4444_TCP_ADDR:

  • localhost
  • hub

...without success.

The hub log show the following message :

Nodes should register to http://10.244.107.3:4444/grid/register/

Obviously I have no way to guess the dynamically attributed IP address of this service container. Maybe there is a secret environment variable ?

Here is the full content of my bitbucket-pipelines.yml for your viewing pleasure.

image: mrjoops/node:latest

pipelines:
  branches:
    feature/*:
      - step:
          caches:
            - node
          name: Run tests
          script:
            - make install
            - make SELENIUM_HOST=localhost test
          services:
            - chrome
            - firefox
            - hub
    hotfix/*:
      - step:
          caches:
            - node
          name: Run tests
          script:
            - make install
            - make SELENIUM_HOST=localhost test
          services:
            - chrome
            - firefox
            - hub
definitions:
  services:
    chrome:
      environment:
        HUB_PORT_4444_TCP_ADDR: hub
        HUB_PORT_4444_TCP_PORT: 4444
      image: selenium/node-chrome
    firefox:
      environment:
        HUB_PORT_4444_TCP_ADDR: hub
        HUB_PORT_4444_TCP_PORT: 4444
      image: selenium/node-firefox
    hub:
      image: selenium/hub

Note that I have a similar and working config with Docker Compose.

Thank you in advance for your answers.

2 answers

1 accepted

0 votes

Thanked to the Atlassian Support Team, I managed to solve the issue.

Here is a working services definition :

definitions:
  services:
    chrome:
      environment:
        HUB_PORT_4444_TCP_ADDR: localhost
        HUB_PORT_4444_TCP_PORT: 4444
      image: selenium/node-chrome
    firefox:
      environment:
        DISPLAY: :88
        HUB_PORT_4444_TCP_ADDR: localhost
        HUB_PORT_4444_TCP_PORT: 4444
        SE_OPTS: -port 5556
      image: selenium/node-firefox
    hub:
      environment:
        SE_OPTS: -host 127.0.0.1
      image: selenium/hub

In short you have to tell Selenium to run on localhost (and use the SE_OPTS env var for hub), and since everything run on localhost in BitBucket Pipelines, you have to ensure there aren't any port conflict between the services (and map either chrome or firefox on different ports).

That said, this leads to a configuration where you only have 1Gb per service, and dockerized Firefox have known issues regarding "low" memory management (I have to run docker with shm_size: 2g for FF to work), so I couldn't run my E2E tests on both browsers : Firefox dies silently shortly after beginning the test suite.

Hopefully the memory issue in Firefox will be solved one day (:fingers_crossed:) and this configuration will work !

0 votes

I understand that the hub service will be accessible at localhost:4444 from the main container, but what about the other service containers ?

You need to use localhost as well for these, so in your bitbucket-pipelines.yml

environment:
        HUB_PORT_4444_TCP_ADDR: hub
        HUB_PORT_4444_TCP_PORT: 4444

should be

environment:
        HUB_PORT_4444_TCP_ADDR: localhost
        HUB_PORT_4444_TCP_PORT: 4444 

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

651 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot