1

I'm trying to run moodle phpunit on my gitlab ci server. Using gitlab-ci.yml file i'm creating a container with php 5.6 and mysql service.

# Services
services:
  - mysql:latest

before_script: 
  - mysql -e 'CREATE DATABASE gitlab_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;

I'm getting ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) and not sure how to proceed.

Tomasz Kowalczyk
  • 1,951
  • 2
  • 16
  • 18
  • http://stackoverflow.com/a/15039113 – Drew Nov 30 '15 at 16:39
  • Possible duplicate of [ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)](http://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run) – Drew Nov 30 '15 at 16:40
  • 1
    Was the error produced by the command in before_script or the job itself? Since the `mysql` service is in another container, there may be a need to use `mysql --host=mysql -e 'CREATE...`. – Yong Jie Wong Nov 30 '15 at 18:26
  • Yes, the error was produced in before_script. And I think you suggestion worked, just need to figure out now how to connect to that database. – Tomasz Kowalczyk Dec 01 '15 at 09:16

1 Answers1

0

Tomasz this is my gitlab-ci.yml file you will need something like this:

# Select image from https://hub.docker.com/r/_/php/
image: php:7.0.0

services:
  - mysql:5.7

variables:
  # Configure mysql environment variables (https://hub.docker.com/r/_/mysql/)
  MYSQL_DATABASE: symfony
  MYSQL_ROOT_PASSWORD: qwerty

# Composer stores all downloaded packages in the vendor/ directory.
# Do not use the following if the vendor/ directory is commited to
# your git repository.
cache:
  paths:
  - vendor/

before_script:
# Install dependencies
- bash ci/docker_install.sh > /dev/null
- cp ci/parameters.yml app/config/parameters.yml
- composer install

test:app:
  script:
  - phpunit

And this is my docker_install.sh inside ci folder

#!/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 phpunit, the tool that we will use for testing
curl -o /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar
chmod +x /usr/local/bin/phpunit

# Install mysql driver
# Here you can install any other extension that you need
docker-php-ext-install pdo pdo_mysql mbstring
Luis Lopes
  • 506
  • 4
  • 14