Live Docker NocoDB Django Postgres Project:


3. Django Backend Introduction

Company administration Django backend made by team members (repo/company_backend/README.md)

Production PowerPC (ppc64le) server:

Just do what is in ../README.md

Explanation: Docker uses the Dockerfile to set all of this up for you including running the uvicorn company_backend.asgi:application --host 0.0.0.0 --port 8000 --reload command internally and even reroutes traffic through nginx instead of directly accessing this server. It also sets up database (required), presentation_frontend for fullstack development and proper URL routing for the "/api" route. If you need to use python3.12 manage.py ... for anything within the container access it using docker exec -it CONTAINER_ID where CONTAINER_ID is the backend container ID from docker container ls -a.

First time setup OUTSIDE Docker

DO NOT DO THIS ON WINDOWS YOU WILL REGRET IT, python tends to fail in finding mariadb connector way too often, etc.

  1. Install Python 3.12 (e.g. sudo apt install python3.12 on Linux/macOS or https://python.org/downloads/windows if running using Powershell)
  2. Try to install Django Admin globally: python3.12 -m pip install Django==5.1.2 (if pip isn't working: sudo apt install pip) (if it breaks because "externally managed dependency" error, just continue with step 3)
  3. Use venv: python3.12 -m venv .venv
  4. Source the venv:
  1. Make sure python is running under venv: which python3.12 or where python3.12 should show the venv directory's python
  2. Install dependencies: python3.12 -m pip install -r requirements.txt
  1. Launch two MariaDB servers (or change db to sqlite - not recommended)
  1. Set your enviroment variables: cp .env.example-backend-light-dev .env and edit them in your favorite editor except the prefilled ones - MAKE SURE ALL VARIABLES ARE SET!
  2. Activate your enviroment variables: source .env or on windows PowerShell .\loadenv.ps1
  3. Run the server: uvicorn company_backend.asgi:application --host 0.0.0.0 --port 8000 --reload

Subsequent runs

  1. Source the venv:
  1. Launch two MariaDB servers as before
  2. Activate your enviroment variables: source .env or on windows .\loadenv.ps1
  3. Run the server: uvicorn company_backend.asgi:application --host 0.0.0.0 --port 8000 --reload

How the boilerplate was created

  1. django-admin startproject company_backend && mv company_backend/* .

Docker Compose Snippet


  # Django backend for Public Presentation
  presentation_backend:
    build:
      dockerfile: Dockerfile
      context: presentation_backend
    environment:
      - PRESENTATION_DJANGO_SECRET_KEY=...
      - ...
    volumes:
      - ./presentation_backend:...
    depends_on:
      presentation_db:
        condition: service_healthy
    healthcheck:
      test:
        ["CMD-SHELL", "wget ..."]
      start_period: 20s
      interval: 10s
      timeout: 5s
      retries: 10
    networks:
      - common_network
    restart: unless-stopped
    logging:
      driver: ...
      options:
        syslog-address: ...
        tag: ...

  # Django backend for Company Administration
  company_admin_backend:
    build:
      dockerfile: Dockerfile
      context: company_backend
    environment:
      - COMPANY_DJANGO_SECRET_KEY=...
      - ...
    volumes:
      - ./company_backend:...
    depends_on:
      company_admin_db:
        condition: service_healthy
    healthcheck:
      test:
        ["CMD-SHELL", "wget ..."]
      start_period: 20s
      interval: 10s
      timeout: 5s
      retries: 10
    networks:
      - common_network
    restart: unless-stopped
    logging:
      driver: ...
      options:
        syslog-address: ...
        tag: ...