Skip to content

Project to create all the configuration file needed to start a nginx - uwsgi - django - postgresql stack using docker-compose

Notifications You must be signed in to change notification settings

parruc/docker-django

Repository files navigation

Brief guide

Configuration:

To create a configuration file for the project run::

cp .config.template .config
vim .config

Now edit the .config file according to your desired result (read about the config details later in this guide)

Automatic installation:

This kind of installation assumes that you are on a DEB system and you already have a git repo to checkout with all the django project inside

Just run::

./configure.sh
make install

Manual instalation apply for any other case:

This instructions are for deb/ubuntu users. Modify them to supply your OS flavour::

pip3 install virtualenv docker-compose
virtualenv --python=python3 .
bin/pip install -r requirements.txt
./init.py  # (no arguments to use the .config)
docker-compose up -d
service nginx reload

As you see we call the init script that compiles the configuration templates into real configuration files for docker compose and nginx Arguments can be passed to the command but easiest way is to use a .config file containing the relevant setup information in json format.

The init script, after compiling the external nginx configuration file will create a symlink in te appropriated nginx directory: /etc/nginx/sites-(available|enabled)/example.com.conf BBB: If you are not on a linux system place the link accordingly

The init script help screen. Contains all the parameters that you will also find into the .config file. Password are autogenerated if not configured, other fields have more or less sensibledefaults:

  -h, --help            show this help message and exit
  -hn HOSTNAME, --hostname HOSTNAME
                        Host name
  -pe PORTEXTERNAL, --portexternal PORTEXTERNAL
                        Http external nginx port number publically visible
  -pes PORTEXTERNALSSL, --portexternalssl PORTEXTERNALSSL
                        Https external nginx port number publically visible
  -pi PORTINTERNAL, --portinternal PORTINTERNAL
                        Http internal nginx port number publically visible
  -cp CERTIFICATESPATH, --certificatespath CERTIFICATESPATH
                        Use this parameter for certificates path
  -csp CONTENTSECURITYPOLICY, --contentsecuritypolicy CONTENTSECURITYPOLICY
                        Use this parameter for the value of the content
                        security policy http header
  -dbn DBNAME, --dbname DBNAME
                        Database name
  -dbu DBUSER, --dbuser DBUSER
                        Database user
  -dbp DBPASSWORD, --dbpassword DBPASSWORD
                        Database password
  -g, --gis             Use this parameter to add GIS support to postgres
  -gr GITREPOSITORY, --gitrepository GITREPOSITORY
                        Project repository checkout
  -gb GITBRANCH, --gitbranch GITBRANCH
                        Project repository branch
  -l LIBRARIES, --libraries LIBRARIES
                        apt requirements
  -r REQUIREMENTS, --requirements REQUIREMENTS
                        Django app requirements
  -rd REQUIREMENTSDEV, --requirementsdev REQUIREMENTSDEV
                        Django app development requirements
  -smtpu SMTPUSER, --smtpuser SMTPUSER
                        SMTP user
  -smtpp SMTPPASSWORD, --smtppassword SMTPPASSWORD
                        SMTP password
  -smtph SMTPHOST, --smtphost SMTPHOST
                        SMTP host address
  -pn PROJECTNAME, --projectname PROJECTNAME
                        Name of the project
  -pv PYTHONVERSION, --pythonversion PYTHONVERSION
                        Python version to use as base docker image
  -sc SECRETKEY, --secretkey SECRETKEY
                        django project secret key
  -sp, --spooler        add spool process
  -scale SCALE, --scale SCALE
                        django instances number
  -ul UPLOADLIMIT, --uploadlimit UPLOADLIMIT
                        max MB uplodable
  -br BACKUPREPOSITORY, --backuprepository BACKUPREPOSITORY
                        backup git repo
  -bf BACKUPFOLDERS, --backupfolders BACKUPFOLDERS
                        Folders to backup
  -bi BACKUPIGNORES, --backupignores BACKUPIGNORES
                        Folders to ignore during backup
  -cm CRONJOBMINUTE, --cronjobminute CRONJOBMINUTE
                        backup croonjob minute
  -ch CRONJOBHOUR, --cronjobhour CRONJOBHOUR
                        backup cronjob hour
  -v, --verbose         Use this parameter to see verbose output
  -c, --create          Use this parameter to create the .config file if does
                        not exists
  -dev, --development   Use this parameter to see development to true
  -async, --async       Use this parameter to use async server

Init params order of resultion is: cli arguments -> .config fie -> defaults

Generated Makefile commands:

Deletes the eventually running containers, clones the chosen repository/branch, installs node dependecies and restarts the containers

make install

Starts the containers using the scale parameter for wsgi

make: up

Removes containers

make down

Recreates containers

make recreate

Restarts containers

make restart

Reload uwsgi instances

make reload

Clears redis cache

make clearcache

Creates django migrations, if needed

make migrations

Executes existing migrations

make migrate

Extracts and compiles tranlation messages

make messages

Compiles static resources and, if in dev ,starts hot reload

make theme

Updates the repository and runs pull, migrate, messages and theme

make update

Tails on last 100 logs entry of the containers

make logs

Create a superuser

make superuser

HTTPS

If you want to setup an https server you will also need letsencrypt::

sudo apt-get install letsencrypt

And you will have to create your own certificates::

letsencrypt certonly --webroot -w . -d example.com -d www.example.com

To use https you can use certificatespath arguemnt writing the path where the certificates are. The certificates must have been created externally using certpath command (installed as python requirement)

When developement is active:

  • Django is execute in debug mode
  • Debug toolbar is shown
  • uwsgi starts with python-autoreload=1 and honour-stdin=true to allow pdb
  • docker compose launches uwsgi using stdin_open: true tty: true to allow pdb

About

Project to create all the configuration file needed to start a nginx - uwsgi - django - postgresql stack using docker-compose

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published