Gitlab CI PHP App

Hi,

I’m trying to run end to end integrated tests with a PHP application using nginx. I’ve created a .gitlab-ci.yml that uses the richarvey/nginx-php-fpm image from Docker Hub as a starting point.

When I run this docker image using docker, it starts nginx and fpm on startup, and is listening on port 80.

However, when running within Gitlab CI, neither of those services are running.

My .gitlab-ci.yml file is as follows:

image: richarvey/nginx-php-fpm

before_script:
  # install ssh-agent
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  # run ssh-agent
  - eval $(ssh-agent -s)
  - echo "SSH_PRIVATE_KEY"
  - echo "$SSH_PRIVATE_KEY"
  # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  # disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks)
  # WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config
  - mkdir -p ~/.ssh
  - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

  # Composer update and deploy into php location
  - composer install --no-scripts

stages:
  - test

test:
  script:
    - whoami
    - pwd
    - ls -al /var/www/
    - ls -al /var/www/html
    - netstat -l
    - ps
    - php --version
    - curl "http://localhost/"

The netstat -l command when running in Gitlab CI gives the following output:
$ netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 35333 /tmp/ssh-6Rr12pCsnv9w/agent.9

whereas when I run it through standard docker locally, it outputs:
bash-4.3# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:http 0.0.0.0:* LISTEN
tcp 0 0 :::http :::* LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 28390 /var/run/php-fpm.sock
unix 2 [ ACC ] STREAM LISTENING 29885 /dev/shm/supervisor.sock.1

Any ideas? How do I get the nginx running in order to do some end-to-end testing of the app. I’ve found lots of examples using phpunit and gitlab ci but none on actually running the PHP app, and testing it over HTTP (All of my end to end integration tests are written in NodeJS using Chakram).

Cheers,
Michael.

I’ve managed to add a workaround to my .gitlab-ci.yml file to make this work - if I add these two lines to the top of my script, then it works:

test:
  script:
    - /start.sh &
    - sleep 2
    - ... 

For some reason, when running the Docker image using gitlab-ci-multi-runner, it doesn’t seem to be executing the last line of the Dockerfile: