Other parts:
- 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
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=orders
- 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
- Rename
.env.example
to.env
- Set the project name same as
COMPOSE_PROJECT_NAME
in Traefik.env
COMPOSE_PROJECT_NAME=orders
- 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
- Rename
.env.example
to.env
- Set the project name same as
COMPOSE_PROJECT_NAME
in Traefik.env
COMPOSE_PROJECT_NAME=orders
- 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=orders.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
- 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=orders
- Uncomment
Mode 3
block:# Mode 3: For production with SSR COMPOSE_FILE=production.yml DOMAIN=orders.baikov.dev
- Change all secure variables
- Add Sentry DSN and Email settings (optional)
- Run container with
docker compose build
anddocker compose up -d
coming soon...