Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. from fabric.api import *
  2. from fabric.operations import *
  3. from fabric.contrib.project import rsync_project
  4. from fabric.contrib.files import exists
  5.  
  6. import sys, os
  7.  
  8. abspath = lambda filename: os.path.join(
  9. os.path.abspath(os.path.dirname(__file__)),
  10. filename
  11. )
  12.  
  13. # --------------------------------------------
  14. # DEV platform cofiguration
  15. # --------------------------------------------
  16.  
  17. class FabricException(Exception):
  18. pass
  19.  
  20. def dev():
  21. print "Connecting to Ec2 machine"
  22.  
  23. env.setup = True
  24. env.user = 'ubuntu'
  25. env.ubuntu_version = '16.04'
  26. env.warn_only = True
  27. env.development_env = 'dev'
  28. env.password = 'ubuntu'
  29. env.key_filename = abspath('keyfile.pem')
  30. env.hosts = [
  31. 'A.B.C.D'
  32. ]
  33. #env.app_port = '3000'
  34.  
  35. env.home = '/home/%s' %(env.user)
  36. env.project = 'finwallet-client'
  37. env.app_path = '%s/%s' %(env.home, env.project)
  38.  
  39. env.graceful = False
  40.  
  41. env.nginx_config = abspath('../nginx.conf')
  42.  
  43. env.rsync_exclude = [
  44. "fonts/",
  45. "javascripts/",
  46. "stylesheets/",
  47. "*.py",
  48. "*.pyc",
  49. "sample.index.html",
  50. "*.pem"
  51. ]
  52. return
  53.  
  54.  
  55. # --------------------------------------------
  56. # Installing Dev Platform
  57. # --------------------------------------------
  58.  
  59. def install():
  60. print 'Start installing Dev Platform'
  61. update()
  62. install_nginx()
  63. nginx_config()
  64. print 'Finished installing Dev Platform'
  65. return
  66.  
  67. def update():
  68. print 'Start updating the system'
  69. sudo('apt-get update')
  70. return
  71.  
  72. def install_nginx():
  73. print 'Installing NGINX'
  74. sudo("apt-get install -y nginx")
  75. return
  76.  
  77. def nginx_config():
  78. print 'Configuring NGINX'
  79. default_config='/etc/nginx/sites-enabled/nginx.conf'
  80. if exists(default_config):
  81. sudo('rm /etc/nginx/sites-enabled/nginx.conf')
  82. print 'Deleted NGINX default config'
  83.  
  84. print 'Install NGINX config'
  85. put('%s' % (env.nginx_config), '/etc/nginx/sites-enabled/', use_sudo=True)
  86.  
  87. print 'Restarting NGINX'
  88. sudo("service nginx stop")
  89. sudo("service nginx restart")
  90. return
  91.  
  92. def build_client_app():
  93. print 'Building Client App...'
  94. local('cd ..; export NODE_ENV="production"; npm install; npm run build')
  95. return
  96.  
  97. def sync_code_base():
  98. print 'Syncing codebase'
  99. local('cp sample.index.html index.html')
  100. rsync_project(env.app_path, abspath('') + '*', exclude=env.rsync_exclude, delete=True, default_opts='-rvz')
  101. local('rm index.html')
  102. return
  103.  
  104.  
  105. # --------------------------------------------
  106. # Deploying DEV Platform
  107. # --------------------------------------------
  108.  
  109. def deploy():
  110. print 'Start deploying .....'
  111. build_client_app()
  112. sync_code_base()
  113. print 'Successfully finished deployment'
  114. # --------------------------------------------
  115. # fabric script end
  116. # --------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement