GitLab CI with Unity3D in Docker

Tests should be an integral part of every software development project and tests mean a lot to us. For our version control we use GitLab, which has great support for CI. For our front-end we use Unity3D, which now has built-in support for unit tests. We wanted to run our Unity3D unit tests on the GitLab CI runners, which proved a bit more difficult than we thought. In the end we got it working using Docker, this blogpost is about how we set it up.

Docker is a great tool that allows you to create containers for software, so that you don’t have to worry about the environment that it is being installed on. To learn more about Docker, check out this link. Our docker image is based on an Ubuntu docker image. The Dockerfile used to create this image is the following. It installs a bunch of dependencies necessary for Unity3D.

FROM ubuntu
ADD unity-editor-5.3.3f1+20160223_amd64.deb .
RUN apt-get update -qq
RUN apt-get install -qq -y gconf-service lib32gcc1 lib32stdc++6 libasound2 libc6 libc6-i386 libcairo2 libcap2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libfreetype6 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libgl1-mesa-glx libglib2.0-0 libglu1-mesa libgtk2.0-0 libnspr4 libnss3 libpango1.0-0 libstdc++6 libx11-6 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxtst6 zlib1g debconf npm xdg-utils lsb-release libpq5 xvfb
RUN dpkg -i unity-editor-5.3.3f1+20160223_amd64.deb

We use Unity 5.3.3, you can easily change the version by placing the Linux package downloaded from here in the same folder as the Dockerfile and changing the following line

ADD unity-editor-5.3.3f1+20160223_amd64.deb .

and then building the Docker image again.

As for our .gitlab-ci.yml file, that looks like this:

image: "aran/unity:latest"
- mkdir -p /root/.cache/unity3d # A folder necessary for building your project
- cd FrontEnd/FuroUnity # Cd into your Unity project dir
- xvfb-run --server-args="-screen 0 1024x768x24" /opt/Unity/Editor/Unity -projectPath $(pwd) -batchmode -runEditorTests -force-opengl -logFile

Most of this was found out by trial and error, as there was no definite guide on how to run Unity3D on servers without GUI, so hopefully this will help you set it up.

De art van het unwrappen – Dutch