Skip to content

Commands to Update a Deployment

pwhipp edited this page Nov 12, 2014 · 2 revisions

Updating a deployment will start with a git pull in some branch (frequently master but often something else).

Git looks after all of the code changes for us but it does not do anything to the database and it cannot update the virtualenv if there are new python modules to be installed. The management commands deal with these issues.

It is always a good idea to look at the result of the pull and use that information to apply the following management commands intelligently. If you pull frequently, the list of changes will generally be quite managable. You can always pipe the pull output to a file with git pull > pull.out to process it at your leisure. You can also undo a pull if need be with git reset HEAD@{1}.

However, each command can be applied distinctly without risk of damage. The following table describes the management commands and when they should be applied (by calling django <command> unless stated otherwise):

Command What it does When to apply it
collectstatic Copies all the static files into a special folder so that nginx can quickly serve them. On nginx fronted services only, apply it if you see any /static/... changes or additions following the pull.
syncdb Adds any new tables needed for models in /models.py. Whenever you see models.py file changes.
migrate Updates any changes made to tables. Whenever you see models.py file changes (syncdb is being dropped from Django in the 1.7 release so migrate will be the only command needed).
sync_translation_fields Adds any new required translation fields. If you've added a language to the settings.LANGUAGES.
update_translation_fields Migrates entries in the default language fields into the default language field. If you have entries in the default fields that need moving to the correct language - this will probably never happen.
remove_translation_fields Removes existing model translation fields. If you've removed a language from the settings.LANGUAGES.
pip install -r requirements.txt Adds new python modules to the installation. This is the whole command. If you see the requirements.txt file change

Once these updates are complete, any processes running the code need to be restarted. If behind nginx, these processes are typically managed via upstart so an appropriate sudo service <user>_<venvname> copy will do the trick. If on a development system using runserver, it will probably restart itself; otherwise use ctl-c to kill the existing process and relaunch it.

Updating dependent modules

Sometimes a dependent module may not have version information in the requirements.txt (e.g. docmeta or another cccs module). This is technically incorrect because the requirements.txt is supposed to be a concrete list specifying versions but it is expedient.

In such cases in may be necessary to uninstall and reinstall the relevant package (upgrading may result in other undesirable upgrades). For example:

(production)abadi:~/production $ pip uninstall docmeta
Uninstalling docmeta:
  /home/abadi/.virtualenvs/production/lib/python2.7/site-packages/docmeta.egg-link
Proceed (y/n)? y
  Successfully uninstalled docmeta
(production)abadi:~/production $ pip install -r requirements.txt 
...