I use Gitlab CI for unit testing of a PHP application that talks to a database server. We use a test matrix to test all combinations of versions of PHP and database engines that we support, and have just added MySQL 8.4 to our testing regime. It doesn’t work out of the box with PHP 7.3, but needs mysql_native_password=ON
adding to my.cnf
. (I appreciate it’s fairly unlikely that someone will use such an old version of PHP in conjunction with a brand new version of MySQL, but the test matrix doesn’t know that.)
At the moment, I have a .gitlab-ci
config a bit like this one:
test-php:
stage: test
parallel:
matrix:
- PHPVERSION: ["7.3"]
DBSERVICE: ["mysql:8.4"]
image: php:$PHPVERSION
services:
- $DBSERVICE
before_script:
- ./setup-mysql.sh
… and a setup-mysql.sh
script that does a bit of database setup, and installs the PHP mysqli
extension:
docker-php-ext-install mysqli > /dev/null
docker-php-ext-enable mysqli
if [ "$PHPVERSION" = "7.3" -a "$DBSERVICE" = "mysql:8.4" ]; then
# PHP 7.3 doesn't support caching_sha2_password authentication
export DEBIAN_FRONTEND="noninteractive"
apt-get -qq update && apt-get -qqy install mariadb-client
mysql -u root -p"$MYSQL_ROOT_PASSWORD" -h mysql
-e "ALTER USER '$MYSQL_USER'@'%'
IDENTIFIED WITH mysql_native_password BY '$MYSQL_PASSWORD'"
fi
Ideally, I would this script also do something like:
cat > /etc/mysql/conf.d/enable-mysql-native-password.cnf <<EOF
[mysqld]
mysql_native_password=ON
EOF
service mysql restart
… but I know that won’t work, as the script is run on the main container, not the MySQL service container. Is there a way of achieving this, while still using standard MySQL image for my service container?