First, we will prepare the project, then web server and other services that we might need to use.
git clone name@server:git/project.git
Here is my structure for Django apps. You may see different structure but it will be similar to this:
project/ ├── apps -> The project folder ├── etc -> Sample configurations ├── fabfile.py -> Fabric script for automate deployment ├── README ├── requirement.txt -> dependent apps for the project └── www -> static files, ex. css, js ...
pip install requirement.txt
Not all projects need this. I usually don’t save secret keys in settings.py. So, I get them from my environment variables. Advantage of using this:
There are 5 environment variables I need to set to deal with the project:
Set it on your .profile:
vi ~/.profile export SECRET_KEY='' export DATABASE_NAME='' export DATABASE_USER='' export DATABASE_PASSWORD='' export DEBUG=True
./manage.py syncdb ./manage.py migrate --all
if there is fixture and you did not put them in your settings, then add them:
./manage.py loaddata app_name
You may use Nginx or Apache2. Checkout this to see sample configurations and more details.
pip install gunicorn
To run it on special port type:
gunicorn apps.wsgi:application -b 127.0.0.1:8001
sudo aptitude install supervisor
Create new configration:
sudo vi /etc/supervisor/conf.d/site_name.conf
Don’t forget to restart it.
sudo service supervisor restart // or reload sudo supervisorctl site_name reload
sudo supervisorctl ? sudo supervisorctl update site_name.conf
Fabric is used to automate deployment to the server. This is a scenario maybe later I will provide with some codes.
Prepare for deployment:
Scenario for develop new feature and deploy it: