Guest User

Untitled

a guest
Jan 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import time
  2.  
  3. from fabric.api import *
  4.  
  5. env.git_remote = 'git@example.com:myapp.git'
  6.  
  7. def production():
  8. """Production server settings"""
  9. env.settings = 'production'
  10. env.hosts = ['example.com']
  11. env.user = 'user'
  12.  
  13. def deploy():
  14. """Deploy the latest version of the site to the server and restart"""
  15. clone_repo()
  16. checkout_latest()
  17. install_requirements()
  18. symlink_current_release()
  19. migrate()
  20. reload()
  21.  
  22. def clone_repo():
  23. """Do initial clone of the git repo"""
  24. run('if [ ! -d ~/shared/cached-copy ]; then git clone %(git_remote)s ~/shared/cached-copy; fi' % env)
  25.  
  26. def checkout_latest():
  27. """Pull the latest code into the git repo and copy to a timestamped release directory"""
  28. env.release = time.strftime('%Y%m%d%H%M%S')
  29. run("cd ~/shared/cached-copy; git pull origin master")
  30. run('cp -R ~/shared/cached-copy ~/releases/%(release)s; rm -rf ~/releases/%(release)s/.git*' % env)
  31.  
  32. def install_requirements():
  33. """Install the required packages using pip"""
  34. run('pip install -E ~/ -r ~/releases/%(release)s/requirements.txt' % env)
  35.  
  36. def symlink_current_release():
  37. """Symlink our current release, uploads and settings file"""
  38. run('cd ~/; ln -nfs ~/releases/%(release)s current' % env)
  39. run('cd ~/current/usability_manager; ln -nfs ~/shared/db db')
  40.  
  41. def migrate():
  42. """Run our migrations"""
  43. run('cd ~/current; ~/bin/python manage.py syncdb --noinput')
  44.  
  45. def reload():
  46. """Reload uWSGI"""
  47. run('kill -HUP $(< ~/shared/pids/uwsgi.pid)')
Add Comment
Please, Sign In to add comment