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.
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.
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.
Completing the setup will launch your first build.
$ heroku login ... Authentication successful. $ heroku create django-example-semaphore Creating django-example-semaphore... done, stack is cedar-14 https://django-example-semaphore.herokuapp.com/ | https://git.heroku.com/djang-example-semaphore.git 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.
Select automatic deployment, as we want every successful build to trigger a new deploy.
Select the branch from which you would like to deploy.
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.
In the last step, name your deploy server and optionally add an URL.
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.
To test out the setup, start the deployment.
After the deployment completes, visiting the server's URL will present you the Django application running on Heroku.
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