3

Trying to streamline a deployment process to webfaction.com for my django application, I have a master (working copy) and a development branch.

currently I'm doing the following:

  1. Make changes to my development branch in my local dev environment
  2. When changes are working, test with run local server, then merge with my master branch
  3. git push so the code is in my remote repo (this has other issues such as passwords, keys etc which I've not quite solved yet) (also i dont believe its possible to scp code to webfaction and I'm not really a fan of any of the FTP services I've used so far)
  4. SSH into my webfaction server and do a git pull and git merge
  5. Test to see if everything is still working (it never is)
  6. Make anychanges required to get everything working again
  7. commit any changes I've had to do to fix everything then push back to the remote repo
  8. Go back to my development environment and sync the code up with the production code
  9. Rinse Repeat for the next feature

obviously I've missed the efficient development train, for the record I've only been working with django for a couple of months as a hobby project.

Can anyone suggest a django deployment process that would be more conducive to sane development?

AnythingMapping
  • 367
  • 3
  • 15

2 Answers2

5

I would strongly suggest Fabric to handle your deployments to WebFaction: http://docs.fabfile.org/en/1.11/tutorial.html

By using Fabric you can deploy code and do other server side operations from your local terminal with no need to manually ssh to the server. First install Fabric:

pip install Fabric

Create fabfile.py in your project root folder. Here is an example fabfile that can get you started:

from fabric.api import task, env, run, cd
from fabric.context_managers import prefix

env.hosts = ('wf_username@wf_username.webfactional.com',)
env.forward_agent = True

MANAGEPY = '~/webapps/my_project/code/my_project/manage.py'
PY = '~/webapps/my_project/env/bin/python2.7'

@task
def deploy():
    with cd('~/webapps/my_project/code/'):
        with prefix('source production'):
            run('git pull --rebase origin master')
            run('pip install -r requirements.txt')
            run('{} {} migrate'.format(PY, MANAGEPY))
            run('{} {} collectstatic --noinput'.format(PY, MANAGEPY))
            run('touch my_project/my_project/wsgi.py')

You can run fab task from your terminal with:

fab deploy

In my opinion, making code changes directly on server is a bad practice. Fabric can improve your development flow so that you make code edits only locally, quickly deploy them and test them.

ozren1983
  • 1,891
  • 1
  • 16
  • 34
  • a friend has also recommended I use Vagrant. Is this similar to Fabric? – AnythingMapping May 06 '16 at 10:03
  • Not really, Vagrant is used for automatic provision of virtual machines, and it's not possible to use it on WebFaction. – ozren1983 May 06 '16 at 13:47
  • Fabric helps you streamline the use of SSH for application deployment and system administration tasks. I mostly use Fabric for automating deployments. Instead of using your previous flow where you push code to git, ssh to server, pull code, optionally run migrations or install requirements, and restart server, with fab you can run single command from your local terminal, that will do all that repetitive work for you. – ozren1983 May 06 '16 at 13:54
-1

The best and shortest way

In settings.py:

try:
  from production_settings import *
except ImportError as e:
  pass

You can override what needed in production_settings.py; it should stay out of your version control and you can use git resourcefully.

RoshP
  • 19
  • 1
  • 5