4

I'm new to Git. I need to setup Git to deploy a Django website to the production server. My question here is to know what is the best way of doing this.

By now I only have a Master branch. My problem here is that Development environment is not equal to the Production environment. How can I have the two environments(Development and Production) in Git? Should I use two new Branches(Development and Production). Please give me a clue on this.

Other question... when I finish to upload/push the code to the Production server I need to restart the Gunicorn(serves Django website). How can I do this?

And the most important question... Should I use Git to do this or I have better options?

Best Regards,

André
  • 24,706
  • 43
  • 121
  • 178
  • 1
    I'm not sure I understood very well your question: do you mean that to deploy your software you need to push it to a GIT repo on a production server? – Giovanni Di Milia Dec 02 '11 at 09:13
  • No, it seems he's not sure how to use branches in GIT. Well, no one really knows :). Kidding, it's not the branches you should worry about, but your project layout. You probably have hard time figuring out how to have separate settings for production and development? – Davor Lucic Dec 02 '11 at 09:23
  • @rebus, Yes, that is my question. What is the best way to have separate Development and Production. And... Should I do this in Git or I have easier options to deploy new code to the production server... – André Dec 02 '11 at 09:35
  • We use [`buildout`](http://www.buildout.org/) to solve that problem, but there are plenty of other approaches that can be found on [SO](http://stackoverflow.com/questions/88259/how-do-you-configure-django-for-simple-development-and-deployment) – Davor Lucic Dec 02 '11 at 09:39

2 Answers2

2

The first question you must solve is your project structure. Usually the difference between development and the production environment is setting.py and url.py. So why you firstly separate those? :) For example you can have one main settings.py where you define all the default settings which are in common. Then at the end of the file you just import the settings_dev.py and settting_prod.py for exemple:

try:
    from settings_prod import *
except ImportError:
    pass

try:
    from settings_dev import *
except ImportError:
    pass

Then simply you can overload all the setting you want and have custom settings of the project (for example installed apps). The same logic you can use for urls.py file.

Then you can simply ignore adding the *_dev files to repo and on the server side you can just checkout the code from repo and restart http server. To automatize this for now I can't give the right name of app to use. Sometimes simple python script could be solution like: watching if the file datetime changed and if yes, just run restart command for http.

Hope that helped.

Ignas

Ignas Butėnas
  • 6,061
  • 5
  • 32
  • 47
0

You can follow this brunching model - http://nvie.com/posts/a-successful-git-branching-model/

And, git is ok but use Fabric for deployment.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
Rifat
  • 7,628
  • 4
  • 32
  • 46