Django using a TDD approach, using containerization of it for agility, API documentation with Swagger, Github Actions for automated testing, etc...
app/
- Django projectapp/core/
- Code shared between multiple appsapp/user/
- User related code (User registration & auth tokens)app/recipe/
- Recipe related code (Handling and updating ingrediants and tags and managing tags)
docker-compose run --rm app sh -c "python manage.py collectstatic"
run
will start a specific container defined in config, to remove the container once is finished running. Important to avoir having lots of containers running in the background.
--rm
removes the container
sh -c
passes in a shell command
docker-compose run --rm app sh -c "django-admin startproject app .
docker-compose up
docker build .
once one has the app folder created at root
How we'll test
docker-compose run --rm app sh -c "python manage.py test"
Django installation from within docker
docker-compose run --rm app sh -c "django-admin startproject app ."
Run project with Docker Compose
docker-compose up
Stop all the containers
docker stop $(docker ps -a -q)
Remove all the containers
docker rm $(docker ps -a -q)
Creating core app:
docker-compose run --rm app sh -c "python manage.py startapp core"
Init:
docker-compose run --rm app sh -c "python manage.py makemigrations"
- Avoid relying on external services!! (we dont' have necessarily control over these)
- Ex: sendin email func, but we don't want to actually send an email
- Speeding up tests (for example bypass sleep funcs)
Package that you need in order for Django to connect to our database. It's the most popular PostgreSQL adaptor for Python. Supported by Django officially.
psycopg2-binary
: ok for dev, but not for prodpsycopg2
: compiled from source, compiled for the OS your running on.Better for reliability and perf.
Dependencies:
- C compiler
- python3-dev
- libq-dev
Equivalent packages for Alpine
- postgresql-client
- buildbase
- postgresql-dev
- musldev
docker-compose run --rm app sh -c "python manage.py wait_for_db"
Not working: docker-compose run --rm app sh -c "python manage.py makemigrations"
Working: docker-compose run app sh -c "python manage.py makemigrations core"
docker-compose run --rm app sh -c "python manage.py wait_for_db && python manage.py migrate"
docker-compose run --rm app sh -c "python manage.py createsuperuser"