Dockerised Gitlab+CI+Runner

Posted on 7 Oct 2015

Gitlab is an open source clone of Github with some extra features like merge requests which are useful for teams. It has recently been combined with Gitlab CI which is a continuous integration server similar to Travis.

Getting Gitlab and Gitlab CI up and running is pretty easy. The bit that I struggled with was the runner(s). A Gitlab CI runner is any computer with the gitlab-ci-multi-runner agent software installed. This agent phones home regularly to check for any jobs that it should be running. The agent can run the jobs locally on the same machine or remotely on a different machine over SSH. But the neat bit is that it can use Docker to spawn containers in which to run the jobs. This means each job is guaranteed an identical, fresh, clean test environment.

If you're on OSX or Linux you can use docker-compose with the following file but we're going to use a web service called Tutum which uses the same format input file but works cross platform.

Let's get going:

  1. Sign up for Tutum (free)
  2. Sign up for DigitalOcean ($10 free credit with this link)
  3. Start a Node Cluster. Choose a single node and a size of at least 2GB. Less than this and you will get intermittent errors.
  4. Create a Stack using the docker-compose.yml file above.
  5. Wait for the node to finish deploying then start the stack.
  6. Wait for the containers to start up. The node-runner container will fail to start. This is expected. The gitlab container will report that it is running but the application itself takes a few minutes to start up. Watch progress at Services > gitlab > Logs.
  7. Find the URL of the service at Services > gitlab > Endpoints. It will be something like http://gitlab.[stack name].[user name]
  8. Log in to your new Gitlab instance with username root and default password 5iveL!fe
  9. Set a new password then log in again with it.
  10. Click the spanner icon i the top right to go to the admin area. Then click Continuous Integration then Runners.
  11. Copy the 20 character hex runner token.
  12. Go back to Tutum and edit the stack file you created and update the RUNNER_TOKEN environment variable. Also update GITLAB_HOST to match your endpoint, for example
  13. Now redeploy the node-runner service to apply the config change.
  14. Refresh the Runners page on your Gitlab instance and you should see the runner listed.
  15. Do a little victory lap of your desk/room. Things are going well.
  16. Click the plus icon in the top right to create a new project.
  17. For testing purposes, we can use my gulp-readmin plugin and pull it directly by choosing Import project from and pasting in the following URL
  18. Go Back to Dashboard then click on Continuous Integration then Add project to CI.
  19. Click on Runners in the menu then Enable shared runners.
  20. Go to the project page then select Files in the menu.
  21. Click the little plus icon next to the branch name to create a new file.
  22. Name the file .gitlab-ci.yml and past in the file at the end of this post.
  23. Write a commit message such as "Added CI config" then commit the change.
  24. Click Continuous Integration and you should see your commit with the build status.
  25. Click the commit ID then the build number to see the console output.
  26. You did it! Now go forth and make things.