Can't setup Gitlab-ci with a symfony project

Hello everybody,

I’m trying to configure Gitlab-ci with a Symfony project, and after reading the documentation and some examples in external blogs I’m unable to complete the setup. I asked in StackOverflow without any working solution. Those are my files:

.gitlab-ci.yml:

# Select image from https://hub.docker.com/_/php/
image: php:5.6
# Select what we should cache
cache:
  paths:
  - vendor/

before_script:
# Install git, the php image doesn't have installed
- apt-get update -yqq
- apt-get install git -yqq
- apt-get install wget -yqq
- apt-get install zip unzip zlib1g-dev -yqq

# Install mysql driver & zip
- docker-php-ext-install pdo_mysql
- docker-php-ext-install zip
- docker-php-ext-install mbstring

# Install composer
- curl -sS https://getcomposer.org/installer | php

# Install all project dependencies
- mv app/config/parameters.gitlab.yml app/config/parameters.yml.dist
- ping -c 3 mysql
- php -v
- php composer.phar clear-cache
- php composer.phar install
- php bin/console doctrine:schema:create

services:
- mysql:latest

variables:
  # Configure mysql service (https://hub.docker.com/_/mysql/)
  MYSQL_DATABASE: symfony
  MYSQL_ROOT_PASSWORD: password

# We test PHP5.6 (the default) with MySQL
test:mysql:
  script:
  - vendor/bin/phpunit --configuration phpunit.xml --coverage-text

parameters.gitlab.yml (which becomes parameters.yml.dist)

# This file is auto-generated during the composer install
parameters:
    database_driver: pdo_mysql
    database_host: mysql
    database_port: 3306
    database_name: symfony
    database_user: root
    database_password: password

I have tried mysql user root, and another user using ‘MYSQL_USER’ variable. The result is always the same:

$ mv app/config/parameters.gitlab.yml app/config/parameters.yml.dist
$ ping -c 3 mysql
PING mysql (172.17.0.2): 56 data bytes
64 bytes from 172.17.0.2: icmp_seq=0 ttl=64 time=0.282 ms
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.140 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.151 ms
--- mysql ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.140/0.191/0.282/0.065 ms
$ php -v
PHP 5.6.26 (cli) (built: Sep 23 2016 21:22:39) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
$ php composer.phar clear-cache
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Clearing cache (cache-dir): /root/.composer/cache
Clearing cache (cache-files-dir): /root/.composer/cache/files
Clearing cache (cache-repo-dir): /root/.composer/cache/repo
Cache directory does not exist (cache-vcs-dir): 
All caches cleared.
$ php composer.phar install
......
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

  [Doctrine\DBAL\Exception\ConnectionException]                              
  An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused  
                                         
  [Doctrine\DBAL\Driver\PDOException]        
  SQLSTATE[HY000] [2002] Connection refused  
                                         
  [PDOException]                             
  SQLSTATE[HY000] [2002] Connection refused  

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception

What am I doing wrong or missing?

What is with the pdo_mysql extension in php? May you have to change the php.ini!

This sounds more like a Symfony problem:

  1. Are you sure everything is running in the correct environment? Your tests are probably running in the test environment, while the clearCache method may be executed for the dev environment.

  2. Do all Symfony environments rely on parameters.yml? Many setups use parameters.yml only for the prod environment and have different values for the test and dev env.

  3. Try moving parameters.gitlab.yml directly to parameters.yml (instead of ...yml.dist). I had a similar situation where “updating” and “using” parameters.yml in the same composer install cycle did not work (this was not related to gitlab though).

1 Like

Great! That was the problem. I was updating parameters.yml, but I forgot that composer install was using dev environment, and I had a parameters_dev.yml there. I copied parameters.gitlab.yml over parameters_dev.yml and now it’s connecting and executing tests. Thanks a lot!