HOW TO: Laravel testing on Gitlab CI with Docker

This is just a quick mini-post sharing some of the nice stuff that I’ve done with my co-worker, Kheng Hui, while I was working on an A*STAR project. The project used Laravel 5.3 with PHP 7 and MySQL, and needed to have an in-house Gitlab CI environment that tests the code that was committed into the repository. Other than that, we had faced some challenges with the network as it was a little slow. We had to create a Docker image that has the Laravel dependencies packaged so that the build and test could be done at a faster pace.

Kheng Hui dealt mostly with the server parts — configuring Gitlab, Gitlab CI’s runners and executors whilst I had to write some configuration files to test Laravel. As a Fedora ambassador, whenever the Gitlab server had issues, I always told Kheng Hui in a very sarcastic manner, “What OS is the server running? Ubuntu? That’s the problem! Why aren’t you running Fedora?” Of course, the problems wasn’t an OS issue.

I was also very fortunate as my A*STAR supervisor, Rafael, was a very open minded and friendly person that allowed me to opensource some of the components that I’ve worked on, as long as they were “MIT licensed” (of course!). I’m going to make some possibly reasonable assumptions about your CI environment – you have Gitlab with CI installed, have a (shared or specific) CI runner configured, and have selected Docker as your executor for your runner.

Now, you just have to copy these files that I have uploaded on Github into your Laravel base repository and you’re all set. From now onwards, every commit you make your Gitlab repository will trigger a build and run the test. That was easy, wasn’t it? :) If you encounter any issues, please let me know in the comments section below!

If you’re interested in learning more of the gotchas and experience we had at A*STAR, do watch my presentation about Gitlab:

Author: Woo Huiren

Currently a student at National University of Singapore. I contribute to opensource projects - primarily PHP and Angular related. I write about PCF and PWS related stuff too.

One thought on “HOW TO: Laravel testing on Gitlab CI with Docker”

Leave a Reply