forked from mikedory/fabfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
84 lines (61 loc) · 1.96 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
# import the fabric requirements
from __future__ import with_statement
from fabric.api import *
# import local_settings.py
from config.local_settings import *
# import the submodules
import lib.local as local
import lib.remote as remote
"""
Test and prepare everything locally using Django's test framework
Then, commit files, and push to Github
"""
# test the app locally
def test():
local.test()
# run all the pre-flight tests
def prepare(test=test_default, commit=commit_default, push=push_default):
if test is True:
local.test()
if commit is True:
local.commit()
if push is True:
local.push()
"""
Deploy to the remote server!
For tags:
fab env deploy:tag=YYYY-MM-DD-tag-description
For branches:
fab deploy:branch=master
So to deploy a tag to production, run:
fab prod deploy:tag=YYYY-MM-DD-tag-description
And to deploy to a single server:
fab -u username -H domain.com -i /path/to/.ssh/id_rsa deploy:tag=YYYY-MM-DD-tag-description
"""
# run the code deploy, then restart the supervisor process
@parallel(pool_size=pool_size)
def deploy(tag=None, branch=None, supervisor_restart=supervisor_default):
with hide('stdout', 'stderr'):
remote.code_deploy(tag, branch)
remote.minify()
if supervisor_restart is True:
remote.supervisor_restart()
# roll back to a specific tag
@parallel(pool_size=pool_size)
def rollback(tag=None, supervisor_restart=supervisor_default):
remote.code_rollback(tag)
if supervisor_restart is True:
remote.supervisor_restart()
# roll back to a specific tag
@parallel(pool_size=pool_size)
def restart(virtualenv=virtualenv_default):
if virtualenv is True:
with hide('stdout', 'stderr'):
remote.virtualenv_check()
remote.virtualenv_activate()
remote.supervisor_restart()
# set up the virtualenv for deploys
@parallel(pool_size=pool_size)
def virtualenv_setup():
remote.virtualenv_check()
remote.virtualenv_activate()