Guest User

Untitled

a guest
Feb 15th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. from fabric.api import local, run, env, put
  2. import os, time
  3.  
  4. # remote ssh credentials
  5. env.hosts = ['10.1.1.25']
  6. env.user = 'deploy'
  7. env.password = 'XXXXXXXX' #ssh password for user
  8. # or, specify path to server public key here:
  9. # env.key_filename = ''
  10.  
  11. # specify path to files being deployed
  12. env.archive_source = '.'
  13.  
  14. # archive name, arbitrary, and only for transport
  15. env.archive_name = 'release'
  16.  
  17. # specify path to deploy root dir - you need to create this
  18. env.deploy_project_root = '/var/www/projectx/'
  19.  
  20. # specify name of dir that will hold all deployed code
  21. env.deploy_release_dir = 'releases'
  22.  
  23. # symlink name. Full path to deployed code is env.deploy_project_root + this
  24. env.deploy_current_dir = 'current'
  25.  
  26. def update_local_copy():
  27. # get latest / desired tag from your version control system
  28. print('updating local copy...')
  29.  
  30. def upload_archive():
  31. # create archive from env.archive_source
  32. print('creating archive...')
  33. local('cd %s && zip -qr %s.zip -x=fabfile.py -x=fabfile.pyc *' \
  34. % (env.archive_source, env.archive_name))
  35.  
  36. # create time named dir in deploy dir
  37. print('uploading archive...')
  38. deploy_timestring = time.strftime("%Y%m%d%H%M%S")
  39. run('cd %s && mkdir %s' % (env.deploy_project_root + \
  40. env.deploy_release_dir, deploy_timestring))
  41.  
  42. # extract code into dir
  43. print('extracting code...')
  44. env.deploy_full_path = env.deploy_project_root + \
  45. env.deploy_release_dir + '/' + deploy_timestring
  46. put(env.archive_name+'.zip', env.deploy_full_path)
  47. run('cd %s && unzip -q %s.zip -d . && rm %s.zip' \
  48. % (env.deploy_full_path, env.archive_name, env.archive_name))
  49.  
  50. def before_symlink():
  51. # code is uploaded, but not live. Perform final pre-deploy tasks here
  52. print('before symlink tasks...')
  53.  
  54. def make_symlink():
  55. # delete existing symlink & replace with symlink to deploy_timestring dir
  56. print('creating symlink to uploaded code...')
  57. run('rm -f %s' % env.deploy_project_root + env.deploy_current_dir)
  58. run('ln -s %s %s' % (env.deploy_full_path, env.deploy_project_root + \
  59. env.deploy_current_dir))
  60.  
  61. def after_symlink():
  62. # code is live, perform any post-deploy tasks here
  63. print('after symlink tasks...')
  64.  
  65. def cleanup():
  66. # remove any artifacts of the deploy process
  67. print('cleanup...')
  68. local('rm -rf %s.zip' % env.archive_name)
  69.  
  70. def deploy():
  71. update_local_copy()
  72. upload_archive()
  73. before_symlink()
  74. make_symlink()
  75. after_symlink()
  76. cleanup()
  77. print('deploy complete!')
Add Comment
Please, Sign In to add comment