Reading Time: 4 minutes
How to set up Continuous Integration and Continuous Deployment for a Django Application from GitHub to App Engine
In this blog post we’re gonna deploy a Django application from a GitHub repository to App Engine using Codeship. Before we get started you might also want to take a short look at our documentation article on deployment to Google App Engine.
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.
Together, we’re gonna deploy this application to App Engine using the Codeship.
First, sign in to the Codeship with GitHub. The Codeship needs access to your GitHub repositories to be able to set them up. Let’s allow access.
We’re back at the Codeship. Now let’s create your first project.
The first step of your project setup is to select GitHub as your repository provider.
In the list of your GitHub repositories
search for the repository you want to set up and select it. In my case I search for “codefish”.
Now your repository is connected and you can 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.
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 manage.py test, you don’t need to change the test commands. Otherwise just enter your own test commands.
Now let’s finish your setup and go to the dashboard.
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.
Now commit and push this change.
This triggered a new build on the Codeship.
You can access the build details by clicking the arrow on the right. Here you can follow the running build.
And a few seconds later your build succeeded! Great!
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.
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.
Now let’s deploy your application to App Engine. Go to your project settings by clicking on the settings icon in the projects dropdown.
Then navigate to the “Deployment” section.
As we want to deploy to App Engine we click on the “App Engine” button.
Before you can configure your App Engine deployment, you need to connect your App Engine account to Codeship by clicking the “Connect to App Engine” link.
Let’s accept the connection.
When you select “App Engine” again now, you can configure your deployment.
You can leave the path as it is, but if you’d like the Codeship to check if your deployment worked, you should insert the URL of your application.
So if you haven’t already, let’s create your application at appengine.google.com now.
There you need to enter an identifier for your app (in my case “my-codefish”) and a title (in my case “Codefish”) and create the application.
You can enter your application URL
http://YOUR_APP_IDENTIFIER.appspot.com into your deployment configuration.
Now save your deployment by clicking on the green checkmark on the right.
From now on the Codeship will deploy your application to App Engine everytime you push to your GitHub repository.
Let’s get your application ready for App Engine by creating a file
app.yml in the root directory of your application. In this configuration file you tell App Engine your web application’s identifier (in my case “my-codefish”) and that it is a python app.
App engine also requires a
version and an
api_version parameter, which you can both set to “1”. And finally add a handler for all urls to be handled by your app boot script, in my case
Now you can commit and push this change
And immediately another build will start running on the Codeship. Let’s go back to your project overview.
After the commands we already know from your first build, your application also gets deployed to App Engine now.
And about 2 minutes later your application is online.
When you open the URL of your App Engine app now, your deployed application appears. You can find mine on my-codefish.appspot.com.
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!