Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fabric.api import *
- from fabric.operations import *
- from fabric.contrib.project import rsync_project
- from fabric.contrib.files import exists
- import sys, os
- abspath = lambda filename: os.path.join(
- os.path.abspath(os.path.dirname(__file__)),
- filename
- )
- # --------------------------------------------
- # DEV platform cofiguration
- # --------------------------------------------
- class FabricException(Exception):
- pass
- def dev():
- print "Connecting to Ec2 machine"
- env.setup = True
- env.user = 'ubuntu'
- env.ubuntu_version = '16.04'
- env.warn_only = True
- env.development_env = 'dev'
- env.password = 'ubuntu'
- env.key_filename = abspath('keyfile.pem')
- env.hosts = [
- 'A.B.C.D'
- ]
- #env.app_port = '3000'
- env.home = '/home/%s' %(env.user)
- env.project = 'finwallet-client'
- env.app_path = '%s/%s' %(env.home, env.project)
- env.graceful = False
- env.nginx_config = abspath('../nginx.conf')
- env.rsync_exclude = [
- "fonts/",
- "javascripts/",
- "stylesheets/",
- "*.py",
- "*.pyc",
- "sample.index.html",
- "*.pem"
- ]
- return
- # --------------------------------------------
- # Installing Dev Platform
- # --------------------------------------------
- def install():
- print 'Start installing Dev Platform'
- update()
- install_nginx()
- nginx_config()
- print 'Finished installing Dev Platform'
- return
- def update():
- print 'Start updating the system'
- sudo('apt-get update')
- return
- def install_nginx():
- print 'Installing NGINX'
- sudo("apt-get install -y nginx")
- return
- def nginx_config():
- print 'Configuring NGINX'
- default_config='/etc/nginx/sites-enabled/nginx.conf'
- if exists(default_config):
- sudo('rm /etc/nginx/sites-enabled/nginx.conf')
- print 'Deleted NGINX default config'
- print 'Install NGINX config'
- put('%s' % (env.nginx_config), '/etc/nginx/sites-enabled/', use_sudo=True)
- print 'Restarting NGINX'
- sudo("service nginx stop")
- sudo("service nginx restart")
- return
- def build_client_app():
- print 'Building Client App...'
- local('cd ..; export NODE_ENV="production"; npm install; npm run build')
- return
- def sync_code_base():
- print 'Syncing codebase'
- local('cp sample.index.html index.html')
- rsync_project(env.app_path, abspath('') + '*', exclude=env.rsync_exclude, delete=True, default_opts='-rvz')
- local('rm index.html')
- return
- # --------------------------------------------
- # Deploying DEV Platform
- # --------------------------------------------
- def deploy():
- print 'Start deploying .....'
- build_client_app()
- sync_code_base()
- print 'Successfully finished deployment'
- # --------------------------------------------
- # fabric script end
- # --------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement