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 https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | 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 https://get.docker.com/ | 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 https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | 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. https://gitlab.com/ci )
<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
my-runner

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

Please enter the Docker image:
python-ci:latest
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. 

https://youtu.be/7tKSz5OkrA0

    By Posted On
SENIOR DEVELOPER at MICROPYRAMID

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Kubernetes Installation on BareMetal(Fedora) Dinesh Deshmukh

Kubernetes manages containerized applications across multiple hosts. With years of experience in managing highly scalable products, google has released kubernetes an open source project which ...

Continue Reading...
Google Analytics Graphs to your Dashboard in Python Web Frameworks Jagadeesh V

Ecommerce solution providers like OpenCart, Magento Provide extensions to see Google analytics data in their own dashboards as graphs. whereas there are no such plugins ...

Continue Reading...
How to create Custom User Model in Django? Chaitanya Kattineni

Django provides built in authentication which is good for most of the cases, but you may have needs that are being served with the existing ...

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