![](/img/trans.png)
[英]gitlab runner: mysqld: Can't read dir of '/etc/mysql/conf.d/'
[英]Gitlab CI Runner | Custom mysql conf
我正在嘗試為Gitlab CI Runner設置自己的mysql conf。 我在文檔中找到了如何設置自己的php.ini:
before_script:
- cp ci/php.ini /usr/local/etc/php/conf.d/test.ini
我沒有找到有關如何設置my.cnf的信息,我嘗試了:
before_script:
- cp ci/my.cnf /usr/local/etc/mysql/conf.d/my.cnf
但是/ usr / local / etc / mysql /在生成的環境中不存在。
這就是我所有的gitlab.ci:
services:
- mysql:latest
variables:
# Configure mysql environment variables
WITH_XDEBUG: "1"
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: symfony
cache:
paths:
- vendor/
before_script:
# Install dependencies
- bash ci/docker_install.sh > /dev/null
- cp ci/php.ini /usr/local/etc/php/conf.d/test.ini
- cp ci/my.cnf /usr/local/etc/mysql/conf.d/my.cnf
- mv app/config/parameters.gitlab.yml app/config/parameters.yml
- mv app/config/config_test.gitlab.yml app/config/config_test.yml
- composer clear-cache
- composer install
- php bin/console doctrine:schema:update --force
- php bin/console doctrine:fixtures:load
test:
image: php:7.0
stage: test
script:
- echo "Running PHPUnit Tests"
- vendor/bin/phpunit --configuration phpunit.xml.dist --colors --debug --coverage-text
還有我的docker_install.sh:
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && [[ ! -e /.dockerinit ]] && exit 0
set -xe
# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git -yqq
apt-get install wget -yqq
apt-get install zip unzip -yqq
# Install composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# Install mysql driver
# Here you can install any other extension that you need
docker-php-ext-install pdo_mysql mbstring
謝謝。
我認為不可能使用Gitlab CI配置將配置輕松安裝到服務容器中。 僅創建一個擴展用於測試的映像並在那里設置所需配置的Dockerfile可能會更容易。
您可以在此處找到一個如此小的Dockerfile的示例,作者在其中復制了一個配置文件以將編碼設置為utf8:
https://hub.docker.com/r/dnhsoft/mysql-utf8/dockerfile
或者,如果您不想編寫用於復制文件的Dockerfile,則可以像這樣簡單地附加配置,例如:
FROM mysql:8.0
RUN echo '[mysqld]' >> /etc/mysql/conf.d/mysql.cnf
RUN echo 'default-authentication-plugin = mysql_native_password' >> /etc/mysql/conf.d/mysql.cnf
RUN echo 'collation-server = utf8mb4_general_ci' >> /etc/mysql/conf.d/mysql.cnf
RUN echo 'character-set-server = utf8mb4' >> /etc/mysql/conf.d/mysql.cnf
Dockerfile具有所需的配置后,您可以使用您的用戶名將其發布到Dockerhub。 然后在gitlab-ci.yml
可以像這樣使用它:
services:
- {name: 'mydockerusername/mysql:1', alias: 'mysql'}
然后,在gitlab-ci.yml
腳本中,您可以像這樣連接到自定義數據庫容器:
script:
- 'mysql -u gitlabci -h mysql --password="gitlabci" -e "SHOW DATABASES"'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.