In today's rapidly evolving world of software development, implementing Continuous Integration (CI) and Continuous Deployment (CD) has become increasingly important. CI/CD pipelines ensure your applications are built, tested, and deployed efficiently and reliably. is a platform that enables developers to automate and optimize their workflows easily. This blog post will guide you through building a Django app and setting up a CI/CD pipeline using


Before we begin, ensure you have the following installed and set up on your local machine:

  • Python 3.6 or later
  • Django 2.2 or later
  • Git
  • Docker
  • CLI, GitHub Account, and access to a Account

Getting Started

First, let’s create a sample Django app:

  • Open your terminal and create a new directory for your project:
mkdir django-docker-example

cd django-docker-example
  • Install Django an create a virtual environment
python -m venv venv 

source venv/bin/activate 

(venv) $ pip install django
  • Create a new Django Project:
(venv) $ django-admin startproject myproject
  • Move into the project directory.
(venv) $ cd myproject
  • Create a new Django App
(venv) $ python startapp myapp

Now, let's create a Dockerfile and docker-compose.yml file:

  • In the root of your project directory, create a file named Dockerfile:
# Use an official Python runtime as a parent image
FROM python:3.9

# Set the working directory

# Copy the requirements.txt file
COPY requirements.txt .

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host -r requirements.txt

# Copy the rest of the application
COPY . .

# Make port 8000 available to the world outside this container

# Define the command to run the application using Django's development server
CMD ["python", "", "runserver", ""]
  • Create a requirements.txt file in the root of your project directory with the following content:


  • Create a docker-compose.yml file in the root of your project directory
version: "3.9"

    build: .
    command: python runserver
      - .:/app
      - "8000:8000"

Configure your Ops.yml file

To configure your ops.yaml file, open a new file called ops.yml and configure your Pipeline steps with your pipeline events and environment variables.

version: "1"
 - name: django-workflow:0.1.5
   description: django-workflow
       - DEBIAN_FRONTEND=noninteractive
       - ORG=<github_username>
       - REPO=<github_repo>
       - REF=main
     - "github:<github_username>/<github_repo>:pull_request.opened"
     - "github:<github_username>/<github_repo>:pull_request.merged"
     - name: django-workflow-build
       description: django workflow
         - git
         - echo "django workflow"
         - curl -O
         - python3 -m pip install --upgrade pip
         - pip install -r requirements.txt
         - python3 test
         - docker build -t <image_name> .

Trigger Pipelines with GitHub Events

In my configuration, I’m using the pull_request:opened and the pull_request:merged event triggers. In my GitHub repo, I'll open a pull request and build my application using the PR comments workflow.

  • In the comment section, your pipeline runs with all the checks passing.

View Pipelines in Dashboard

Your dashboard shows your Pipeline workflow passing with the logs from your Django Application. Your Pipeline dashboard shows the VERSION, DESCRIPTION, PIPELINE STATUS, and the ACTION that triggered it.


In conclusion, incorporating a CI/CD pipeline in your Django projects can significantly streamline the development process, improve code quality, and accelerate deployment. Following this blog's steps and best practices ensures your team always works with the latest, most reliable codebase version.

By embracing CI/CD in your Django projects today, you'll enhance your development workflow and foster a culture of collaboration and continuous improvement within your team.