4

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
3
  • 2
    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. Commented Apr 7, 2016 at 17:31
  • added the command but the error log did not show anything. Commented Apr 8, 2016 at 6:22
  • gitlab.com/nasirkhan/laravel-5-starter/builds/1027449 Commented Apr 8, 2016 at 6:51

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.