Headless Ember Tests in GitLab with Docker
My goal was to run my Ember tests in our (in-house, private) GitLab pipeline, but without duplicating the setup steps already encapsulated in our Dockerfile for building the production app. There were a number pieces I had to puzzle over to get this running, this being my first attempt while learning how GitLab CI works. Iām no expert here, so please comment if you have similar experience to share. Hereās the high-level steps I wanted to cover:
- Start with our Dockerfile that installs NGINX, builds our Ember application and copies the built distribution to /usr/share/nginx/html.
- Our deployment ENTRYPOINT for the image is ānginxā in this example.
- To keep the GitLab CI script small and avoid any setup duplication, run the unit tests with the same docker image we just built.
- Collect the unit test report in GitLab CI as a build artifact.
Readying the Testem Configuration
The testem.js file in your ember project specifies command-line options that are passed to this executable. Note in the testem.js file below the process.env.TRAVIS variable; this is something weāll have to ensure is set to true in our Dockerfile. Another couple changes I made to the default are:
- Setting the
report_fileso I can later collect the test results - Setting
tap_quiet_logsso error cases are much easier to pick out of the log. - Your CI may have support for a different
reporter, such as junit format.
The Dockerfile for Headless Testing
The first problem in getting the Dockerfile ready was finding an example of installing Chrome in an alpine-based Node.js Docker image ā most seemed to be for Ubuntu-based images, using apt-key, which isnāt available here. The full Dockerfile is below. It does the following:
- Installs NGINX.
- Installs Chromium. You may not require
freetypeorharfbuzzwith a newer Alpine base; mine was not the latest and didnāt work without those. - Locates the executable. Using Chromium over Chrome-proper meant that
testem.jscouldnāt find the executable since it is configured by default to look explicitly for āgoogle-chromeā. Easy to solve withRUN ln -s /usr/bin/chromium-browser /usr/bin/google-chrome. (I imagine you could probably do this with an environment variable flag to specify the right executable in thetestem.jsfile too.) - Set the CI environment for Testem:
ENV TRAVIS=true
The rest of the file just does the expected basic building of the application distribution and copying it over to the appropriate directory for NGINX to serve it up.
Kicking off the Tests from GitLab
To use the same image to run the tests, my gitlab-ci.yml script took these steps:
- Built the production image
- Made a directory for the test report
- Ran the tests in the container, by overriding the original ENTRYPOINT
Putting that all together, we get:
Next Steps
This isnāt really the final ideal picture, mostly due to GitLab being completely new to me. Some next steps:
- Chrome is essentially bloating the docker production image. Could I use a Chrome service image instead to avoid this, instead connecting to a chrome external to the image? Again, in GitLab, and I suppose because Iām running via the docker image, I donāt have the luxury of TravisCIās
addon: chromeoption. - Split the build and test stages. I still need to add the steps for pushing the image to our registry ā at which point I could pull it back down in a separate ātestā stage. This was the original impetus to figure out running the alternate
--entrypoint(rather than simply running the tests in the Dockerfile itself.) - Upgrade our version of GitLab to get the built-in test report support.
If you have any suggestions, tips, etc., please share them.
Photo credit: https://flic.kr/p/pZXF4j
Follow us on Twitter š¦ and Facebook š„ and join our Facebook Group š¬.
To join our community Slack š£ļø and read our weekly Faun topics šļø, click hereā¬

