Carles
Carles

Reputation: 160

Can't setup Gitlab-ci with a symfony project

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. 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?

Upvotes: 0

Views: 2293

Answers (1)

Carles
Carles

Reputation: 160

The problem was in dev environment, as tackerm told me in Gitlab forum. I was using a parameters_dev.yml file on dev environment, and composer install was reading that file instead of parameters.yml as I thought. Changing database settings in parameters_dev.yml solves the error and now Gitlab is connecting and executing tests.

Upvotes: 2

Related Questions