Continuous Deployment for Django apps from Bitbucket to dotCloud

Deployment Academy

How to set up Continuous Integration and Continuous Deployment for a Django Application from Bitbucket to dotCloud

In this blog post we’re gonna deploy a Django application from a Bitbucket repository to dotCloud using the Codeship.

Codeship – A hosted Continuous Deployment platform for web applications

We’ve set up a simple Django application called codefish which contains some tests. We’ll use screenshots of this application in this blog post. If you haven’t got an own project to set up but you want to follow along on your computer, just fork the repository.

codefish-django on Bitbucket

Together, we’re gonna deploy this application to dotCloud using the Codeship.

The Codeship Landing Page

First, sign in to the Codeship with Bitbucket. The Codeship needs access to your Bitbucket repositories to be able to set them up. Let’s allow access.

Bitbucket Access

We’re back at the Codeship. Now let’s create your first project.

Let's set up our first project on the Codeship

The first step of your project setup is to select Bitbucket as your repository provider.

Select your repository provider

In the list of your Bitbucket repositories

Search for your repository in the list

search for the repository you want to set up and select it. In my case I search for “codefish”.

Find your repository in the filtered list

Now your repository is connected and you can set up your test commands:

Set up your test commands

Codefish is a Django application. Therefore let’s choose “Python” as your technology. This prepopulates the setup commands and the test commands for you.

Select Django as your technology

For my application I don’t use a database, so I leave the setup commands as they are. If you want to run the syncdb or the migrate command for your application, just uncomment the commands by removing the # in front of them.

If you want to run your tests with python test, you don’t need to change the test commands. Otherwise just enter your own test commands.

Django test commands

Now let’s finish your setup and go to the dashboard.

Finish your setup. You are on the Dashboard now

To start your first build, you need to add a push hook to your Bitbucket repository. Copy the hook url and follow the link to the service hook settings of your repository. Add a “POST” hook there,

Bitbucket select POST hook

paste the hook url

Bitbucket paste hook URL

and save the hook.

Bitbucket hook URL

You can trigger a build for your application by pushing to your repository. Let’s add the Codeship status image to the README file. I use markdown syntax to insert the image.

Copy the code for the Codeship status badge to your README file

Now commit and push this change.

Commit and push your change

This triggered a new build on the Codeship.

A new build got triggered on the Codeship

You can access the build details by clicking the arrow on the right. Here you can follow the running build.

Click on the arrow to the right to access the build details

And a few seconds later your build succeeded! Great!

Look at all the commands that are running

You see all the commands that were run. After a few initial preparation commands the Codeship ran the commands that you specified a few moments ago.

You can inspect the output of a single command by clicking on it. For the codefish application, we can see that two tests were run.

Look at the log of a single command by clicking on it

You’ve already pushed to your repository, watched your build log and got a green build. So you can finish the assistant at the top.

Finish the setup wizard by clicking on the click to finish button

Now let’s deploy your application to dotCloud. Go to your project settings by clicking on the settings icon in the projects dropdown.

Go to your project settings by clicking on the settings icon in the projects dropdown

You are on the Testing Setup screen now

Then navigate to the “Deployment” section.

You are on the Deployment Setup screen now

As we want to deploy to dotCloud we click on the “dotCloud” button.

Click on the dotCloud button

To retrieve your API key, just follow the link to Dotcloud.

Dotcloud API key

Copy the key and insert it into your deployment configuration at the Codeship.

Dotcloud deployment with API key

You can name your application whatever you like. The application will be automatically created the first time you deploy to Dotcloud.

Copy and paste the dotCloud API key to the Codeship

Now save your deployment by clicking on the green checkmark on the right.

Save your deployment configuration by clicking on the green checkmark

From now on the Codeship will deploy your application to dotCloud everytime you push to your Bitbucket repository.

Let’s get your application ready for Dotcloud. Dotcloud expects a file dotcloud.yml in the root directory of your application. In this configuration file you need to tell Dotcloud that your web application is of type “python”.

  type: python

Dotcloud also needs a file in the root directory of your application. Just copy the content from the Dotcloud Django documentation page

Dotcloud Django documentation page

and replace the app name hellodjango with your own Django application’s name.


Now you can commit and push this change

Commit and push Dotcloud config

And immediately another build will start running on the Codeship. Let’s go back to your project overview.

Go back to the project overview to see a new running build

After the commands we already know from your first build, your application also gets deployed to dotCloud now.

After some initial commands were run your application gets deployed

And about 2 minutes later your application is online.

After about 2 minutes your application is online

When you open the URL of your dotCloud app now, your deployed application appears. You can find mine on

Have a look at the app you just deployed

If you need help with setting up your own application, please use the support link in the top-right corner or please tweet us @codeship!

If you need help please click the support link in the top-right corner or tweet us @codeship

Subscribe via Email

Be sure to join 13,643 subscribers of our newsletter to receive updates on software development best practices, Continuous Delivery and tips and tricks to start shipping your product faster.

Join the Discussion

Leave us some comments on what you think about this topic or if you like to add something.