Gitlab CI Runner |自定义mysql conf

时间:2016-12-07 11:48:57

标签: mysql docker gitlab-ci my.cnf runner

我试图为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

感谢。

1 个答案:

答案 0 :(得分:0)

我认为无法使用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"'