A story of a Tanuki and a green Swan
Enable Gitlab CI for a Sylius project
My task was straight-forward: Add GitLab CI to a Sylius project.
While I have setup a lot of projects with TravisCI, I had never before with GitLab CI. All I knew was, analogous to TravisCI, that I would need some kind of configuration file which controls the automatization. GitLab says, that it is super easy – just create a
.gitlab-ci.yml in your project root. But the more I read GitLabs documentation and blog posts, the more questions came to my mind.
- Do I need to create a Docker container?
- Where to store it?
- Where to register it?
- Installing a Gitlab Runner? Where? Why?
- What are shared runners?
I went straight to the Sylius Slack Channel to ask if somebody already has a configuration file available … but the answer was negative. I thought that this is a common task and since Sylius is based on Symfony 4 aka Flex, somebody has to have written a config file for it. But … all I found was outdated or misleading information. At the end I cherry picked piece by piece from all those findings and literally pushed line by line to GitLab waiting for the outcome. It took me a little less than 100 commits to get it working. Another 10 for fine tuning. In the following I will share and explain my config file with you. It can be used for a Sylius 1.3 project.
TLDR: Here you go. If your are in a hurry, just copy the file and commit it to your project.
I will update the file from time to time to keep up to date with GitLab changes or when I discover something new. Below the Gist, I explain the configuration in more detail.
I learned that I don’t have to create a Docker container by myself. Some awesome people already did this and I (and you) can profit from it. The task was to find this container which comes with batteries included. The batteries here a the a fully installed LAMP stack. I tried
alpine first only to find out it was missing a lot of stuff. I ended with the image from edbizarro/gitlab-ci-pipeline-php which addresses Laravel users but works very well for Flex/Sylius.
It took me a while to configure the connection to the database. Used to use
127.0.0.1 for the
--host I kept getting a
Connection refused error. I learned to use
mysql for the host option, since I import a MySQL Docker container when I specify
mysql as a service in
One of my sources for my
.gitlab-ci.yml was the
.travis.yml file at https://github.com/Sylius/Sylius-Standard/blob/master/.travis.yml. From there I took the rough structure and the environment. In case you wondered why I use
--env=test_cached … now you know :-)
If you read the file you will see that they use a specific
.env.test_cached file, which responds to the
test_cached environment. The copy it and source it to make the environment variables available.
You will miss this in my config because it sets the
mysql:://email@example.com/sylius_test_cached. This was too static for me, so I decided to set the environment variables manually and use those variables to create the database connection string.
All dependencies of Sylius are managed by Composer. There are two spots in the config I want to highlight:
Composer run out of memory: Sometimes while he was fetching the dependencies from upstream, sometimes while clearing the cache after installing the dependencies. Therefore I set the memory limit to infinite on line 14.
Composer hit max execution time: Again the clear cache command was the culprit. It takes ages to clear an–I guess already empty cache–that it slows down the whole process and sometimes even hits the
max_execution_timelimit. I decided to run composer install with the
--no-scripts option(line 51).
I think the rest is pretty basic stuff and self explaining. If you have any question, please leave a comment.