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
How to develop RESTful webservice in Django using djangorestframework? Chaitanya Kattineni

DjangoRestFramework is widely used to develop restful API. DjangoRestFramework is easy to use who are familiar with Django, as it is developed on the core ...

Continue Reading...
Understanding Django's model fromsets in detail and their advanced usage. Ramya Ambati

Silmilar to the regular formsets, django also provide model formset that make it easy to work with django models. Django model formsets provide a way ...

Continue Reading...
Vim for Python Web Development Ashwin Kumar

Having a good environment setup is important for effective, fast and easy coding. We have different IDE's like eclipse, pycharm, sublime etc.. which are powerful ...

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