我已经开始配置我的项目的CircleCI集成。我已经使用2.0标准创建了配置文件。我已经使其运行平稳,可以部署并且一切正常,除了我创建的phpunit测试。当我运行phpunit命令时,它返回一个错误(我相信他无法连接到数据库)。
Unable to insert fixtures for "App\Test\TestCase\Model\Table\UsersTableTest" test case. SQLSTATE[HY000] [2002] No such file or directory in [***/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php, line 356]
这是我的测试数据库配置:
'test' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
// 'port' => '3306',
'database' => 'common_resources_test',
'username' => 'root',
'password' => 'root',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
],
这是我的circleCI代码:
version: 2
jobs:
build:
working_directory: *removed*
parallelism: 1
shell: /bin/bash --login
environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
DEBUG: true
docker:
- image: circleci/php:7.1-apache
steps:
- checkout
- run:
name: Install Maria DB
command: sudo apt-get install -y mariadb-server-10.1 mariadb-server-core-10.1 mariadb-client-10.1 mariadb-client-core-10.1
- run:
name: Initializing Mysql
working_directory: *removed*
command: 'sudo service mysql status || sudo service mysql restart; '
- run:
name: Set password
command: sudo mysql -u root -e "USE mysql; UPDATE user SET password=PASSWORD('root') WHERE User='root';FLUSH PRIVILEGES;"
- run:
name: Check settings
command: sudo mysql -u root -proot -e "USE mysql; SELECT host FROM user WHERE user = 'root';grant all privileges on *.* to root@'127.0.0.1' identified by 'root';FLUSH PRIVILEGES; SELECT host FROM user WHERE user = 'root';SELECT @@port;SELECT @@hostname;"
- run:
name: Restarting Mysql
working_directory: *removed*
command: 'sudo service mysql status || sudo service mysql restart; '
- run:
name: Create Mysql database and show current databases
command: sudo mysql -uroot -proot -e "create database common_resources_test;SHOW DATABASES"
- run:
name: Install required Libraries for PHP-GD
command: sudo apt-get update && sudo apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
- run:
name: Install PHP Extensions (PHP-GD && PDO-MYSQL)
command: sudo docker-php-ext-install gd && sudo docker-php-ext-install pdo_mysql
- run:
name: Install Other required Libraries for PHP & Activating PHP-GD and PDO-MYSQL
command: sudo docker-php-ext-install -j$(nproc) iconv && sudo docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && sudo docker-php-ext-install -j$(nproc) gd && sudo docker-php-ext-enable pdo_mysql
- run:
name: Create folder for Circle Artifacts and Circle Test Reports
working_directory: *removed*
command: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
- run:
name: Download Composer
command: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
- run:
name: Running Composer Install
working_directory: *removed*
command: composer install --no-interaction;
- run:
name: Download Yarn
working_directory: *removed*
command: curl -o- -L https://yarnpkg.com/install.sh | bash
- run:
name: Install Yarn
working_directory: *removed*
command: sudo yarn install
- restore_cache:
keys:
- v1-dep-{{ .Branch }}-
- v1-dep-pre-production-
- v1-dep-
- save_cache:
key: v1-dep-{{ .Branch }}-{{ epoch }}
paths:
- vendor/bundle
- ~/virtualenvs
- ~/.m2
- ~/.ivy2
- ~/.bundle
- ~/.go_workspace
- ~/.gradle
- ~/.cache/bower
- ~/.composer/cache
- ~/.yarn-cache
- run:
name: Creating folder for PHPUnit Tests
working_directory: *removed*
command: mkdir -p $CIRCLE_TEST_REPORTS/phpunit
- run:
name: Running PHPUnit Tests
working_directory: *removed*
command: ./vendor/bin/phpunit --configuration ./phpunit.xml.dist --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml
- store_test_results:
path: /tmp/circleci-test-results
- store_artifacts:
path: /tmp/circleci-artifacts
- store_artifacts:
path: /tmp/circleci-test-results
deployment:
docker:
- image: circleci/python:2.7-jessie
steps:
- run:
name: Install awsebcli
command: sudo pip install awsebcli
- run:
name: Deploy to S3
command: eb deploy --profile default
workflows:
version: 2
build_and_test:
jobs:
- build:
filters:
tags:
only: /.*/
- deployment:
requires:
- build
filters:
branches:
only: pre-production
感谢您的时间
答案 0 :(得分:2)
我将按照配置中的方式处理数据库。您可以将第二个容器用于数据库。然后使用环境变量设置数据库凭据。
配置行如下所示:
- image: circleci/mariadb:10.1
environment:
MYSQL_DATABASE: "common_resources_test"
MYSQL_ROOT_PASSWORD: "root"
答案 1 :(得分:0)
找到一种解决此问题的方法。基本上,mysql root不允许使用密码登录。不得不进行设置。这是我的app.php配置:
'test_common_resources' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => '127.0.0.1',
'unix_socket' => '/var/run/mysqld/mysqld.sock',
'database' => 'common_resources_test',
'username' => 'root',
'password' => 'root',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
]
这是我的circleci配置:
version: 2
jobs:
build:
working_directory: **removed**
parallelism: 1
shell: /bin/bash --login
environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
DEBUG: true
docker:
- image: circleci/php:7.1-node-browsers
steps:
- run:
name: Install Maria DB
command: sudo apt-get install -y mariadb-server-10.1 mariadb-server-core-10.1 mariadb-client-10.1 mariadb-client-core-10.1
- run:
name: Initializing Mysql
command: 'sudo service mysql status || sudo service mysql restart; '
- run:
name: Set password
command: sudo mysql -u root -e "USE mysql; UPDATE user SET password=PASSWORD('root') WHERE User='root';FLUSH PRIVILEGES;"
- run:
name: Check settings
command: sudo mysql -u root -proot -e "USE mysql; UPDATE user SET plugin='mysql_native_password' WHERE User='root'; SELECT User, Host, plugin FROM mysql.user WHERE user = 'root';grant all privileges on *.* to root@'127.0.0.1' identified by 'root';FLUSH PRIVILEGES; SELECT host FROM user WHERE user = 'root';SELECT @@port;SELECT @@hostname;"
- run:
name: Restarting Mysql
command: 'sudo service mysql status || sudo service mysql restart; '
- run:
name: Create Mysql database and show current databases
command: sudo mysql -uroot -proot -e "create database common_resources_test;SHOW DATABASES"
- run:
name: Install required Libraries for PHP-GD
command: sudo apt-get update && sudo apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
- run:
name: Install PHP Extensions (PHP-GD && PDO-MYSQL)
command: sudo docker-php-ext-install gd && sudo docker-php-ext-install pdo_mysql
- run:
name: Install Other required Libraries for PHP & Activating PHP-GD and PDO-MYSQL
command: sudo docker-php-ext-install -j$(nproc) iconv && sudo docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && sudo docker-php-ext-install -j$(nproc) gd && sudo docker-php-ext-enable pdo_mysql
- run:
name: Create folder for Circle Artifacts and Circle Test Reports
command: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
- run:
name: Download Composer
command: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
- run:
name: Download Yarn
command: curl -o- -L https://yarnpkg.com/install.sh | bash
- run:
name: Install Yarn
command: sudo yarn install
- restore_cache:
keys:
- v1-dep-{{ .Branch }}-
- v1-dep-pre-production-
- v1-dep-
- checkout
- run:
name: Running Composer Install
command: composer install --no-interaction;
- save_cache:
key: v1-dep-{{ .Branch }}-{{ epoch }}
paths:
- vendor/bundle
- ~/virtualenvs
- ~/.m2
- ~/.ivy2
- ~/.bundle
- ~/.go_workspace
- ~/.gradle
- ~/.cache/bower
- ~/.composer/cache
- ~/.yarn-cache
- run:
name: Creating folder for PHPUnit Tests
command: mkdir -p $CIRCLE_TEST_REPORTS/phpunit
- run:
name: Checking Mysql Status
command: 'sudo service mysql status'
- run:
name: Running PHPUnit Tests
command: ./vendor/bin/phpunit --configuration ./phpunit.xml.dist --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml
- store_test_results:
path: /tmp/circleci-test-results
- store_artifacts:
path: /tmp/circleci-artifacts
- store_artifacts:
path: /tmp/circleci-test-results
deployment:
docker:
- image: circleci/python:2.7-jessie
steps:
- run:
name: Install awsebcli
command: sudo pip install awsebcli
- run:
name: Deploy to S3
command: eb deploy --profile default
workflows:
version: 2
build_and_test:
jobs:
- build:
filters:
tags:
only: /.*/
- deployment:
requires:
- build
filters:
branches:
only: pre-production