Django Testing Automated with Self Hosted Gitlab CI and Docker

Reading Time : ~ .

It is a bit pricy if you want to host code for collaboration using bitbucket or github on your own VPS or On-Premisis servers. Gitlab in midst of this provides a community edition which is packed with essential features and also free of cost. Both Editions ship with CI integrated in it and also can handle 3rd party CI applications like Jenkins or Bamboo ..etc.,

In this Tutorial you will see

  1. Installation of GITLAB
  2. Configuring CI + Runners 

Test Environment: Ubuntu 14.04 on VPS with 2 cores/4 GB RAM

Installing GITLAB:

Install Dependencies:

sudo apt-get install curl openssh-server ca-certificates

Official Gitlab suggests the use of postfix, but you can use other email delivery solutions like Sendgrid or Mailchimp, which provide 10,000+ emails/month.

Use Bash Script provided by GITLAB to add repository to apt-package list:

curl -sS | sudo bash

Then Install using command 

sudo apt-get install gitlab-ce

This will Install Gitlab, now we need to make following changes to  configuration information in /etc/gitlab/gitlab.rb and run gitlab-ctl reconfigure to apply the changes

external_url "<gitlab endpoint url>"

For details regarding smtp settings you can visit this link. which has settings for various smtp mail providers.

After Reconfiguring. You can navigate to gitlab in web browser and set password. Note that default credentials are root/<password-set>.

Gitlab CI + Runners:

For Security reasons it is not preferrable to run Test cases in same server as Gitlab CE+CI Instances. But we can use Docker to advantage and run the test cases in Isolated Environments which is safe.

Install Docker with following command

curl -fsSL | sh

Prepare a docker image which comprises of your required system packages. we use this image for django testing. 

Install Gitlab Runner by 

curl -L | sudo bash

sudo apt-get install gitlab-ci-multi-runner

Register it your gitlab instance by 

sudo gitlab-ci-multi-runner register

Please enter the gitlab-ci coordinator URL (e.g. )
<gitlab endpoint url>/ci

Please enter the gitlab-ci token for this runner
Can find in admin area runners section (shared runner) or project Runners Section (Project Specific Runner) 

Please enter the gitlab-ci description for this runner

Please enter the executor: shell, docker, docker-ssh, ssh?

Please enter the Docker image:
INFO[0037] Runner registered successfully. Feel free to start it,


Thus you successfully set up both CE + CI + Runners.

Create a GITLAB Project and Push your Project with test cases in it. you should see builds running.

Visit this Video Tutorial in case you're struck somewhere.

    By Posted On

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Imageview customization (circular image view) Chaitanya Kattineni

In android designing we'll come across ImageView. An ImageView displays an arbitrary image, such as an icon. The ImageView class can load images from various ...

Continue Reading...
Dynamic Models in Django-Part1 (adding new fields to models from admin) Siva Chittamuru

Some times in the production level there may be a chance of adding new fields to our model.With the normal django models when we add ...

Continue Reading...
Basics of Linux File System Heirarchy Dinesh Deshmukh

In 1994, FHS(File System Hierarchy Standard) was proposed, it describes the directory structure of UNIX and UNIX-like systems(Linux). Before FHS was proposed, there had been ...

Continue Reading...

Subscribe To our news letter

Subscribe to our news letter to receive latest blog posts into your inbox. Please fill your email address in the below form.
*We don't provide your email contact details to any third parties