-
-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathfabfile.py
79 lines (55 loc) · 1.86 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
import os
import re
from fabric import colors
from fabric.api import task
from fabric.api import local
from fabric.api import env
from fabric.api import run
from fabric.api import cd
env.hosts = ['cloudtun.es']
env.user = 'cloudtunes'
env.key_filename = '~/.ssh/id_dsa'
GITHUB = '[email protected]:jakubroztocil/cloudtunes.git'
ROOT = '~'
CODE_ROOT = '%s/cloudtunes-webapp' % ROOT
BUILD_DIR = os.path.dirname(__file__) + '/build/production'
REV_RE = re.compile('(?<=\.css)|(?<=\.js)')
BUILD_COMMIT_MESSAGE = 'Built for deployment.'
@task
def bootstrap():
print(colors.cyan('Bootstrapping...', bold=True))
run('rm -rf %s' % CODE_ROOT)
run('git clone %s %s' % (GITHUB, CODE_ROOT))
@task
def git_pull():
with cd(CODE_ROOT):
run('git pull')
def update_html():
last_commit_rev = local('git rev-parse HEAD', capture=True)
print(colors.cyan('Updating index.html...', bold=True))
with open(BUILD_DIR + '/index.html', 'r+w') as f:
html = f.read()
html = REV_RE.sub('?' + last_commit_rev, html)
f.seek(0)
f.write(html)
@task
def build():
print(colors.cyan('Compiling...', bold=True))
local('rm -rf ' + BUILD_DIR)
local('brunch build --production --config=config-dist.coffee')
update_html()
@task
def deploy():
"""Deploy code and schema changes to production"""
local('git diff --exit-code') # Must be clean.
last_commit_message = local('git log --format=%B -n 1', capture=True)
if last_commit_message != BUILD_COMMIT_MESSAGE:
build()
print(colors.cyan('Committing...', bold=True))
# Can exit 1 with no diff; it's ok
os.system('git add . && git commit -am "%s"' % BUILD_COMMIT_MESSAGE)
print(colors.cyan('Pushing...', bold=True))
local('git push')
print(colors.cyan('Deploying...', bold=True))
with cd(CODE_ROOT):
run('git pull')