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:
- Sign up for Tutum (free)
- Sign up for DigitalOcean ($10 free credit with this link)
- Start a Node Cluster. Choose a single node and a size of at least 2GB. Less than this and you will get intermittent errors.
- Create a Stack using the
- Wait for the node to finish deploying then start the stack.
- 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.
- Find the URL of the service at Services > gitlab > Endpoints. It will be something like
http://gitlab.[stack name].[user name].cont.tutum.io:10080
- Log in to your new Gitlab instance with username root and default password 5iveL!fe
- Set a new password then log in again with it.
- Click the spanner icon i the top right to go to the admin area. Then click Continuous Integration then Runners.
- Copy the 20 character hex runner token.
- 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
- Now redeploy the node-runner service to apply the config change.
- Refresh the Runners page on your Gitlab instance and you should see the runner listed.
- Do a little victory lap of your desk/room. Things are going well.
- Click the plus icon in the top right to create a new project.
- 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
- Go Back to Dashboard then click on Continuous Integration then Add project to CI.
- Click on Runners in the menu then Enable shared runners.
- Go to the project page then select Files in the menu.
- Click the little plus icon next to the branch name to create a new file.
- Name the file .gitlab-ci.yml and past in the file at the end of this post.
- Write a commit message such as "Added CI config" then commit the change.
- Click Continuous Integration and you should see your commit with the build status.
- Click the commit ID then the build number to see the console output.
- You did it! Now go forth and make things.