Django project template with a lot of basic project must-have features, such as containerization and deployments to GCR, ECR, Dockerhub and regular old VM using Github Actions. Also Unit Test, Code Coverage, Static Analysis and Stages Flow (such as dev, staging, uat and production) are part of this project template repository.
- Python >= 3.8.5
- Pip >= 21.0.1
pip install -r requirements.txt
source envvars
To start new database server, run this command:
docker-compose up -d
Check if database running correctly by accessing database from command line or PGAdmin.
To create migration scripts:
python manage.py makemigrations app
To execute migrations:
python manage.py migrate app
python manage.py runserver 0.0.0.0:8080
This application using pytest as the test framework and pytest-django as integration tool with Django Framework. To run unit test simply run this command.
pytest -s
This application using coverage as the code coverage tool and pytest-cov as integration tools with Pytest. To run code coverage simply run this command.
pytest --cov-report html --cov-report term --cov=app app/tests/
To run static analysis using flake8, run this command:
flake8 --config=.flake8 --count --statistics app/ core/
You can use build-ci status checks in the repository settings to ensure continues integration is working correctly on target branch. This status checks come from .github/workflows/onpush-ci.yml.
This project template provide deployment using docker image. The deployment targets are GCR, ECR, Dockerhub or VM, you can see the workflows from this these files .github/workflows/*-deployment.yml.
To build image run this command (change the tag name & version with your preferred tag name & version).
$ docker build . -t myorganization/myimage:1.0.0
To create a container from the image, run this command (change the tag name & version with your preferred tag name & version).
$ docker run -d -p 8000:8000 --network=serviceNetwork --name django-app myorganization/myimage:1.0.0
Then you can access the app from the browser with this url: http://127.0.0.1:8000
This repository is proven by running build in Dockerhub, you can see the result here.