Guest User

Untitled

a guest
May 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1.  
  2. """
  3. This fabfile deploys projects versioned in git and that use a virtualenv in the
  4. remote server.
  5.  
  6. The deploy and deploy_version tasks are framework-independent.
  7.  
  8. The freshdb task is specific for Django projects.
  9.  
  10. The restart task is for projects deployed using FastCGI.
  11.  
  12. TODO:
  13. * Bootstrap command to create a virtualenv and install requirements with pip.
  14.  
  15. """
  16.  
  17. from __future__ import with_statement
  18.  
  19. from fabric.api import cd, env, require, run, settings
  20.  
  21. env.project_name = 'project_name'
  22.  
  23. env.user = 'remote_user'
  24. env.hosts = ['your_host.com']
  25. env.home_path = '/home/remote_user'
  26. env.path = '%s/path/to/project' % env.home_path
  27. env.virtualenv_dir = '%s/env' % env.home_path
  28.  
  29.  
  30. def _virtualenv(command):
  31. """Execute a command in remote host inside a virtualenv."""
  32. require('virtualenv_dir')
  33. run('source %s/bin/activate && %s' % (env.virtualenv_dir, command))
  34.  
  35.  
  36. def deploy():
  37. """Update the remote code to the last version and make it visible."""
  38. deploy_version()
  39.  
  40.  
  41. def deploy_version(version=None):
  42. """Update the remote code to a specific version and make it visible."""
  43. require('path')
  44. with cd(env.path):
  45. run('git checkout master')
  46. run('git pull')
  47. if version is not None:
  48. run('git checkout %s' % version)
  49. restart()
  50.  
  51.  
  52. def freshdb():
  53. """Delete the remote DB and make a fresh syncdb."""
  54. require('path')
  55. with cd(env.path):
  56. with settings(warn_only=True):
  57. run('rm chattr.db')
  58. _virtualenv('python manage.py syncdb --noinput')
  59.  
  60.  
  61. def restart():
  62. """Restart the FastCGI process (to make changes visible)."""
  63. require('home_path')
  64. with settings(warn_only=True):
  65. run('kill $(cat %(home_path)s/run/chattr.pid)' % env)
  66. run('sh %(path)s/conf/chattr_fastcgi.sh' % env)
Add Comment
Please, Sign In to add comment