Skip to content

Instantly share code, notes, and snippets.

@edude03
Created March 10, 2014 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edude03/9466976 to your computer and use it in GitHub Desktop.
Save edude03/9466976 to your computer and use it in GitHub Desktop.
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
from fabric.operations import prompt
import os, sys
env.user = 'root'
def set_roles():
_hosts = dict()
for (key, val) in hosts.iteritems():
_hosts[key] = [val['host']]
return _hosts
hosts = {
'production' : {
'code_dir': '/var/www/mobilespa/app',
'schema': 'mysql://MobileSpa:Manager2012@dev.mobilespaelite.com/mobilespa',
'host': 'dev.mobilespaelite.com'
},
'dev' : {
'code_dir': '/var/www/mobilespa/app',
'schema': 'mysql://mobiledev:mobilespa@elliptic.melenion.com/mobilespadev',
'host': 'elliptic.melenion.com'
},
'wemassage' : {
'code_dir' : "/var/www/wemassage/app",
'schema' : "mysql://wemassage:sistercompany1@wemassage.ca/wemassage",
'host' : 'wemassage.ca'
}
}
env.roledefs = set_roles()
def syncdb():
with lcd('schema'):
local('schemasync mysql://root:Urbanone1@localhost/mobilespadev {0} --tag={1}'.format(hosts[env.roles[0]]['schema'], env.roles[0]))
def predeploy(target):
# Minify the Assets
#minify()
# Check if any need to be commited
# Does a 'cd' in the current directory into app
with lcd('app'):
#push the commits to the server
local('git push {} master'.format(target))
def minify():
with lcd('app/webroot/js'):
print os.path.join(os.curdir, 'minified.js')
local('rm minified.js')
local('cat jquery.min.js bootstrap.js bootstrap-datepicker.js wysihtml5-0.3.0.js bootstrap-wysihtml5-0.0.2.js bootbox.js bootstrap-formhelpers-phone.format.js bootstrap-formhelpers-phone.js bootstrap-timepicker.js functions.js | uglifyjs > minified.js')
with lcd('app/webroot/css'):
local('rm minified.css')
local('cat app.css bootstrap.css minified.css datepicker.css responsive.css bootstrap-wysihtml5-0.0.2.css bootstrap-timepicker.css style.css styleie9.css | cleancss -s > minified.css')
#Asks the user if they want to enter a tag for this release
def add_tag(tag):
tag = prompt("Enter a tag for this release")
if len(tag) > 0:
local("git tag -a {}".format(tag))
def deploy():
#Determine the code_dir based on the config
code_dir = hosts[env.roles[0]]['code_dir']
with cd(code_dir):
#Stop the web server
# run("/etc/init.d/nginx stop")
# Pull from the repo
run("git pull")
# Setup any submodules
# Ensure the submodule URLs are upto date first
run("git submodule sync")
run("git submodule update --init --recursive")
#Restart the webserver
# run("/etc/init.d/nginx start")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment