Advertisement
Guest User

Untitled

a guest
May 26th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import os
  2. import json
  3. from datetime import datetime
  4. from fabric.api import *
  5. from fabric.context_managers import settings
  6. from fabric.utils import fastprint
  7.  
  8.  
  9. with open('deploy.json', 'r') as f:
  10. env.project_settings = json.loads(f.read())
  11.  
  12.  
  13. @task
  14. def deploy():
  15. if os.environ.get('TRAVIS_BRANCH', 'None varible branch') == 'master':
  16. env.settings = env.project_settings['stages']['stable']
  17. else:
  18. env.settings = env.project_settings['stages']['development']
  19.  
  20. # Set env.
  21. env.host_string = env.settings['host']
  22. env.user = env.settings['user']
  23. env.password = os.environ.get('sshpass', '')
  24.  
  25. with hide('stderr', 'stdout', 'warnings', 'running'):
  26. with cd(env.settings['code_src_directory']):
  27. pull_repository()
  28. install_requirements()
  29. restart_application()
  30.  
  31.  
  32. def print_status(description):
  33. def print_status_decorator(fn):
  34. def print_status_wrapper():
  35. now = datetime.now().strftime('%H:%M:%S')
  36. fastprint('({time}) {description}{suffix}'.format(
  37. time=now,
  38. description=description.capitalize(),
  39. suffix='...\n')
  40. )
  41. fn()
  42. now = datetime.now().strftime('%H:%M:%S')
  43. fastprint('({time}) {description}{suffix}'.format(
  44. time=now,
  45. description='...finished '+description,
  46. suffix='.\n')
  47. )
  48. return print_status_wrapper
  49. return print_status_decorator
  50.  
  51.  
  52. @print_status('pulling git repository')
  53. def pull_repository():
  54. command = 'git pull {} {}'.format(
  55. env.project_settings.get('git_repository'),
  56. env.settings.get('vcs_branch')
  57. )
  58. print command
  59. run(command)
  60.  
  61.  
  62. @print_status('installing requirements')
  63. def install_requirements():
  64. run('npm i')
  65.  
  66.  
  67. @print_status('restarting application')
  68. def restart_application():
  69. with settings(warn_only=True):
  70. restart_command = env.settings['restart_command']
  71. result = run(restart_command)
  72. if result.failed:
  73. abort('Could not restart application.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement