GitLab CI and MySQL

So i’m playing around with the GitLab CI features, and i’m trying to get a MySQL database up and running.

My .gitlab-ci.yml file looks like this:

image: php:5.6

  - mysql:latest

  MYSQL_DATABASE: test_database # Created at image startup
  MYSQL_ROOT_PASSWORD: super-secret-password

  - php -v
  - curl --silent --show-error | php

    - echo Running job1...
    - echo "SELECT 'OK';" | mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql "$MYSQL_DATABASE"

It fails with the following message:

Running with gitlab-ci-multi-runner 1.4.2 (bcc1794)
Using Docker executor with image php:5.6 ...
Pulling docker image mysql:latest ...
Starting service mysql:latest ...
Waiting for services to be up and running...
Pulling docker image php:5.6 ...
Running on runner-30dcea4b-project-1566290-concurrent-0 via runner-30dcea4b-machine-1472046208-6ab7c3fe-digital-ocean-4gb...
Cloning repository...
Cloning into '/builds/densou/test'...
Checking out 9a4ccf71 as master...
$ php -v
PHP 5.6.25 (cli) (built: Aug 22 2016 19:34:09) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
$ curl --silent --show-error | php
All settings correct for using Composer
Downloading 1.2.0...

Composer successfully installed to: /builds/densou/test/composer.phar
Use it: php composer.phar
$ echo Running job1...
Running job1...
$ echo "SELECT 'OK';" | mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql         "$MYSQL_DATABASE"
/bin/bash: line 50: mysql: command not found
ERROR: Build failed: exit code 1

I thought the mysql image was linked when using the services: option, but it doesn’t work. What am i missing?
I want to have mysql available in my php image i guess? Or should i install it manually. I don’t want to use the mysql image.


It looks to me like it is properly pulling in the mysql docker image however that is not the issue. From the bash error you do not have the mysql client installed on the build server.

If the build server (where the gitlab runners run) is a Debian based server run the following command from a terminal:

sudo aptitude install mysql-client

Thanks, not sure how I overlooked the last line :smile: Thanks!