gitlab ci dusk-mysql连接被拒绝

k3fezbri  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(382)

这个问题问了好几次,但我尝试了所有的解决方案,我发现并有一个运行“正常”phpunit测试与类似的设置,所以不是我做的每件事都可能是错误的。
问题是:
我知道,与gitlab ci和docker一起出现此问题的主要原因(仅报告?)是使用了错误的主机。在几乎所有情况下,op都会尝试某种本地主机来访问db。
这里不能这样因为 DB_HOST 在我的 variables , DB_HOST 在我的 .env 文件和mysql服务的别名都是一样的。
我甚至钩入容器(通过添加 sleep 1h 就在黄昏前指挥并做一个 docker exec )并成功地登录到我的数据库,并看到迁移和种子表。小叮当也能锻炼。
唯一的问题是黄昏。
有趣的事实:抛弃我的 DB_HOST 给予 mysql-test (我做了一个 config:clear 在运行黄昏之前,甚至把它添加到我的 setUp 功能。
我真的没什么主意了,希望能从人群中得到一些主意。
这是我的.yml文件

stages:
- build
- test  

variables:
  DB_HOST: mysql-test
  MYSQL_DATABASE: laravel
  MYSQL_ROOT_PASSWORD: secret
  DB_CONNECTION: mysql

composer:
  image: lorisleiva/laravel-docker:latest
  stage: build
  script:
  - composer install --no-progress --no-interaction
  - cp .env.gitlab-testing .env
  - php artisan key:generate
  artifacts:
    paths:
    - vendor/
    - bootstrap/
    - .env
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - vendor/
  tags:
  - docker

npm:
  image: lorisleiva/laravel-docker:latest
  stage: build
  script:
  - npm install
  - npm run prod
  artifacts:
    paths:
    - public/mix-manifest.json
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - node_modules/
  tags:
  - docker  

dusk:
  stage: test
  dependencies:
  - composer
  - npm
  tags:
  - docker
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - vendor
    - node_modules
    policy: pull

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

  image: chilio/laravel-dusk-ci:latest
  script:
  - cp .env.dusk.gitlab-testing .env
  - cp phpunit.dusk.xml phpunit.xml 
  - configure-laravel
  - start-nginx-ci-project
  - php artisan dusk --colors --debug

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

.env.dusk.gitlab-测试

APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

LOG_CHANNEL=stack
HEADLESS=true

DB_CONNECTION=mysql
DB_HOST=mysql-test
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync

phpunit.dusk.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Browser Tests">
            <directory suffix="Test.php">./tests/Browser</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="local"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>
8gsdolmq

8gsdolmq1#

它现在确实起作用了。
以下是我的文件现在的样子:
.env.dusk.gitlab-测试:

APP_ENV=local
APP_KEY=base64:WY4y4XWUAKbCPzf8XqC92z5wWMn7oOHXZMFMbg9al3E=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=mysql-test
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync

.gitlab-ci.yml公司

stages:
- build
- test
- deploy

# Variables

variables:
  DB_HOST: mysql-test
  MYSQL_DATABASE: laravel
  MYSQL_USER: laravel
  MYSQL_PASSWORD: secret
  MYSQL_ROOT_PASSWORD: secretroot
  DB_CONNECTION: mysql

composer:
  image: lorisleiva/laravel-docker:latest
  stage: build
  script:
  - cp .env.gitlab-testing .env
  - composer install --no-progress --no-interaction
  - php artisan key:generate
  artifacts:
    paths:
    - vendor/
    - bootstrap/
    - .env
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - vendor/
    - bootstrap/
  tags:
  - docker

npm:
  image: lorisleiva/laravel-docker:latest
  stage: build
  script:
  - npm install
  - npm run prod
  artifacts:
    paths:
    - public/mix-manifest.json
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - node_modules/
  tags:
  - docker

phpunit:
  image: lorisleiva/laravel-docker:latest
  stage: test
  services:
  - name: mysql:5.7
    alias: mysql-test
  - redis:latest
  artifacts:
    when: always
    paths:
    - storage/logs/
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - vendor/
    - node_modules/
    policy: pull
  dependencies:
  - composer
  - npm
  script:
  - php artisan migrate
  - php artisan db:seed --class=TestingSeeder
  - php vendor/bin/phpunit --coverage-text --colors
  tags:
  - docker

dusk:
  stage: test
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
    - vendor/
    - node_modules/
    policy: pull

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

  image: chilio/laravel-dusk-ci:stable
  tags:
  - docker
  script:
  - cp .env.dusk.gitlab-testing .env
  - configure-laravel
  - composer dump-autoload
  - start-nginx-ci-project
  - php artisan dusk --colors

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

我想,是因为它错过了 MYSQL_PASSWORD 中的变量 .yml 但我不是100%确定。很高兴它现在起作用了。

相关问题