Skip to content

A starter template Dockerizing django with postgres, gunicorn, nginx and certbot.

Notifications You must be signed in to change notification settings

alexdeathway/headstart-django

Repository files navigation

headstart-django

Python Django PostgreSQL Gunicorn Nginx Certbot License

This template is designed to quickly set up a Django project using PostgreSQL, Gunicorn, Nginx, and Certbot (for SSL). It supports both development and production environments, facilitating the running of your project in a containerized setup.

Motivation

I needed a robust Docker setup for my Django projects and came across this article The (near) Perfect Dockerfile for Django Applications by Siddharth Sahu. While the original setup was a good start, it lacked several essential features for my projects. As a result, I decided to enhance it and create this template.

Tech Stack

Technology Version Badge
Django 5.1 Django
PostgreSQL 16.4 PostgreSQL
Gunicorn 21.2.0 Gunicorn
Nginx 1.27.1 Nginx
Certbot latest Certbot

Features

  • Quick setup for Django projects with a core application.
  • Dockerized environments for both development and production.
  • Automatic SSL certificate renewal using Certbot.
  • Production-ready Nginx configuration.
  • Local static and media directories (configurable for S3 or other storage services).
  • Support for both PostgreSQL and SQLite databases (SQLite will be used in development if PostgreSQL isn't available).

Setup Instructions

Production Environment Setup

  1. Create a .prod.env File: In the root directory of your project, create a .prod.env file with the required environment variables. Use the provided template.prod.env for guidance.

  2. Run Docker Compose: Execute the following command to build and run your project in a production environment:

    docker compose -f docker-compose.prod.yml up --build

    Your project is now running in a production environment!

Development Environment Setup

Option 1: Using Virtualenv (Recommended)

  1. Create a Repository from This Template:

    Create Repository

  2. Clone the Repository Locally:

    git clone <YOUR-repository-url>
  3. Create a Virtual Environment:

    python3 -m venv venv
  4. Activate the Virtual Environment:

    source venv/bin/activate
  5. Install Requirements:

    pip install -r requirements.txt
  6. Create a .dev.env File: In the root directory of the project, create a .dev.env file with the required environment variables, referencing template.dev.env.

  7. Start the Development Server:

    python manage.py runserver

Option 2: Using Docker

  1. Clone the Repository:

    git clone <repository-url>
  2. Create a .dev.env File: In the root directory of the project, create a .dev.env file with the required environment variables, referencing template.dev.env.

  3. Run Docker Compose:

    docker compose up --build

=======