In one of the projects, you should regularly upload the code from the stage branch to the staging server. Started doing it manually - you log in via ssh, do the git push origin stage, if you need to - update the database and then restart apache. By the end of this week, it was decided that it would be good to perform all these actions with one team. I have gone through blogs - now they are very actively writing about the use of the
Fabric library for this purpose (this is an analogue of
Capistrano from Ruby on Rails).
How to install
Install the fabric library via pip or easy_install, then create a symbolic link for the fab application, or add a folder with bin files in your Python distribution in the PATH. Below is a brief tutorial for Mac OS X + ports.
sudo pip-2.6 install fabric
sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/fab /usr/bin/fab
What Fabric does
Fabric allows you to perform a variety of ssh actions on a whole group of servers. Actions are described in the file fabfile.py and represent normal Python functions. Usually fabfile.py is placed in the root folder of the project (next to manage.py, settings.py, urls.py, ...).
')
from fabric.api import *
env . hosts = [ 'moodbox.com' ]
def deploy ():
local( 'hg push' )
with cd( 'hgreps/vorushin_ru' ):
run( 'hg update' )
run( '/etc/init.d/apache2 reload' )
Now if I run fab deploy from the project folder vorushin_ru (the code of this blog written in Django), then first push will happen from my local machine, then ssh will be updated on the server and then restarted.
Any subtleties
First, work on ssh should go through certificates. See
ssh-keygen ,
ssh authorized keys .
Secondly, if you need to pull from another server, you need to add the -A parameter when calling ssh. Details -
lincolnloop.com/blog/2009/sep/22/easy-fabric-deployment-part-1-gitmercurial-and-sshThirdly, if the development team is alternately done by a development team, then the project files should have write permissions for the entire development team. Details -
lincolnloop.com/blog/2009/oct/7/easy-fabric-deployment-part-2Fourth, if several projects are running under Apache, then it is better to restart it via touch your.wsgi (if mod_wsgi is configured to work in daemon_mode).
The original article in my blog - vorushin.ru/blog/10-razvertyvanie-django-proektov-c-pomoshyu-fabric