I maintain about a dozen plugins in the Moodle plugins repository. I use Moodlerooms’ moodle-plugin-ci project to test all of them on Travis CI. It’s a fantastic tool and rely heavily on it.
This fall I’ve been working on a plugin which, because of various hooks into Lafayette’s internal infrastructure, I’m not releasing publicly. I’d still like to test it in the usual way, so I decided to run the tests on our internal GitLab infrastructure.
Building a container
Dagefoerde pitched a usable .gitlab-ci.yml some time ago. This could be run on our existing docker-based CI infrastructure with basically no tweaks. Adding those packages on each run took several minutes, so I crafted a custom container (based on PHP 5.6, which is what we’re running) to eliminate the overhead. The package part is pretty simple:
1 | RUN apt-get clean |
A few lines add the PHPUnit and Composer support:
1 | ADD https://phar.phpunit.de/phpunit.phar /usr/local/bin/phpunit |
Confident, I deployed this container instead of the stock php:7.0
and it promptly died:
1 | [Symfony\Component\Process\Exception\ProcessFailedException] |
Huh?
phpenv
Getting this working was tricky. There are several different phpenv projects floating around. Travis CI uses CHH/phpenv. The installation notes are a bit sparse, and didn’t spell out that you needed to install php-build as well to use the phpenv config-add
and phpenv config-rm
commands. I adapted most of this block from jolicode/phpenv, with some tweaks to reflect that I was running everything under root:
1 | RUN git clone https://github.com/CHH/phpenv.git /tmp/phpenv && \ |
Directory collisions
Our internal Moodle projects in GitLab are organized into a “Moodle” group. When GitLab clones a project during a CI run it puts it into the /builds/moodle/<project name>
directory. This causes a problem, because by default moodle-plugin-ci will try cloning core Moodle into /builds/moodle
. The directory isn’t empty in our case, so this clone fails.
The first way I solved this was by proposing a feature request to moodle-plugin-ci: allow a customized installation path for Moodle. A second way, I realized later, was to create such a directory myself in the .gitlab-ci.yml
file, and then create the ci project and core installation one level deep. The build path for the project ($CI_PROJECT_DIR
) is absolute anyway. It looks a little clunkier than the default, but it works:
1 | - mkdir moodle-ci |
In this revised setup, builds
looks like this:
1 | builds/ |
Multiple versions
GitLab doesn’t have the same concept of the Travis build matrix, but you can approximate it using a job template:
1 | .job_template: &job_definition |
This works well enough for my purposes. For an internal project, I’m only interested in testing my current environment, and the next likely environment. I don’t need to test postgresql, or myriad Moodle versions that we don’t run.