我已经开始了一个基于Laravel 5.1的项目。它在Gitlab上托管,我想在这个项目中使用Gitlab CI(https://gitlab.com/nasirkhan/laravel-5-starter)。我的.gitlab-ci.yml
设置如下。但是每次运行命令php artisan migrate:refresh
时,构建都会失败,并显示错误
[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
答案 0 :(得分:4)
问题已解决。 hostname
应为mysql
。
Gitlab CI构建将通过以下配置,
首先使用以下内容创建新的.env.test
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
然后.gitlab-ci.yml
应该是这样的,
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