Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php_network_getaddresses Name or service not know #21

Closed
chinleung opened this issue Jul 3, 2018 · 23 comments
Closed

php_network_getaddresses Name or service not know #21

chinleung opened this issue Jul 3, 2018 · 23 comments

Comments

@chinleung
Copy link

I've taken the files from the example and it keeps giving me this:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name o  
  r service not known

Here's the .gitlab-ci

stages:
  - build
  - test

# Variables
variables:
  MYSQL_ROOT_PASSWORD: root
  MYSQL_USER: root
  MYSQL_PASSWORD: secret
  MYSQL_DATABASE: test
  DB_HOST: mysql
  DB_CONNECTION: mysql

build:
  stage: build
  services:
     - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
    # - npm install # if you need to install additional modules from your projects package.json
    # - npm run dev # if you need to run dev scripts for example laravel mix 
  cache:
      key: ${CI_BUILD_REF_NAME}
      paths:
        # these are only examples, you should modify them according to your project, 
        # or remove cache routines entirely, if they are causing any problems on your next builds..
        # below are 2 safe ones if you use composer install and npm install in your stage script
        - vendor
        - node_modules
         # - /resources/assets/vendors  # for example if you put your vendor node-libraries there

test:
  stage: test
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
    policy: pull
    
  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
    - cp .env.example .env
    # - cp phpunit.xml.ci phpunit.xml # if you are using custom config for your phpunit tests in CI
    - configure-laravel
    - start-nginx-ci-project
    - ./vendor/phpunit/phpunit/phpunit -v --coverage-text --colors --stderr
    # - phpunit -v --coverage-text --colors --stderr # if you want to use preinstalled phpunit
    - php artisan dusk --colors --debug

  artifacts:
    paths:
      - ./storage/logs # for debugging
      - ./tests/Browser/screenshots
      - ./tests/Browser/console
    expire_in: 7 days
    when: always

And my .env.example:

APP_NAME="Testing"
APP_ENV=testing
APP_DEBUG=true
APP_URL=http://localhost
APP_KEY=

DB_HOST=mysql
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=secret

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
MAIL_DRIVER=log
@chilio
Copy link
Owner

chilio commented Jul 3, 2018

@chinleung what versions of gitlab, docker and gitlab-runner are you using?
After which command the error is displayed?
It seems like some problem with underlying docker, cause it means that testing image could not connect to mysql docker instance.
Is mysql properly downloaded and started in gitlab pipeline logs?

@chinleung
Copy link
Author

chinleung commented Jul 5, 2018

@chilio In the GitLab admin, it says the runner is on version 10.4.0 but when I execute gitlab-runner --version on the server, I get the following:

Version:      11.0.0
Git revision: 5396d320
Git branch:   11-0-stable
GO version:   go1.8.7
Built:        2018-06-22T11:03:37+00:00
OS/Arch:      linux/amd64

I see the following in the logs during both the build and the test stage:

Using Docker executor with image chilio/laravel-dusk-ci:stable ...
Starting service mysql:5.7 ...
Pulling docker image mysql:5.7 ...
Using docker image mysql:5.7 ID=sha256:66bc0f66b7af6ba3ea96582685d3afcd6dff93c2f8999da0ffadd67b280db548 for mysql service...
Waiting for services to be up and running...

*** WARNING: Service runner-689f83b9-project-23-concurrent-0-mysql-0 probably didn't start properly.

I'm not too familiar with Docker. Do you have any idea how to fix this?

@chilio
Copy link
Owner

chilio commented Jul 5, 2018

@chinleung Your problem is in this line:
*** WARNING: Service runner-689f83b9-project-23-concurrent-0-mysql-0 probably didn't start properly.
Which means that docker has problem running mysql instance.
Therefore throwed error: SQLSTATE[HY000] [2002] php_network_getaddresses: makes sense.

There could be several problems, but for sure you need to check your docker installation (sometimes it can be something as silly as low space, mem, etc.)

First I would try to run mysql manually and make sure it works... Some more info here...

@chinleung
Copy link
Author

@chilio Yeah that's what I thought too. Thanks I'll have a look on why it's not starting properly. I'll post back here once I find the solution for anyone with the same issue.

@chilio
Copy link
Owner

chilio commented Jul 11, 2018

@chinleung did you succeeded with this issue?

@chinleung
Copy link
Author

@chilio No I am still working on it. I've tried multiple things like these guides:

I've also tried to enable the privileged to the docker container but I'm still unable to start the SQL service.

