forked from hacktoolkit/django-htk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fab_helpers.py
70 lines (57 loc) · 1.97 KB
/
fab_helpers.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
"""fab_helpers.py
Helper functions and classes for Fabric (http://fabric.readthedocs.org/en/latest/)
Used by fabfile.py
"""
# Python Standard Library Imports
import datetime
# Third Party (PyPI) Imports
import requests
from fabric.api import *
def tag_deploy():
"""Automatically create a tag whenever we deploy, so that we can roll-back to it at a future date"""
commit_timestamp = local(
'git log -n 1 --pretty=format:"%ct" master', capture=True
)
commit_datetimestr = datetime.datetime.utcfromtimestamp(
float(commit_timestamp)
).strftime('%Y%m%d%H%M')
revision = local('git log -n 1 --pretty=format:"%H" master', capture=True)
local(
'git tag -a deploy-{commit_datetimestr}-{revision}-master master -m "Auto-tagged deploy {commit_datetimestr} {revision}"'.format(
commit_datetimestr=commit_datetimestr,
revision=revision[:10],
)
)
local('git push --tags')
def rollbar_record_deploy(access_token, env='other'):
"""Tracking deploys
http://rollbar.com/docs/deploys_fabric/
"""
environment = env
local_username = local('whoami', capture=True)
# fetch last committed revision in the locally-checked out branch
revision = local('git log -n 1 --pretty=format:"%H"', capture=True)
resp = requests.post(
'https://api.rollbar.com/api/1/deploy/',
{
'access_token': access_token,
'environment': environment,
'local_username': local_username,
'revision': revision,
},
timeout=3,
)
if resp.status_code == 200:
print("Deploy recorded successfully.")
else:
print("Error recording deploy:", resp.text)
class AbstractFabricTaskManager(object):
def deploy(self):
"""Default deploy task"""
print('I am a dummy task')
def _get_hosts(self):
hosts = []
return hosts
def _get_setup_args(self):
setup_args = '-h'
return setup_args