Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have two servers, a Dev server and a Production server. The Production server runs a live Django site, while the Dev server has a copy of the Django project. I use the Dev server to work on the Django site, make improvements, fix bugs, etc. Once I am satisfied with how the Dev version is working, I move the whole Django directory from the Dev server and replace the same directory on the Production server. The two servers are not on the same LAN so the process is not straight forward.

There are a few issues with this that I am having so far.

  1. Moving the whole directory is laborious and time consuming
  2. If I only change a few files, it is even move tedious to replace a few files than the whole directory since the project is getting fairly large and I worry that I'll miss something
  3. I often run into permission issues after I've moved things
  4. It's super inefficient, and, due to lack of time, I haven't bothered figuring out a new method. Now it's just getting out of hand and i need to address the situation.

I am thinking I need to move to a GIT repository for this process. But my question is how would I set this all up?

  • Do I host the repository on the Production server, pull from the Dev server, do work, then commit? Then I would pull from the Production server (same server the repo is hosted on) to run the current working version?
  • Do I host the repo on the Dev Server, pulling from the same server to do work on the repo, then pull a working version onto the Production server?
  • Should I be hosting the repo on a different server than the Production server and the Dev server (a third server)?
  • Are there any special considerations with Django and repos that I need to worry about?

Thanks for the help :)

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I work with Django development and GIT for 18 months. During this period I tried to hosting myself a git repository and today I use GITHUB for the job. It is easier and time saving for a little cost. Look at my considerations:

  • Unless you are a Linux expert with GIT experience it is cheaper (consider that time is money) to host your project in GITHUB. They have free GIT hosting for public projects (anyone can clone/fork them). They also have a (cheap) paid GIT hosting if you want to have a private repository.

  • GITHUB (or other GIT hosting company) will make it easier to setup repositories so you can learn to work with GIT as you use it (in another words, due to the web interface you don't have to learn more than the basig GIT command line syntax before using GIT)

  • GIT is a distributed control version system. This means that every place where you put a copy of your repository will have the full history of all your code, so in case you choose to host your own GIT server, it is irrelevant to put on DEV or PRD server. Actually you can put it in your own notebook with no fear in loosing data, because you have a copy in DEV and PRD too. Have in mind that you have to make PULLs ON your DEV and ON your PRD server from your GIT server.

  • It is easy to do FABRIC scripts for updating the DEV or PRD server from your own machine. All you have to do is to have something like this in your fabfile.py:

    def deploy_production():
        with cd('/home/my_user/my_project'):
            run("git pull") # update to the newest version
            with prefix('source ~/.virtualenvs/my_env/bin/activate'):
                run('./manage.py collectstatic --noinput')
    def production():
        """
        Sets environment to production
        """
        continue = confirm('Updating the production environment, continue?', default=False)
        if not continue:
            abort('Good bye - thanks for doing nothing on production!')
        env.hosts = ['my_server.my_domain.com.br']
        env.key_filename = ['~/amazon/my_ssh_key.pem']
        env.user = 'ubuntu'

    # Use this to run fabric update procedure:
    fab production deploy_production
  • Use virtualenv and virtualenvwrapper
  • create a file in the project root called '.gitignore' and put the file (or file patterns) that you don't want to manage through GIT like: *.pyc, .idea, .DS_Store (one per line)

Hope it helps, good look!

If you find these answer useful, please assign points.

share|improve this answer
    
Thanks for your advice on the topic. I have considered using GitHub for holding my repos, but I don't think I have a need high enough to pay for it (and I don't want a public version, since the project I am working on is for a business). I am working through a Git guide and, so far, it looks very straight forward. I also think that Fabric is fantastically amazing! I wish I had found it earlier since it will definately speed up my work flow. Thanks again! –  Garfonzo Oct 31 '12 at 4:01

I suggest you use a source code control system such as git as you mentioned, do your work locally, and have a look at Fabric for deployment. You can use git checkout-index to export the code locally (via code in the fabfile) before sending it to the server via a command like fab dev deploy. When you're ready to deploy to production fab prod deploy. You can put code in the fabfile to move the source code to the proper location, update dependencies like Django (via pip for example), restart uwsgi, etc.

share|improve this answer
    
When you say "do your work locally" do you mean on the Dev server? Because that's the server I do my programming on, no other machine. If that is what you mean, would I host the git repo's on the Dev server or the Production server? Is it just as easy to checkout a repo onto a machine that is also hosting the repo? –  Garfonzo Oct 29 '12 at 17:31
    
No I was suggesting that you do your work on your local machine. However, you could still use Fabric on the dev machine and deploy from there. –  xofer Oct 29 '12 at 17:41
    
Well, my local machine is a WinBox so I always just ssh into the Dev server and work on the code - never worked right on the WinBox. When I'm programming, I make some changes, test it out, change a bit more, test it out. Seems to me that working on the WinBox and pulling/pushing the repo would be more work than just working right on the Dev machine. I like the looks of Fabric and will certainly be using that in the future. Thanks for your input :) –  Garfonzo Oct 29 '12 at 17:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.