Skip to content

Instantly share code, notes, and snippets.

@mackensen
Created November 14, 2016 15:49
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mackensen/c0b53d55667f8975d59fbb7ccaa2c2c3 to your computer and use it in GitHub Desktop.
Save mackensen/c0b53d55667f8975d59fbb7ccaa2c2c3 to your computer and use it in GitHub Desktop.
Mocked up gitlab config for running selenium in a linked container
# Custom docker image which exposes 8080
image: lafayette/hoth:5.5
services:
- selenium/standalone-chrome:latest
before_script:
# Use 0.0.0.0 instead of localhost to allow external connections
- php -S 0.0.0.0:8080 -t ../ &> /dev/null &
job1:
script:
# Detect the IP and tell behat about it
- export BEHAT_IP=`ip addr show eth0 | grep -Po 'inet \K[\d.]+'`
- sed -i -e "s/localhost/$BEHAT_IP/" behat.yml
- vendor/bin/behat --format progress
default:
autoload:
- %paths.base%/features/bootstrap
suites:
default:
contexts:
- YourContextHere
extensions:
Behat\MinkExtension:
base_url: 'http://localhost:8080'
browser_name: 'chrome'
sessions:
default:
selenium2:
wd_host: 'http://selenium__standalone-chrome:4444/wd/hub'
@stepansib
Copy link

Thank you! Tired to wait when they will create normal docker network for CI containers and services...

@quicksketch
Copy link

Another thank you! This was VERY tricky to figure out! GitLab's magic networking is definitely making things more difficult here. Two additional things I needed to get this working:

  • Instead of ip addr show eth0 | grep -Po 'inet \K[\d.]+' I used hostname -I | awk '{print $1}' because iproute2 is not installed on default PHP images.
  • I also had proxy servers in my environment. I had to add the IP address to the NO_PROXY variable.

Resulting in the following additions to the script section:

    - export LOCAL_IP_ADDRESS=`hostname -I | awk '{print $1}'`
    - export NO_PROXY=localhost,$LOCAL_IP_ADDRESS
    - sed -i -e "s/localhost/$LOCAL_IP_ADDRESS/" behat.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment