Other parts:
- Traefik 2.10 as revers-proxy in Docker (SSL in dev and prod)
- Nuxt 3 production-ready template in Docker (SPA/SSR)
- Django/DRF backend in Docker (based on django-cookiecutter)
- Custom User model
- Djoser registration
- Celery + Redis + Flower
- Sentry in prod
- Nginx for media in prod
- Silk profiling in dev
- add logging
- Create virtual environment
python -m venv venv
- Activate virtual environment
source venv/bin/activate
- Install requirements
pip install -r requirements/local.txt
- Install and activate all recomended
VSCode
extensions - Install
pre-commit
pre-commit install
- Install
Docker Desktop
- Make sure
ruff
andmypy
are workingruff check backend/
mypy backend/
- Copy
.env.example
and rename it to.env
on local machine
Choose one of .env
presets.
To use
Mode 1
andMode 2
, a raised container from this repo with Traefik is required. Because an external network to which frontend and backend containers are connected is created in Traefik compose.
- No need for a Traefik container
- Set
uniqe
project nameCOMPOSE_PROJECT_NAME=uniqe_name
- Uncomment
Mode 0
block and set custom ports if needed:# Mode 0: As separate dev server on custom port COMPOSE_FILE=local.yml DOMAIN=localhost DJANGO_DOCKER_PORT=8000 MAILHOG_DOCKER_PORT=8025 FLOWER_DOCKER_PORT=5555 DOCS_DOCKER_PORT=9000
- Run
docker compose build
anddocker compose up -d
Avaliable paths:
dj-admin/
,api/
,ststic/
,silk/
. Other paths are proxied to the frontend container
- The Traefik container must be running in
Mode 1
- Set the project name same as
COMPOSE_PROJECT_NAME
in Traefik.env
COMPOSE_PROJECT_NAME=example
- Uncomment
Mode 1
block:# Mode 1: As dev server behind the Traefik with http # For Windows users: use `;` (semicolon) as separator - local.yml;local.traefik.yml COMPOSE_FILE=local.yml:local.traefik.yml DOMAIN=localhost # or another aliace for 127.0.0.1 declared in etc/hosts, but same as DOMAIN in Traefik .env!
- Run Traefik container, then run Django stack with
docker compose build
anddocker compose up -d
Avaliable paths:
dj-admin/
,api/
,ststic/
,silk/
. Other paths are proxied to the frontend container
- The Traefik container must be running in
Mode 2
- Set the project name same as
COMPOSE_PROJECT_NAME
in Traefik.env
COMPOSE_PROJECT_NAME=example
- Uncomment
Mode 2
block:# Mode 2: As dev server behind the Traefik + SSL and custom domain # For Windows users: use `;` (semicolon) as separator - local.yml;local.traefik.yml;local.traefik.ssl.yml COMPOSE_FILE=local.yml:local.traefik.yml:local.traefik.ssl.yml DOMAIN=tpl.local # same as DOMAIN in Traefik .env!
- Run Traefik container, then run Django stack with
docker compose build
anddocker compose up -d
- Show Logs (e.g. Django)
docker logs -f django # or docker compose logs -f django
- Migrations
docker compose run --rm django python manage.py makemigrations
docker compose run --rm django python manage.py migrate
- Django shell_plus with ipython
docker compose run --rm --name django_shell django python manage.py shell_plus --ipython
- Create DB backup (placed in
./pg-backups
)docker compose exec postgres backup
- Show backups list
docker compose exec postgres backups
- Restore backup (only from
gzip
)docker compose exec postgres restore backup_2023_05_26T12_34_08.sql.gz
- Hot clean DB (close all connections)
docker compose exec postgres restore clean
Using this modes assumes that the
your-domain.com
is already bound to your server (A
records are configured) and Traefik container raised in production mode
- The Traefik container must be running in
Mode 3
on prod server - Copy
.env.production.example
and rename it to.env
- Set the project name same as
COMPOSE_PROJECT_NAME
in Traefik.env
COMPOSE_PROJECT_NAME=example
- Uncomment
Mode 3
block:# Mode 3: For production with SSR COMPOSE_FILE=production.yml DOMAIN=your-domain.com
- Change all secure variables
- Add Sentry DSN and Email settings (optional)
- Run container with
docker compose build
anddocker compose up -d
coming soon...
I made this template for myself, but it's awesom if it helps someone else. The settings are far from ideal, so fell free to make a pull request.