Classic Docs
Docs Navigation

Continuous Integration and Deployment of a Django application from GitHub to Heroku with Semaphore

In this guide, we will show you how to deploy a Django application to Heroku using Semaphore. We will be using a barebones, open-source Django repository on GitHub. Feel free to fork it and use it to follow along if you don't have a project already set up.

The sample application will be deployed automatically by Semaphore every time all tests pass on the master branch. Semaphore lets us easily set up this kind of deployment, which is also known as continuous deployment. With this in place, we can be sure that we have working code on our server at all times.

The sample application will be deployed to Heroku. Both Semaphore and Heroku have native support for Python, so setting up a project using these services is a breeze.

# Requirements

  • Heroku account
  • Semaphore account — create one here
  • Python with virtualenv installed on your machine
  • git installed on your machine

# Setting up continuous integration with Semaphore and GitHub

After creating a Semaphore account and hooking it up with your GitHub or BitBucket account, you are ready to add the Django project from the list of your available repositories.

Project list

In the following steps, selecting the branch and the account to which you wish to add the project will bring you to the analysis page, where Semaphore determines the settings for your project. These settings can be changed at any time in Project Settings.

Semaphore analysis complete

Completing the setup will launch your first build.

Semaphore first successful build

# Setting up continuous deployment from Semaphore to Heroku

By installing heroku-toolbelt, you gain access to Heroku CLI. With this tool, you can set up your application on Heroku without leaving the comfort of your terminal.

$ heroku login
Authentication successful.

$ heroku create django-example-semaphore
Creating django-example-semaphore... done, stack is cedar-14 |
Git remote heroku added

We are ready to configure the deployment to Heroku. Visiting the project's page on Semaphore will reveal a "Set Up Deployment" button. Semaphore's deploy wizard will guide you through the process of setting up your first deployment to Heroku.

Semaphore deployment destination

Select automatic deployment, as we want every successful build to trigger a new deploy.

Semaphore deployment type

Select the branch from which you would like to deploy.

Semaphore deployment branch

At this point, you will be asked for your Heroku API key. It can be found by going to account settings on Heroku and clicking the "Show API Key" button at the bottom.

Go back to Semaphore and select the Heroku application to which Semaphore will deploy your code.

Semaphore deployment Heroku application

In the last step, name your deploy server and optionally add an URL.

Semaphore deployment server name

A deploy can be triggered right away. Every new commit to the master branch will trigger a new build, which, if successful, will run the deploy to Heroku.

Semaphore deployment setup complete

To test out the setup, start the deployment.

Semaphore first successful deployment

After the deployment completes, visiting the server's URL will present you the Django application running on Heroku.

Heroku application

After completing these steps, your project has continuous integration and deployment set up and you can enjoy the benefits of this agile practice.

Semaphore Docs are open source — Edit on GitHub


Occasional lightweight product and blog updates. Unsubscribe at any time.

2009-2020 © Rendered Text. All rights reserved. Terms of Service, Privacy policy, Security.