代码之家  ›  专栏  ›  技术社区  ›  Tobias Gaertner

使用服务:gitlab ci中mysql的codecption测试失败,显示“连接被拒绝”

  •  1
  • Tobias Gaertner  · 技术社区  · 6 年前

    我有一个带codeception插件的CakePHP应用程序用于测试 在本地,我在ddev docker环境中运行它,一切正常。

    Running with gitlab-runner 11.1.0 (081978aa)
      on shared runner 601c0f11
    Using Docker executor with image kevinliteon/cakephp:php7 ...
    Starting service mysql:latest ...
    Pulling docker image mysql:latest ...
    Using docker image sha256:6a834f03bd02bb88cdbe0e289b9cd6056f1d42fa94792c524b4fddc474dab628 for mysql:latest ...
    Waiting for services to be up and running...
    
    *** WARNING: Service runner-601c0f11-project-94-concurrent-0-mysql-0 probably didn't start properly.
    
    Health check error:
    service "runner-601c0f11-project-94-concurrent-0-mysql-0-wait-for-service" timeout
    
    Health check container logs:
    
    
    Service container logs:
    2018-10-04T12:12:18.904025613Z Initializing database
    2018-10-04T12:12:18.925096235Z 2018-10-04T12:12:18.919745Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
    2018-10-04T12:12:18.925195518Z 2018-10-04T12:12:18.919970Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.12) initializing of server in progress as process 30
    2018-10-04T12:12:50.330736417Z 2018-10-04T12:12:50.330487Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    
    *********
    
    Pulling docker image kevinliteon/cakephp:php7 ...
    Using docker image sha256:bd4a83b02647ad93a356b343d2ce5ae3a9a1177aea2cd76c61b009abc7df8990 for kevinliteon/cakephp:php7 ...
    Running on runner-601c0f11-project-94-concurrent-0 via d7f4a5e71b47...
    Fetching changes...
    Removing vendor/
    HEAD is now at 92cb022 test
    Checking out 92cb0223 as deployment...
    Skipping Git submodules setup
    Checking cache for default...
    Successfully extracted cache
    $ vendor/bin/codecept run Unit
    Codeception PHP Testing Framework v2.3.9
    Powered by PHPUnit 6.5.13 by Sebastian Bergmann and contributors.
    
    In Db.php line 308:
    
      Db: SQLSTATE[HY000] [2002] Connection refused while creating PDO connection  
    

    我的gitlab-ci.yml(部分):

    services:
    - mysql:latest
    
    variables:
      MYSQL_ROOT_PASSWORD: mysql123456789
      MYSQL_DATABASE: test_db
      MYSQL_USER: db
      MYSQL_PASSWORD: db
    
    build:
      ...
    
    codecept:Unit:
      stage: test
      script:
      - vendor/bin/codecept run Unit
    

    modules:
        config:
            Db:
                dsn: 'mysql:host=mysql;dbname=test_db'
                user: 'db'
                password: 'db'
                cleanup: true # reload dump between tests
                populate: true # load dump before all tests
                reconnect: true
    

    我也尝试使用根用户-没有成功。

    问题是,无论什么原因,我都无法连接到数据库。。。也许初始化服务容器时的警告与此有关,但我无法确定如何修复它们,或者这是否是问题所在。

    我真的尝试了很多事情都没有成功!基本上,我的代码依赖于gitlab ci和codeeption的文档,所以应该可以工作。

    有人成功地实现了这个场景,或者知道我做错了什么?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Tobias Gaertner    6 年前

    我想回答我是怎么解决的: 首先,我必须添加env varible“db_dsn”,如下所示:

    export db_dsn="mysql://user:paswd@host/db"
    

    然后我仍然得到健康检查错误。我发现成功安装的唯一方法是为db服务使用另一个docker映像。我选择了“mariadb:最新”-然后它对我有效。