4
votes

I have started a project based on Laravel 5.1. It is hosted at Gitlab and i want to use the Gitlab CI with this project ( https://gitlab.com/nasirkhan/laravel-5-starter ). My .gitlab-ci.yml setting is following. But the build is failing every time when it runs the command php artisan migrate:refresh, with the error,

[PDOException]
SQLSTATE[HY000] [2002] Connection refused

image: tetraweb/php:5.6-cli

services:
  - mysql

variables:
  WITH_XDEBUG: "1"
  MYSQL_ROOT_PASSWORD: secret
  MYSQL_DATABASE: homestead
  MYSQL_USER: homestead
  MYSQL_PASSWORD: secret
  COMPOSER_HOME: /cache/composer

stages:
  - test

php-5.6:
  type: test
  image: tetraweb/php:5.6-cli
  script:
    - docker-php-ext-enable zip
    - docker-php-ext-enable mbstring
    - docker-php-ext-enable pdo_mysql
    - php -v
    - composer self-update
    - composer install --no-progress --no-interaction
    - cp .env.example .env
    - sed -i.bak 's/DB_HOST=localhost/DB_HOST=mysql/g' .env
    - php artisan key:generate
    - php artisan migrate:refresh
    - php artisan db:seed
    - php vendor/bin/phpunit --colors --coverage-text
1
It's an sql connection error, stick some debug stuff into your script section. ping -c 3 mysql comes to mind. Then follow the trail. - Erik Dannenberg
added the command but the error log did not show anything. - nasirkhan

1 Answers

6
votes

the issue is resolved. the hostname should be mysql.

Gitlab CI build will be pass for the the following config,

first create a new .env.test with the following content

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_CONNECTION=mysql
DB_HOST=mysql
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

then the .gitlab-ci.yml should be like this,

image: tetraweb/php:5.6-cli

services:
  - mysql:latest

variables:
  WITH_XDEBUG: "1"
  MYSQL_ROOT_PASSWORD: secret
  MYSQL_DATABASE: homestead
  MYSQL_USER: homestead
  MYSQL_PASSWORD: secret
  COMPOSER_HOME: /cache/composer

stages:
  - test

php-5.6:
  type: test
  image: tetraweb/php:5.6-cli
  script:
    - docker-php-ext-enable zip
    - docker-php-ext-enable mbstring
    - docker-php-ext-enable pdo_mysql
    - ping -c 3 mysql
    - php -v
    - composer self-update
    - composer install --no-progress --no-interaction
    - cp .env.test .env
    - php artisan key:generate
    - php artisan migrate:refresh
    - php artisan db:seed
    - php vendor/bin/phpunit --colors --coverage-text