Closed theriseofendymion closed 4 years ago
Can you share your full CI config? It's either an issue within Docker or a typo in the network/host settings, perhaps?
This is my .gitlab-ci.yml:
stages:
- preparation
- building
- testing
- security
image: edbizarro/gitlab-ci-pipeline-php:7.3
variables:
MYSQL_ROOT_PASSWORD: ''
MYSQL_USER: root
MYSQL_PASSWORD: ''
MYSQL_DATABASE: laravel
DB_HOST: 'mysql:8.0'
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
composer:
stage: preparation
script:
- php -v
- composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
- cp .env.example .env
- php artisan key:generate
artifacts:
paths:
- vendor/
- .env
expire_in: 1 days
when: always
cache:
paths:
- vendor/
yarn:
stage: preparation
script:
- yarn --version
- yarn install --pure-lockfile
artifacts:
paths:
- node_modules/
expire_in: 1 days
when: always
cache:
paths:
- node_modules/
build-assets:
stage: building
dependencies:
- composer
- yarn
script:
- yarn --version
- yarn run production --progress false
artifacts:
paths:
- public/css/
- public/js/
- public/fonts/
- public/mix-manifest.json
expire_in: 1 days
when: always
db-seeding:
stage: building
services:
- name: mysql:8.0
command: ["--default-authentication-plugin=mysql_native_password"]
alias: mysql
dependencies:
- composer
- yarn
script:
- mysql --version
- php artisan migrate:fresh --seed
- mysqldump --host="${DB_HOST}" --user="${MYSQL_USER}" --password="${MYSQL_PASSWORD}" "${MYSQL_DATABASE}" > db.sql
artifacts:
paths:
- storage/logs # for debugging
- db.sql
expire_in: 1 days
when: always
phpunit:
stage: testing
services:
- name: mysql:8.0
command: ["--default-authentication-plugin=mysql_native_password"]
alias: mysql
dependencies:
- build-assets
- composer
- db-seeding
script:
- php -v
- sudo cp /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.bak
- echo "" | sudo tee /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- mysql --host="${DB_HOST}" --user="${MYSQL_USER}" --password="${MYSQL_PASSWORD}" "${MYSQL_DATABASE}" < db.sql
- ./vendor/phpunit/phpunit/phpunit --version
- php -d short_open_tag=off ./vendor/phpunit/phpunit/phpunit -v --colors=never --stderr
- sudo cp /usr/local/etc/php/conf.d/docker-php-ext-xdebug.bak /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
artifacts:
paths:
- ./storage/logs # for debugging
expire_in: 1 days
when: on_failure
codestyle:
stage: testing
image: lorisleiva/laravel-docker
script:
- phpcs --extensions=php app
dependencies: []
phpcpd:
stage: testing
script:
- test -f phpcpd.phar || curl -L https://phar.phpunit.de/phpcpd.phar -o phpcpd.phar
- php phpcpd.phar app/ --min-lines=50
dependencies: []
cache:
paths:
- phpcpd.phar
sensiolabs:
stage: security
script:
- test -d security-checker || git clone https://github.com/sensiolabs/security-checker.git
- cd security-checker
- composer install
- php security-checker security:check ../composer.lock
dependencies: []
cache:
paths:
- security-checker/
This seems wrong: DB_HOST: 'mysql:8.0'
This should be DB_HOST: mysql
as it refers to the hostname mysql
, I believe you're targetting a specific container version which doesn't belong there.
It was actually my fault to paste that config, I was just trying, the real one is this:
stages:
image: edbizarro/gitlab-ci-pipeline-php:7.3
variables: MYSQL_ROOT_PASSWORD: '' MYSQL_USER: root MYSQL_PASSWORD: '' MYSQL_DATABASE: laravel DB_HOST: 'mysql'
cache: key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
composer: stage: preparation script:
yarn: stage: preparation script:
build-assets: stage: building dependencies:
db-seeding: stage: building services:
phpunit: stage: testing services:
codestyle: stage: testing image: lorisleiva/laravel-docker script:
phpcpd: stage: testing script:
sensiolabs: stage: security script:
Getting
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
runningphp artisan migrate:fresh --seed
. That's strange cause I'm using the container service name as host. Any idea?