This repository has been archived by the owner on Feb 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfabfile.py
52 lines (38 loc) · 1.41 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
from fabric.api import abort, run, local, cd, env, roles, execute, prefix
import requests
import standardweb.local_settings as settings
CODE_DIR = '/home/sbezboro/standard-web'
ENV_DIR = '/home/sbezboro/standard-web-env'
WEB_SERVICE = 'standard-web'
env.roledefs = {
'web': ['208.110.64.130']
}
def deploy():
local("git pull")
execute(update_and_restart_webs)
rollbar_record_deploy()
@roles('web')
def update_and_restart_webs():
with cd(CODE_DIR):
with prefix('source %s/bin/activate' % ENV_DIR):
run("git pull")
result = run("pip install -r requirements.txt --quiet")
if result.failed:
abort('Could not install required packages. Aborting.')
run('supervisorctl restart %s' % WEB_SERVICE)
def rollbar_record_deploy():
access_token = settings.ROLLBAR['access_token']
environment = 'production'
username = local('whoami', capture=True)
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': username,
'rollbar_username': username,
'revision': revision
}, timeout=3)
if resp.status_code == 200:
print "Deploy recorded successfully."
else:
print "Error recording deploy:", resp.text