Using Docker executor with image chilio/laravel-dusk-ci:stable ...
Starting service mysql:5.7 ...
Pulling docker image mysql:5.7 ...
Using docker image sha256:66bc0f66b7af6ba3ea96582685d3afcd6dff93c2f8999da0ffadd67b280db548 for mysql:5.7 ...
Waiting for services to be up and running...

*** WARNING: Service runner-237f18d2-project-23-concurrent-0-mysql-0 probably didn't start properly.

Health check error:
ContainerStart: Error response from daemon: Cannot link to a non running container: /runner-237f18d2-project-23-concurrent-0-mysql-0 AS /runner-237f18d2-project-23-concurrent-0-mysql-0-wait-for-service/service

Service container logs:
2018-07-11T19:49:03.214991318Z 
2018-07-11T19:49:03.215062485Z ERROR: mysqld failed while attempting to check config
2018-07-11T19:49:03.215067480Z command was: "mysqld --verbose --help"
2018-07-11T19:49:03.215070774Z 
2018-07-11T19:49:03.215073778Z mysqld: error while loading shared libraries: libpthread.so.0: cannot stat shared object: Permission denied

@chilio
Copy link
Owner

chilio commented Jul 16, 2018

@chinleung My advice is you should not dig dipper, with gitlab....

I believe this is a problem with your underlying infrastructure (probably docker).

I have experienced this error only once, and it was when my test system was overloaded...

So please make sure you can run docker mysql instance without any issues....

@chinleung
Copy link
Author

@chilio I think that's the issue, I'm not able to run mysql properly with docker but I can't figure out why... Any ideas?

@chilio
Copy link
Owner

chilio commented Jul 17, 2018

@chinleung I would try to reinstall docker on your system, have you tried that?
And check if you don't have mysql installed on your host system. Here is more info

@chinleung
Copy link
Author

@chilio Oh wait, I can't have MySQL on my host machine?

@chilio
Copy link
Owner

chilio commented Jul 18, 2018

@chinleung I've never tried it, but I have seen that others had some problems with that...
Please check this issue also...

@ghost
Copy link

ghost commented Jul 20, 2018

@chinleung By using services: -mysql:5.7. This kind of structure is automatically created

image

So everything is a docker container and you don't have to manage your mysql VM/container or even the service on your host by yourself.

By using

variables:
  MYSQL_ROOT_PASSWORD: root
  MYSQL_USER: root
  MYSQL_PASSWORD: secret
  MYSQL_DATABASE: test
  DB_HOST: mysql
  DB_CONNECTION: mysql

The database is already created with the credentials and @chilio made a little script to make your life easier by using

script:
    - configure-laravel

Your laravel env will be setup and your database will be created and seeded (Idon't know if this word exist)

You can have a look here to see what this command is really doing.

I hope it will help you to debug or at least to have a better understanding of the workflow.

@chilio
Copy link
Owner

chilio commented Jul 22, 2018

@chinleung any updates on this?

@chinleung
Copy link
Author

Oh sorry I didn't see @Raccoon5031 's message. So basically it won't work if I have MySQL on my main host. The thing is, I'm using the main host to serve websites, therefore I need the MySQL service running.

@chilio It's not really a fix to the issue, but I realized, I don't even need to install MySQL in my docker because I don't use it all during the tests.

@chilio
Copy link
Owner

chilio commented Jul 23, 2018

@chinleung if so you can modify .gitlab-ci.yml to use alias for example:

services:
    - name: mysql:5.7
      alias: mysql-test

and then in variables section:

variables:
  ...
  DB_HOST: mysql-test

This should work without a problem.
Please check and let me know if it works....

@chinleung
Copy link
Author

I simply removed the mysql from the services completely and it's working. 👍

@chilio
Copy link
Owner

chilio commented Jul 23, 2018

@chinleung I know, but could you check this solution?
So you can have it working where you will use mysql in tests also?

@chinleung
Copy link
Author

@chilio Okay sure, I'll test it and get back to you in like ±3 hours. I don't have access to my laptop right now. Do you want me to add the alias to both stages?

@chilio
Copy link
Owner

chilio commented Jul 23, 2018

@chinleung yes please do, everywhere where you reference mysql in services:...

@chinleung
Copy link
Author

@chilio Yes adding an alias seems to be working!

@chilio
Copy link
Owner

chilio commented Jul 24, 2018

@chinleung I'm glad to hear that...

@chilio chilio closed this as completed Jul 24, 2018
@scofield-ua
Copy link

@chilio received same error today on the shared runner. Maybe alias for MySQL service should be set by default in example .gitlab-ci.yml file?

@chilio
Copy link
Owner

chilio commented Dec 7, 2018

@scofield-ua thanks for the tip.
Readme and .gitlab-ci.yml updated...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants