alexdeathway / headstart-django

A starter template Dockerizing django with postgres, gunicorn, nginx and certbot.
53 stars 5 forks source link
certbot django docker gunicorn hactoberfest hactoberfest-accepted hactoberfest2024 hactoberfest2024-accepted nginx postgresql template

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

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

    =======