-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
53 lines (39 loc) · 1.65 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
# -*-coding: UTF-8 -*-
# Run these commands with fab
from datetime import date, datetime
from fabric.api import local, settings, abort, run, cd, env, sudo, prefix
from fabric.contrib.console import confirm
from fabric.contrib.files import exists
env.site_name = 'spreadsite'
env.hosts = ['{0}@spreadsite.org'.format(env.site_name)]
env.virtualenv = env.site_name
env.settings_subdir = env.site_name
env.django_apps = ['spreadlinks', 'downblog']
def update_requirements():
local("pipenv lock -r > requirements.txt")
def test():
with settings(warn_only=True):
result = local('pipenv run python manage.py test {0}'.format(' '.join(env.django_apps)), capture=True)
if result.failed and not confirm("Tests failed. Continue anyway?"):
abort("Aborting at user request.")
def push():
local('git push')
def deploy():
test()
push()
run('if [ ! -d static ]; then mkdir static; fi')
# run('mkdir -p caches/httplib2')
run('mkdir -p caches/django')
code_dir = '/home/{0}/Sites/{0}'.format(env.site_name)
with cd(code_dir):
run('git pull')
with prefix('. /home/{0}/virtualenvs/{1}/bin/activate'.format(env.site_name, env.virtualenv)):
run('pip install -r requirements.txt')
run('envdir /service/%s/env ./manage.py collectstatic --noinput' % (env.site_name,))
def make_virtualenv():
env_name = 'virtualenvs/{0}'.format(env.site_name)
if exists(env_name):
bak_name = 'virtualenvs/before-{0}.{1}'.format(date.today().isoformat(), env.site_name)
if not exists(bak_name):
run('mv {0} {1}'.format(env_name, bak_name))
run('virtualenv {0}'.format(env_name))