- Goal
- How to setup
- Repo Features
- Configurations
- Development usage
- Testing usage
- Production usage
- License
- Todo
- Bugs
This project main goal is to provide a way to deploy django applications by using docker along with nginx, gunicorn and letsencrypt and much more features a backed developer needs.
you can watch this video to know how you can use this repo
- Latest LTS Django3.2
- Git
- Docker File
- Docker Compose
- Nginx + Gunicorn
- Django env
- Hints and Files
- Github Actions
- Black and Flake8
- Django Rest Framework
- Swagger and Redoc
- Preconfigured
Latest LTS included 3.2.x and needed requirements
python gitignore and README with license
Latest Python image dockerfile prod/dev and dockerignore
Docker compose prod/dev and minimum setup for django and db included,with volumes and network
included nginx setup with gunicorn as serving service and file configs for production
enviroment sample file and setup
Sample files and hints all over the template for giving more pace
Pre Configurations for CI/CD in github actions. plus two step jobs for testing and deploying on vps with docker
Included Pep8 and Flake8 configuration file for test purposes.Reformating the codes and bring the best out of it.
Included DRF package and all its dependencies along side of cors headers. plus simplejwt and token authentication for accounting.
Allowing the urls to include rest api documentations
Preconfigured settings.py for email,db,static,media etc.
- Static & Media Directories
- Template Directories
- Site Framework and Sitemaps + robots
- Database Configs
- Email Configs
- Message Configs
- Hints and Files
- TestCase
- Security
STATIC_ROOT and STATIC_URL and same for media configurations with STATICFILES_DIRS
Genral templates directory for root
Siteframework as in site_id configs with robots.txt and sample sitemaps
Database configuration for production with postgresql and volume directory in data
Email configurations for dev and prod as in env file
Message and warnings configuration for notification handelings
Sample files and hints all over the template for more giving more pace
Hints for TestCases and sample files for an app
Security tags for https and redirections,HSTS,Cookie and other headers
You'll need to have Docker installed. It's available on Windows, macOS and most distros of Linux.
If you're using Windows, it will be expected that you're following along inside of WSL or WSL 2.
That's because we're going to be running shell commands. You can always modify these commands for PowerShell if you want.
git clone https://github.com/AliBigdeli/Ultimate-Django3.2-Template.git
Enviroment Varibales are included in docker-compose.yml file for debugging mode and you are free to change commands inside:
services:
backend:
command: sh -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
environment:
- DEBUG=True
The first time you run this it's going to take 5-10 minutes depending on your internet connection speed and computer's hardware specs. That's because it's going to download a few Docker images and build the Python + requirements dependencies.
docker compose up --build
Now that everything is built and running we can treat it like any other Django app.
If you receive an error about a port being in use? Chances are it's because something on your machine is already running on port 8000. then you have to change the docker-compose.yml file according to your needs.
Visit http://localhost:8000 in your favorite browser.
docker compose run --rm backend sh -c " black -l 79 && flake8 && python manage.py test" -v core:/app
or
docker compose exec backend sh -c sh -c " black -l 79 && flake8 && python manage.py test"
In this phase of the project you can launch the service either in your pc/laptop to use as local host or you can setup on a vps to access through ip or even the domain which is dedicated to it. but before that dont forget to create .env files in the envs directory for stage mode which contains backend,nginx and the db. after creating the files all you need to do to build the project is to run the command bellow:
docker compose -f docker-compose-stage.yml up --build
In this phase of the project you can launch the project only on the vps with the domain name connect to it other than that you have to change the settings accordingly.(you can use the stage config as base for the nginx) But before that dont forget to create .env files in the envs directory for prod mode which contains backend,nginx and the db. after creating the files all you need to do to build the project is to run the command bellow:
docker compose -f docker-compose-prod.yml run --rm certbot /opt/certify-init.sh
Note:the command i provided will firstly create the containers and volumes to run the whole project, then it will create a container to access the running server, when the server is accessible it will ask letsencrypt server to create a certificate for it with acme challange. this certificate will be valid for 90 days and you can renew it when ever you want. Note: if you are using arm base cpu, please go inside the docker file inside of dockerfiles/prod/certbot/dockerfile and change the image name from
FROM certbot/certbot:arm32v6-latest
to
FROM certbot/certbot:v1.27.0
On Production mode you have all the security headers and settings added to nginx and even auto ssl encryption for 90 days valid. you can find the results by using these services:
- Mozilla Observatory
- Security Headers
- SSL Checker
MIT.
- add pre commands
Feel free to let me know if something needs to be fixed. or even any features seems to be needed in this repo.