-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
91 lines (68 loc) · 2.34 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from fabric.api import env, local, require
project_name = 'eraldoenergy'
def backup():
"""fab [environment] backup"""
require('environment')
if env.environment == "development":
local('pg_dump -Fc {project} > backups/{project}-{environment}_`date +%Y-%m-%d_%H%M%S`.dump'.format(
project=project_name, environment=env.environment))
elif env.environment in ['staging', 'production']:
local(
'curl -o backups/{project}-{environment}_`date +%Y-%m-%d_%H%M%S`.dump `heroku pg:backups public-url --app {app}`'.format(
project=project_name, environment=env.environment, app=env.app))
def deploy():
"""fab [environment] deploy"""
require('environment')
maintenance_on()
push()
migrate()
maintenance_off()
ps()
def maintenance_on():
"""fab [environment] maintenance_on"""
require('environment')
local('heroku maintenance:on --app %s' % env.app)
def maintenance_off():
"""fab [environment] maintenance_off"""
require('environment')
local('heroku maintenance:off --app %s' % env.app)
def push():
"""fab [environment] push"""
require('environment')
local('git push origin {branch}'.format(branch=env.branch))
def migrate(app=None):
"""fab [environment] migrate"""
require('environment')
if env.environment == "development":
if app is not None:
local('python manage.py migrate %s' % app)
else:
local('python manage.py migrate')
else:
if app is not None:
local('heroku run python manage.py migrate %s --app %s' % (app, env.app))
else:
local('heroku run python manage.py migrate --app %s' % env.app)
def ps():
"""fab [environment] ps"""
require('environment')
local('heroku ps --app %s' % env.app)
def open():
"""fab [environment] open"""
require('environment')
local('heroku open --app %s' % env.app)
def development():
"""fab development [command]"""
env.environment = 'development'
env.app = 'local'
env.branch = 'development'
def staging():
"""fab staging [command]"""
env.environment = 'staging'
env.app = 'eraldoenergy-staging'
env.branch = 'staging'
def production():
"""fab production [command]"""
env.environment = 'production'
env.app = 'eraldoenergy'
env.branch = 'master'